on Tuesday, August 28, 2012
Today I had to use Redis for the first time which doesn’t seem very well supported under Windows at this point. Coming from Linux I try to use Cygwin under Windows as often as I can. So here is what I did to build the latest Redis version (there were some old binaries for download but I wanted to use a newer version). First make sure you have the Cygwin packages “make” and “gcc” installed. Then open a Cygwin terminal and follow the steps under “Installation” but do not run “make” yet. Before you run “make” open the file src/redis.c and add the following block somewhere on top of the file (I have copied it just one line before the #include statement):

This is a manual change which I found in this issue. Finally run “make”. Ignore the warnings. If all goes well, you should have a bunch of new .exe files at the end. redis-benchmark.exe, redis-check-aof.exe, redis-check-dump.exe, redis-cli.exe and redis-server.exe – copy them into the bin folder of your Cygwin installation and restart the terminal. To test execute “redis-cli -h <your-redis-server> -p <your-redis-port> ping” and hopefully get a pong back.
on Tuesday, August 7, 2012
Next week I'll be changing jobs inside EA. My time at Playfish will be over and I will be working for another studio in Stockholm. Playfish mail is running on the Google mail infrastructure. I am sure I won't be able to access my corporate mail account after I have left, so I thought it was a good idea to get a backup of all my corporate emails. One promising program is gmvault, which I found after stumbling upon an old Matt Cutts blog post about backing up Gmail on Linux yay. Matt is suggesting getmail to get the job done but the project seems to be dead since 2009.

I am running Ubuntu 10.04 Lucid Lynx. First I installed me a new virtualenv, which you should always do if you are required to install new pip packages (gmvault). Just follow these instructions to get started with virtualenv. Once you have your virtualenv activated run pip freeze, to check what packages are installed. If you created the virtualenv with the –no-site-packages option like me, there should be 2 packages distribute and wsgiref. Make sure the distribute package is at least in version 0.6.24. On my Ubuntu 10.04 I needed to upgrade.

Finally install gmvault in your virtualenv and run it.

First it will print some instructions for you. After pressing Enter a browser window is opened and you have to log into your mail account. You will be told that the program gmvault wants to access your credentials. Click accept. This will store a Gmail XOAuth token to your local disc, i.e. as /home/user/.gmvault/reik.schatz@old-company.com.oauth. This token is now used by gmvault to access your email account. Press Enter again and start the download. It took about 3 minutes for 1200 emails to be downloaded via imap. On a side note, if you want to learn more about imap and python, you should read this great book which I just finished.
on Tuesday, July 17, 2012
Done compiling a FiSH module for irssi, which runs on Debian 6.0.5 64-bit. As some of the guides out there are somewhat broken, because links have changed and so on, I decided to post a newer version here.

First verify what system you are running on.

Alright, so we are on Debian x86_64. Lets install some prerequisites.

This will install you irssi and some irssi sources in the same version (0.8.15 on Debian 6.0.5). Now run the following commands line by line. This is basically following this or this guide, but some of the links have changed.

Now it's time to update the Makefile. Change the first 3 lines to the following values.

Make sure these directories exist. They should have been created earlier when installing the packages above. Double check that glib_inc contains glib.h and gmodule.h. Finally run:

This might give you some warnings but if you didn't get any errors, you should now have a libfish.so file. If you get error messages, start reading the make output from the top. The first time I tried, it couldn't include glib.h and gmodule.h because I had the wrong directory configured in Makefile.

To use you new fish module, copy it to the proper location.

To autoload the fish module during irssi startup add a line to you startup file.

Voila enjoy encrypted irc chat.
on Friday, June 1, 2012
Today I spent some time chasing ghosts and a missing textarea value in my POST data. All form elements were posted correctly but the textarea was missing. I am using the WYMeditor for the textarea to turn the element into a rich text field. The textarea was missing from the POST data because it has it's style attribute set to display:none. This is something that the class="wymeditor" attribute does to the textarea. The important bit is the submit button which also needs a class attribute. Something I had missed when copying from the demo page for the WYMeditor. After giving the submit button a class="wymupdate" everything works just fine.
on Thursday, May 31, 2012
Currently I am working on a web application which is based on the Tornado web framework. After reading this excellent blog post I felt motivated to be a bit more strict about TDD with Python. Similar to the code form Tomas, my tornado.web.Application is receiving a peer object in it's init method. The peer is a DAO object wrapping access to a MongoDB database called MongoDbDao. To access MongoDB I am using the PyMongo distribution which heavily uses pymongo.cursor.Cursor objects. These Cursor objects are then returned from my MongoDbDao. Maybe thats not the greatest idea as it leaks out some implementation details from the DAO class. But Cursors itself are nice, so I decided to always return a pymongo.cursor.Cursor.

This however was a bit annoying in unit tests. These tests are not executed against a real database, I am mocking the MongoDbDao instead. When using a pymongo.cursor.Cursor, the only thing I am doing in production code is iteration over the results or checking if there were any results using the count function. So here is what I came up with for the unit test.

This is basically a UserList that has the count function of the pymongo.cursor.Cursor added to it (not really using the with_limit_and_skip argument at the moment). I found this to be easier than creating a stub with Mockito every time I want to return a Cursor that can be iterated or checked for it's size.