Evolving The Blind Watchmaker

Recently I’ve been reading the classic book by Richard Dawkins, The Blind Watchmaker. In it he begins by discussing how evolution can produce complex systems from only a few simple rules. He demonstrates this using a simple tree drawing algorithm in which a few ‘genes’ control aspects such as the number of branches and the branch angle. The trees are evolved solely through mutation of an initial tree, rather combing the ‘genes’ of two trees to produce a child, and introducing mutations in those children.

In reality evolution is driven by pressures from the environment on the genes and those that produce the fittest host will survive. As this is early in the book though Dawkins uses himself as the environment and manually picks the most visually appealing trees.

Although the book is essentially timeless as although new evidence is continually being found in favour of evolution, the general thrust remains true. The passages where he talks about his computer, however, have dated horribly (which is not surprising given it was first published in 1986!). In this post I’ll describe how to recreate the section where he describes evolving trees in Python so you can create your own trees on your pc.

Read More...

Simplifying Django dependencies with virtualenv

virtualenv is a tool for simplifying dependency management in Python applications. As the name suggests, virtualenv creates a virtual environment which makes it easy to install Python packages without needing root privileges to do so.

To use the packages installed in a virtual environment you run the activate script in the bin directory of the virtual environment. This is fine when you’re working on the command line, but you don’t want to have to remember this step when running the debug server, and it’s hard to get that to work when the site is deployed under mod_wsgi.

To make things easier you can add the appropriate directory from the virtual environment to Python’s path as part of manage.py, or the appropriate fcgi or wsgi control script.

import os
import sys
import siten
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
site.addsitedir(os.path.join(root_dir, 've/lib/python%i.%i/site-packages'
                % (sys.version_info[0], sys.version_info[1])))

Just add the code above to the top of your manage.py file and the ve virtual environment will always be activated when you run the script.

Read More...

Making History by Stephen Fry Book Review

This book poses an interesting question, what would happen if you could stop Adolf Hitler from being born? Ask anyone if they had the choice, would they take it and I imagine that almost everyone would say yes. When Michael, the lead character in this story has that choice he takes it with both hands. Unfortunately though, things do not go according to plan.

Stephen Fry is a British institution and a well known upper class intellectual. In this book he is clearly writing about what he knows as it focuses on a post-graduate student at Cambridge. The book is full of colour and detail and has an air of authenticity that draws you into the world effortlessly. There seems to be a significant amount of himself in the lead character and he writes as he talks. At first I found the overly intellectual mode of writing to be annoying and distracting from what the author was trying to say. Persevere though, and you’re rewarded with a charming, warm and funny story that will also make you think about history and the choices we make.

This book can easily be described a genre-defying as the time-travel premise means it clearly fits into science fiction. Don’t worry though, this book is not about spaceships or lasers as the two moments of time-travel are tiny compared to their consequences, and combined with flashbacks into the two world wars, the book fits into historical fiction as well. Is historical science fiction a genre? It is now.

This book was first published in 1996, and if you haven’t read in the last fifteen years then you should definitely go and hunt down copy. You’ll read it and imagine that it was written yesterday.

Read More...

Wii DVD

This weekend I brought Super Mario Galaxy 2 for the Wii. I greatly enjoyed the first one, and it’s one of the few games that me and my girlfriend can play together.

It’s a pretty easy game to pick up, but for this one Nintendo included a tutorial DVD. Two questions immediately spring to mind here. Firstly, what can you do with a DVD that you can’t do with an in-game, interactive, tutorial. Secondly, why is this a DVD that you can’t play on the Wii?

Let me just say that again.

Why is this a DVD that you can’t play on the Wii?

To watch the tutorial you need to turn off your Wii, turn on your DVD player, watch the DVD, and then go back to your Wii. I’d love to know how Nintendo came to this decision, because it drastically slow you down your first experience of playing the game, and those that are mostly likely to want to watch the video are those who will struggle to switch over to the DVD player.

Come on Nintendo, you can do better than this.

Read More...

Continuous Integration Testing

At work we recently set up Buildbot to replace an in-house continuous integration tool that never really took off. I’ve used Buildbot before, in a hobby capacity, but using it my day job has really brought home to me how important not only testing is, but testing continuously.

Buildbot is pretty simple to explain. Every time you make a commit to your source control system this triggers buildbot to run a series of steps over your code. What these steps are is totally configurable by you. Typically though, you’ll configure it to check out your code, compile it and run unit tests.

I’m a big fan of test driven and issue driven development. With these two methodologies when you want to make a change you record the issue in your bug tracking software, then write a test that detects the deficiency in your code. Once you’ve done that you can start actually making the change that you wanted to make in the first place. By writing down the issue you’re forced into thinking about the change that you want to make, and creating the test ensures that you know when it’s complete.

Read More...