07 Mar 2012
A little while ago I was asked what my biggest gripe with Django was. At the time I couldn’t think of a good
answer because since I started using Django in the pre-1.0 days most of the rough edges have been smoothed.
Yesterday though, I encountered an error that made me wish I thought of it at the time.
The code that produced the error looked like this:
from django.db import models
class MyModel(model.Model):
...
def save(self):
models.Model.save(self)
...
...
The error that was raised was AttributeError: 'NoneType' object has no attribute 'Model'. This means
that rather than containing a module object, models was None. Clearly this is impossible as the class
could not have been created if that was the case. Impossible or not, it was clearly happening.
Read More...
10 Feb 2012
After a two week gap the recent snow in the UK has
inspired me to get back to my series of posts on my weather station website,
WelwynWeather.co.uk. In this post I’ll discuss the
records page, which shows details such as the highest and
lowest temperatures, and the heaviest periods of rain.
From a previous post in this series you’ll remember that
the website is implemented as a CouchApp. These are Javascript functions that run
inside the CouchDB database, and while they provide quite a lot of flexibility you do need to tailor your
code to them.
On previous pages we have use CouchDB’s map/reduce framework to summarise data then used a list function to
display the results. The records page could take a similar approach, but there are some drawbacks to that.
Unlike the rest of the pages the information on the records page consists of a number of unrelated numbers.
While we could create a single map/reduce function to process all of them at once. That function will quickly
grow and become unmanageable, so instead we’ll calculate the statistics individually and use AJAX to load them
dynamically into the page.
Read More...
02 Feb 2012
I could wax lyrical about how programming is an art form and requires a great deal of creativity. However,
it’s easy to loose focus on this in the middle of creating project specs and servicing your
technical debt. Like
many companies we recently held a hackathon event where
we split up into teams and worked on projects suggested by the team members.
Different teams took different approaches to the challenge, one team set about integrating an open source code
review site in our development environment, others investigated how some commercial technologies could be
useful to us. My team built a collaborative
filtering system using MongoDB. I’ll post about that project in the future, but in this post I wanted to
focus on what we learnt about running a company Hackathon event.
If you’re lucky you’ll work in a company that’s focused on technology and you’ll always be creating new and
interesting things. In the majority of companies technology is a means to a end, rather than the goal. In that
case it’s easy to become so engrossed in the day to day work that you forget to innovate or to experiment with
new technologies. A hackathon is a great way to take a step back and try something new for a few days.n
Running a hackathon event should be divided into three stages, preparation, the event and the post event.
Before the event you need to take some time to collect ideas and do some preliminary research. The event
itself should be a whirlwind of pumping out code and building something exciting. Afterwards you need to take
some time to demonstrate what you’ve built, and share what you’ve learnt.
Read More...
23 Jan 2012
A hobby project of mine would be made much easier if I could run the same code on the server as I run in the
web browser. Projects like Node.js have made Javascript on the server a more
realistic prospect, but I don’t want to give up on Python and
Django, my preferred web development tools.
The obvious solution to this problem is to embed Javascript in Python and to call the key bits of Javascript
code from Python. There are two major Javascript interpreters,
Mozilla’s SpiderMonkey and
Google’s V8.
Unfortunately the python-spidermonkey project is
dead and there’s no way of telling if it works with later version of SpiderMonkey. The
PyV8 project by contrast is still undergoing active
development.
Although PyV8 has a wiki page entitled How To
Build it’s not simple to get the project built. They recommend using prebuilt packages, but there are none
for recent version of Ubuntu. In this post I’ll describe how to build it on Ubuntu 11.11 and give a simple
example of it in action.
Read More...
20 Jan 2012
In this series of posts I’m describing how I created a CouchDB
CouchApp to display the weather data
collected by the weather station in my back garden. In the
previous post I showed you how to display a single day’s
weather data. In this post we will look at processing the data to display it by month.
The data my weather station collects consists of a record every five minutes. This means that a 31 day month
will consist of 8,928 records. Unless you have space to draw a graph almost nine thousand pixels wide then
there is no point in wasting valuable rending time processing that much data. Reducing the data to one point
per hour gives us a much more manageable 744 data points for a month. A full years worth of weather data
consists of 105,120 records, even reducing it to one point per hour gives us 8760 points. When rendering a
year’s worth of data it is clearly worth reducing the data even further, this time to one point per day.
How do we use CouchDB to reduce the data to one point per hour? Fortunately CouchDB’s map/reduce architecture
is perfect for this type of processing. CouchDB will also cache the results of the processing automatically so
it only needs to be run once rather than requiring an expensive denormalisation process each time some new
data is uploaded.
Read More...