Archive for November, 2011

Election visualisation

Sunday, November 27th, 2011

I have hacked up a booth-by-booth visualisation of votes in Wellington Central. The visible (non-occluded) area of each circle is proportionate to the party vote received, and the circles proceed inwards from most votes. It only shows the top three five parties at each booth at the moment (from skimming over the data, further down than that they become negligibly small). It’s not really as interesting as I’d hoped, but I may try it on other electorates that might show something better later on.

Update: I’ve extended it to the top five, rather than three, parties, and it gets a little more interesting then. The fifth-place party varies quite a bit.

Update 2: More electorates:

Announcing retail – tail with regular expressions

Saturday, November 26th, 2011

I have broken down and implemented my own tail command. retail can output that part of a file (or pipe) following the last match of a regular expression, which can be useful for logfiles and various other kinds of data. It is also a fully compliant implementation of the POSIX.1-2008 tail command, so you can theoretically replace your system tail with it.

The driving use case of this for me is log files – I want to get all of the file after the current occurrence of some event. After establishing that I couldn’t do that with sed, and that although I probably could with awk it would be a bad idea, I set about writing this in C. It does exactly what I want, and I’ve also been over the POSIX tail spec to add everything from that as well, so it is a usable tail command.

The code is on GitHub (for the moment at least), accessible with `git clone git://github.com/mwh/retail.git`, or in an automatic tarball https://github.com/mwh/retail/tarball/master . Although it satisfies my original use-case there are a couple of additions I’d still like to make along with efficiency improvements, and, of course – patches welcome.

Some usage examples:

retail -r Beginning logfile.log

Output everything after the last occurrence of “Beginning” in the file.

retail -r Beginning -u 'succeeded|error' -f logfile.log

Same as the last one, and continue reading as any lines are appended until one matches /succeeded|error/ (i.e., it contains either of those words), and then terminate.

retail -n +10

Start printing at line 10, until the end of the file. Just like in regular tail. Negative numbers, bare [-+]N, and -c work too.

Once more, retail.