Chad's Logs

Botswana: Bot Wars

Announcing the release of Botswana!

A few years ago I took an artificial intelligence class where we learned how to do AI stuff with a game called BZFlags. It was a modified version of the game and was essentially capture the flag. We got to program bots (tanks) in the game to do ‘intelligent’ things and try to win the game by capturing the flag.

A bit ago I was talking to my friend Ben about games like this and we decided to build our own. The code is open source and on GitHub. The whole thing is written in javascript and should work in modern browsers. We simplified the coding of bots too, there are samples bots that you can look at, but essentially a bot returns 1 of 5 commands to the server each turn; forward, backward, left, right, fire.

Feel free to play with it. If you run into any issues/problems/bugs or have any questions for me, let me know. Enjoy.

Botswana screen shot

Posted in Code, Web |

conky for my desktop

At work I have a todo list that I maintain in a simple text file on my system. This todo list looks create and is readable on the command line (using cat) and in vim. However, I was really wanting it in a place where I could see it at a glance.

Also sometimes I miss the Ubuntu notifications in the top right corner of the screen (my background is black and the notifications don’t stand out on a black background since they are also black (I can’t wait until we can easily customize the notification system theme, anyone know how to do that yet?)).

Another item of information that I love to have visible at all times is the list of my co-workers who are currently online (logged into IM). This helps if I need to ask one of them a quick question.

The solution: Conky

At first conky may scare you, I know it did me. The configuration files have a little bit of a learning curve that may be too steep for some. Conky is mainly used as a “light weight system monitor”. I however don’t need a system monitor (I’ve never really used the information they provide while I am on my desktop computer). System monitors are great for a laptop where I need to worry about what processes might be cramping my speed or draining my battery. I might also use the system monitor to check the temperature of my laptop or the battery level. For my desktop however I don’t need (or want) that stuff. Thankfully conky is so much more than a “light weight system monitor”
I can set up scripts to run at any interval I would like and display the output in a nice way in a place where I can (almost) always see it.

Here is my conky configuration file:

background yes
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes

text_buffer_size 1024

use_xft yes
xftfont Inconsolata:size=12
#xftfont Angleterre Book:size=10

alignment top_right
gap_x 20
gap_y 20
maximum_width 400

TEXT

${font Cash Font:bold:size=12}${color #444}TODO:  ${hr 7}

${font}${color gray}${execpi 60 /home/chansen4/conkyTodo.py work}

${font Cash Font:bold:size=12}${color #444}NOTIFICATIONS:  ${hr 7}

${font}${color gray}${execpi 10 /home/chansen4/bin/getLastNotify.py}

${font Cash Font:bold:size=12}${color #444}PEEPS:  ${hr 7}

${execpi 10 conkyPidgin -I co-workers -C C -W U -A A -o -t ~/conkyPidgin.template}

Everything after the “TEXT” is what is displayed (before that are just settings). If you want to change some setting or another you start with the $ (dollar sign) and in {} (curly braces) afterwards specify the property to change and the value to be set.

For example: ${font Cash Font:bold:size=12} sets the font to be the “Cash Font” font, makes it bold and sets the size to 12 point. ${color #444} sets the color to be hex 444. ${hr 7} creates a horizontal rule of 7 pixels thick.

The real interesting part though are the ${execpi commands (the format for these commands is ${execpi [RUN TIME IN SEC] [SCRIPT], not too difficult). This will run an executable script and parse the output at more conky configuration code. There are three such calls in my configuration file. conkyTodo.py (my own script to parse my todo list and display it nicely in conky), getLastNotify.py (once again, my own script to parse the notify-osd.log file to get the last 4 notification messages and display them nicely in conky), and conkyPidgin (which is part of the conky hardcore package and gives one access to the Pidgin contacts).

If any of this is too confusing or you would like some more information/clarification just leave a comment and I will do my best to answer your questions. Thanks!

My current conky theme at work

My current conky theme at work

Update:
Here is my getLastNotify.py script.

Update 2:

I started a github project for the above script.

Posted in Code, Linux | Tagged , , |

removing the top N lines from a file

Just a quick post here.
I was messing around with some pretty large text files yesterday. I had a file with 2.9 million insert statements (one per line) that I was running on a database. It was taking forever so I stopped it. I new how many of the insert statements had run so I needed to get rid of the top million and a half so that they were not inserted again. I came across this nifty one-liner that made it really easy and didn’t take too long:
sed '1,1500000d' inserts.sql > inserts2.sql
Now I will explain what I understand it to be doing. sed is a command that is very powerful (I don’t know the first thing about using it really) for working with text and files. The 1,1500000 indicates that I want to do something to lines 1-1500000 of the file. The d tells sed that I want to delete those lines. Then specify the file you want to do that do and output the remaining contents (>) to a new file insert2.sql.

Pretty simple, but sed can be pretty involved.

Posted in Code, Linux | Tagged , , |