Created an AI for a contest

This year the journal freiesMagazin organized the third contest in a series. This time it’s about programming an AI for a predator-prey-like game. I just submitted my short solution.

As I said, it’s the third programming contest. The first one was about switching gems and in the second contest it was the goal to navigate a robot through a factory. I didn’t got the announce of the first one and missed the second one as a consequence of a lack of time. Hence it’s a premiere for me!

Citing their introduction:

Same procedure as every day: It is late in the evening and you're still sitting at your office desk and listening to some music. Suddenly a siren sounds through all rooms, the doors are closing automatically and you cannot open them anymore. A light green mist appears and some creepy shapes wander around the hall. Sometimes you really hate Mondays …

So, at the beginning of the game all programmed bots are in the same team. After some time one of them changes to the opposite team, trying to catch one of the other while the other ones are fleeing. Simple and clear. It’s running through sockets and the bot-programmers can win vouchers. More information can be found at their website.

On one hand I’m interested in socket programming since a while and on the other hand I’m of course interested in the voucher, so I decided to take part in the contest although there are enough other things to do for me. I agreed with myself to put about two days of work into it. In the end I worked about three days, but however, I could program about 365 more. If you take a look at the code it’s kept more or less simple and many functions aren’t in use. For example I track a motion profile of each opponent, but when I’m predator I don’t care about it. It would be more promising to predict a actual position of a prey (for example with neural networks or something like that) instead of searching without any profoundness. But this would go beyond my scope…

So lets see how many people are also joining this contest. The result will be published mid-January. At least I’m last, but that’s not wicked. I had a lot of fun and even learned something. That’s the main thing. It’s taking part that counts! ;-)

I attached my bot, it’s licensed under GPLv3. In some further articles I’ll explain some smart details of my code, I think some of them are quiet nice to know.

Download: Java: Repository @ GitHub (Please take a look at the man-page. Browse bugs and feature requests.)

Vim plugin for R

Just found a very nice plugin for using R in Vim. It’s unbelievable comfortable!

There are at least two ways to install it. If your are working on a Debian based distro you can use the .deb package provided by the author Jakson Alves de Aquino itself. On this site you’ll also find some smart screen shots. Another way is the installation by hand (I did so). Download the package, in your download directory type something like this:

mkdir -p ~/.vim 
unzip vim-r-plugin-*.zip -d ~/.vim

Yes, that’s it! To start an R session just open a R-file ( .R or .Rnw or .Rd ) with vim and type \\rf . To close the session type \\rq (not saving hist) or \rw (saving history). The handling needs to getting used to.. Here is a list of common commands from the documentation (might want to print them as a cheat sheet!?) :

  . Start R (default)                                    \\rf
  . Start R --vanilla                                    \\rv
  . Start R (custom)                                     \\rc
  . Close R (no save)                                    \\rq
  . Close R (save workspace)                             \\rw

  . File                                               \\aa
  . File (echo)                                        \\ae
  . File (open .Rout)                                  \\ao
  . Block (cur)                                        \\bb
  . Block (cur, echo)                                  \\be
  . Block (cur, down)                                  \\bd
  . Block (cur, echo and down)                         \\ba
  . Function (cur)                                     \\ff
  . Function (cur, echo)                               \\fe
  . Function (cur and down)                            \\fd
  . Function (cur, echo and down)                      \\fa
  . Selection                                          \\ss
  . Selection (echo)                                   \\se
  . Selection (and down)                               \\sd
  . Selection (echo and down)                          \\sa
  . Paragraph                                          \\pp
  . Paragraph (echo)                                   \\pe
  . Paragraph (and down)                               \\pd
  . Paragraph (echo and down)                          \\pa
  . Line                                                \\l
  . Line (and down)                                     \\d
  . Line (and new one)                                  \\q

  . List space                                         \\rl
  . Clear console                                      \\rr
  . Clear all                                          \\rm
  . Object (print)                                     \\rp
  . Object (names)                                     \\rn
  . Object (str)                                       \\rt
  . Arguments (cur)                                    \\ra
  . Example (cur)                                      \\re
  . Help (cur)                                         \\rh
  . Summary (cur)                                      \\rs
  . Plot (cur)                                         \\rg
  . Plot and summary (cur)                             \\rb
  . Update Object Browser                              \\ro
  . Set working directory (cur file path)              \\rd
  . Build R tags file                   :RBuildTags
  . Build omniList (loaded packages)    :RUpdateObjList
  . Build omniList (installed packages) :RUpdateObjListAll
  . Sweave (cur file)                                  \\sw
  . Sweave and PDF (cur file)                          \\sp
  . Go to next R chunk                                  gn
  . Go to previous R chunk                              gN

But if you got used to, it’s very handy! At the start-up it opens a new R-console (just close it, doesn’t matter) and you can send single lines, a block or a whole file to R (see the documentation). Every thing I tried worked really fine!

A small example in action is presented in the image. In an earlier post I explained how to produce such a title consisting of R objects and Greek letters.

I’ve attached the documentation of this plugin, first and foremost for me for cheating, but of course you’re allowed to use it also ;-)

Download: HTML: Vim-R-plugin documentation (Please take a look at the man-page. Browse bugs and feature requests.)

Open Research Computation

I want to announce a new scientific journal: Open Research Computation.

I think it sounds quiet interesting, citing their aims & scope:

Open Research Computation publishes peer reviewed articles that describe the development, capacities, and uses of software designed for use by researchers in any field. Submissions relating to software for use in any area of research are welcome as are articles dealing with algorithms, useful code snippets, as well as large applications or web services, and libraries. Open Research Computation differs from other journals with a software focus in its requirement for the software source code to be made available under an Open Source Initiative compliant license, and in its assessment of the quality of documentation and testing of the software. In addition to articles describing software Open Research Computation also welcomes submissions that review or describe developments relating to software based tools for research. These include, but are not limited to, reviews or proposals for standards, discussion of best practice in research software development, educational and support resources and tools for researchers that develop or use software based tools.

Looking forward…

You may also be interested in a more detailed announce: Can a journal make a difference? Let’s find out.

Similar to ...

one of my idols. At least twitter thinks so! I’m proud.

Value of an R object in an expression

Just wanted to create an expression, existing of some mathematical annotation and a value of an R object. Wasn’t that intuitive!

Each single goal is easy to reach, for example to combine a value of an R object with text just use paste :

> n = 5
> paste ("n=", n, "!")
[1] "n= 5 !"

To have a plot title with an you can use expression :

> plot(1:5, runif(5, 1, 4), main=expression("this is a " * alpha[1] * " example"))

But to let the the title of a plot contain objects and Greek letters isn’t that easy. Those of you who think it’s just about combining paste and expression might try it on their own and come back head-ached after few minutes of unsuccessful testings.

The problem is, that expression interprets chars as expression and not as object identifier, of course, how should it know whether you mean the var alpha or the Greek letter!? The solution is called substitute ! With substitute you can replace objects inline, here is a small example:

> var=10
> substitute(paste("here is the content: ", v), list(v=var))
paste("here is the content: ", 10)

You see, substitute got a list what to substitute and replaces the v in paste with the content of var . Run eval to evaluate to result:

> var=10
> eval(substitute(paste("here is the content: ", v), list(v=var)))
[1] "here is the content:  10"

Now it’s easy to create a more complex plot title:

> var=10
> plot(1:5, runif(5, 1, 4), main=substitute(paste("here ", lambda[1], "=", v, " and ", epsilon^2, "=", b, "!"), list(v=var, b=var^2)))

Go out and produce imposing graphs! (-;

Too much at once

Just installed a new Grml system, annoyingly from a bit too far outdated image so aptitude fails to handle everything at once…

Here is the error:

Reading package fields... 52%/usr/lib/ruby/1.8/debian/utils.rb:47:in 'pipe': Too many open files (Errno::EMFILE)
        from /usr/lib/ruby/1.8/debian/utils.rb:47:in 'pipeline'
        from /usr/lib/ruby/1.8/debian/utils.rb:86:in 'tar'
        from /usr/lib/ruby/1.8/debian.rb:142:in 'load'
        from /usr/lib/ruby/1.8/debian/utils.rb:75:in 'gunzip'
        from /usr/lib/ruby/1.8/debian/utils.rb:40:in 'pipeline'
        from /usr/lib/ruby/1.8/debian/utils.rb:72:in 'gunzip'
        from /usr/lib/ruby/1.8/debian.rb:141:in 'load'
        from /usr/lib/ruby/1.8/debian/ar.rb:150:in 'open'
        from /usr/lib/ruby/1.8/debian/ar.rb:147:in 'each'
        from /usr/lib/ruby/1.8/debian/ar.rb:147:in 'open'
        from /usr/lib/ruby/1.8/debian.rb:140:in 'load'
        from /usr/lib/ruby/1.8/debian.rb:82:in 'field'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:733:in 'field'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:751:in 'create'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:743:in 'each_index'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:743:in 'create'
        from /usr/sbin/apt-listbugs:323
/usr/lib/ruby/1.8/debian.rb:198:in 'parseFields': E: required field Package not found in  (Debian::FieldError)
        from /usr/lib/ruby/1.8/debian.rb:196:in 'each'
        from /usr/lib/ruby/1.8/debian.rb:196:in 'parseFields'
        from /usr/lib/ruby/1.8/debian.rb:439:in 'initialize'
        from /usr/lib/ruby/1.8/debian.rb:150:in 'new'
        from /usr/lib/ruby/1.8/debian.rb:150:in 'load'
        from /usr/lib/ruby/1.8/debian.rb:82:in 'field'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:733:in 'field'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:751:in 'create'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:743:in 'each_index'
        from /usr/share/apt-listbugs/apt-listbugs/logic.rb:743:in 'create'
        from /usr/sbin/apt-listbugs:323
E: Failed to fetch 404  Not Found
E: Sub-process /usr/sbin/apt-listbugs apt || exit 10 returned an error code (10)
E: Failure running script /usr/sbin/apt-listbugs apt || exit 10
A package failed to install.  Trying to recover:
Press return to continue.

Aha, too many open files.. So I had to install everything piecewise in a disturbing manner..

Btw. updating iptables 1.4.6-2 -> 1.4.10-1 before xtables-addons-common 1.23-1 -> 1.26-2 is a bad idea and fails for some reasons. So try to do it the other way round.

Crypto off

if you haven’t noticed yet: SSL is turned off…

Of course it isn’t really turned off, all content is still available through encrypted connections (all links are still working), but it’s disabled by default.

But why!? I got a lot of mails during the last weeks, telling me that there is a problem with my SSL cert. Yes, your browser is completely right, my cert isn’t valid because I’ve signed it by myself.. To get a trusted certificate that your browser recognizes to be valid is very expensive. For a cheap one I still have to pay about $100, that’s neither worthy nor affordable for me and my private blog. But I’m always interested in ideally offering secure mechanisms, so I tried to provide SSL. Another reason for SSL was my auth stuff. Wordpress doesn’t provide both SSL and SSL-free access. In an installation you have to decide whether to use https://... or http://... for URL’s. So all links are either to SSL encrypted content or the next click is unencrypted. Don’t ask me why they don’t check whether SSL was turned on/off for the last query and decide afterwards on using SSL for all further links.. However, I didn’t want to authenticate myself unencrypted and so I enabled SSL by default.

To be congenial to my visitors I turned off SSL, until somebody sponsors a valid certificate. There are also many disgusting tools having problems with my website, so it might be the better way to deliver unencrypted contend. The information on my site isn’t that secret ;-)

As a consequences you aren’t able to register/login anymore. I scripted a little bit to find a secure way for authenticating myself, but you aren’t allowed to take this path :-P Nevertheless, comments are still open and doesn’t require any authentication.

If you can find any SSL zombies please inform me!

ShortCut[siblings]: tail and its derivatives

Every text-tool-user should know about tail! You can print the last few lines of a file or watch it growing. But there are three improved derivatives, just get into it.

I think there is no need for further explanation of tail itself, so lets begin with the first derivative.


colortail is based on tail with support for colors, so it helps to keep track of important content. Common options and parameters are resembled closely to them of tail, so it won’t be a big adjustment to new circumstances for tail fans. The content that it presents is of course the same as if it comes from tail, but colorized ;) With -k you can additional submit a configuration file that defines some regular expressions and its colors. On a Debian some examples can be found in /usr/share/doc/colortail/examples/ . In figure 1 you can see an example output of colortail on the syslog of a virtual machine.


The second tool in this article is multitail. Like colortail it can colorize the output, but all is presented in a ncurses based user interface so it is able to create multiple windows on your console. If you open a file in multitail it’s automatically in a following mode ( -f in case of tail and colortail). If you are monitoring multiple log files your console is split horizontal or vertical or a mix of both. You can pause the output, search for regular expressions and a lot more. Enter F1 to get a small help window. Figure 2 presents a sample output. Its project page keeps much more information.


logtail pursues a different goal. It’s not interested in prettifying the output, it remembers the content that was still displayed and just prints the differences to the last run. So it is an ideal tool for log analyzer, log messages doesn’t have to be parsed multiple times. logtail is written in perl, you can also monitor logfiles on different machines.

I hope I could give you some smart inspirations.

OpenNIC DNS network

DNS look-ups are a very sensible topic. Of course you want very fast name-to-IP resolutions, but should you always use Google’s DNS server? After all they can keep track of all your network motion profile unless you are surfing by IP! Today I read about the OpenNIC Project and ran some speed tests. It’s very interesting and worthy to know about!

The project about itself:

OpenNIC (a.k.a. "The OpenNIC Project") is an organization of hobbyists who run an alternative DNS network. [...] Our goal is to provide you with quick and reliable DNS services and access to domains not administered by ICANN.

Ok, I gave it a try and implemented a Perl-script that checks the speed. It throws a dice to call one of my often used domains and digs1 each of my predefined DNS servers to save the query time. I tested the following DNS server:

  • : one server of the OpenNIC project, located in Germany
  • : one server of the OpenNIC project, located in Germany (NRW)
  • : Google’s public DNS server, proven to be fast and reliable
  • : my ISP’s server
  • : name server of our university

Find the Perl code attached.

And here are the results after 10000 qeuries:

IPProvider10000 queries ISP131989 ms ms ms ms of uni-halle.de394134 ms

As you can see, my ISP’s DNS server is the fastest, they may have optimized their internal infrastructure to provide very fast look-ups to its customers. But it is also nice to see, that there is one OpenNIC server that is faster than google! And this server comes with another feature: It doesn’t track any logs! Isn’t that great!?

To find some servers near you just check their server list. Some of them don’t record logs or anonymize them, and of course all of them are independent from ICANN administrations.

I can’t recommend to use any special DNS server, but I want to advise to test them and find the best one for your demands! Feel free to post your own test results via comment or trackback.

1 dig is part of the larger ISC BIND distribution

Download: Perl: pipapo/scripts/ (Please take a look at the man-page. Browse bugs and feature requests.)

Boot messages to service console

You may have heard about management consoles!? If a server is dead you can revive it via service console without driving the long way to the data center (often miles away).

While logged into the service console you of course have the chance to reboot the machine itself. To get to know what it is doing while booting you may want to see all the messages that are usually prompted to the terminal at the attached monitor. Unfortunately you aren’t next to the machine, and so there is no monitor attached to it, but you can force grub to prompt all messages both to terminal and to service console.

First of all you have to setup the serial console:

serial --unit=0 --speed=57600 --word=8 --parity=no --stop=1

The --unit parameter determines the COM port, here it’s COM1, if you need COM2 you should use --unit=1 . --speed defines a baud rate of 57600 bps, see your manual. To learn more about the other parameter you are referred to the Grub manual for serial. Next you have to tell Grub where to write the output:

terminal --timeout=5 console serial

This line tells grub that there are two devices, the typical console on the attached screen and our previous defined serial console. With this directive Grub waits 5 seconds for any input from serial console or the attached keyboard and will print its menu to that device where the input was generated. That means if you’re at home and press any key, Grub will show you all outputs to your serial connection, but your student assistant (who had to go to the server, by bike while raining!!) isn’t able to see whats happening. But if your assistance is faster than you and hits a key on the physically attached keyboard, he’ll see anything and you’ll look through a black window… If nobody produces any input the output is written to that device that is listed first.

Last but not least you have to modify the kernel sections of the boot menu and append something like that at the end of every kernel line:

console=tty0 console=ttyS0

That tells grub that all kernel messages should be printed to both the real console of the attached screen and the serial console. Keep in mind to modify ttyS0 to match your serial port (here it is COM1). Grub decides for the device that is listed last to also send all stdin/stdout/stderr of the init process, that means only the last device will act as interactive terminal. E.g. checks of fsck are only printed to the last device, so stay calm if nothing happen for a long time on the other one ;-)

Here is a valid example for copy and paste:

# init serial console
serial --unit=0 --speed=57600 --word=8 --parity=no --stop=1
# what device to use for grub menu!?
terminal --timeout=5 console serial
# ....
title           Debian GNU/Linux, LOCAL CONSOLE
root            (hd0,0)
kernel          /vmlinuz-SOMEWHAT-openvz-amd64 root=UUID=AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE ro console=ttyS0 console=tty0
initrd          /initrd.img-SOMEWHAT-openvz-amd64

title           Debian GNU/Linux, LOCAL CONSOLE
root            (hd0,0)
kernel          /vmlinuz-SOMEWHAT-openvz-amd64 root=UUID=AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE ro console=tty0 console=ttyS0
initrd          /initrd.img-SOMEWHAT-openvz-amd64

Here both Grub entries are booting the same kernel, but the first one will use the local console as interactive terminal whether the other entry takes the serial console for interactions.