Playing Possum

March 31st, 2009
A possum

An Opposum

No reason, I just love this little guy. I think I will use a possum as a mascot for my next creation – whatever that may be!

I don't know why people don't like Possums. I wouldn't mind one for a pet.

Here is what Wikipedia has to say on the subject:

Didelphimorphia (pronounced /daɪ.dɛlf.ə.mɔə/) is the order of common opossums of the Western Hemisphere. They are commonly also called possums, though that term is also applied to Australian fauna of the suborder Phalangeriformes. The Virginia Opossum is the original animal named opossum. The word comes from Algonquian wapathemwa. Opossums probably diverged from the basic South American marsupials in the late Cretaceous or early Paleocene. A sister group is Paucituberculata (shrew opossums).

Full article from Wikipedia


Misleading ImportErrors in Django

March 30th, 2009

I was debugging an issue with our Django app at work today; an file wasn't being picked up, and nothing was appearing in the admin pages. It turned that an ImportError was being thrown in the and Django was interpreting this as the file not existing.

I'm assuming that the reason for this is that Django uses __import__ to import the module, and catches ImportError's if the doesn't exist. The trouble with this is that if does exist, and throws an ImportError of its own, Django will also interpret that as a missing – which can be misleading.

The only solution I can think of to more accurately handle this would be to programmaticaly examine the traceback to determine where the ImportError is thrown. If the traceback is one level deep, we know that the ImportError was thrown because the module doesn't exists. If it is greater than one level then we know the module was found, but has thrown an ImportError of its own.

Here's a simple proof of concept:
import traceback
import sys

def check_import(name):
    except ImportError:
        exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
        return len(traceback.extract_tb(exceptionTraceback)) > 1
    return True

print check_import("os")
print check_import("noimport")
print check_import("anotherlevel")
import thismoduledoesnotexist

This produces the following when run:


It would be nice if Django did something similar for its implicit imports. I think the best behaviour would be re-raise the ImportError if it the module does actually exist. That way, it is clear what the problem is. I may attempt to write a patch at some point, unless someone knows of a better solution.


On Ego and Software Development

March 28th, 2009

I've been thinking a lot about ego lately, and how it applies to software development. Writing software – like any other human endeavor – is influenced by the need to be recognized and hopefully praised for our work. I am no different; it is most likely ego that drives me to release open source software and to refine it even when there is no direct benefit to be had for that work. In this respect, ego is beneficial as it compels me to writer better code, but in the context of a day-job work, ego is a liability.


Improving video player applications with an old-school feature

March 25th, 2009

Dear video player application writers, there is a simple feature that would improve my movie watching experience greatly. A feature that I have never seen implemented – on Linux or Windows, and that is the ability to remember the position in a video file where I stopped watching. With current video players, if I want to finish watching a movie that I started watching the day before, I have to drag the slider around and to do a mental binary search to find the point where I left off. What I would like the player to do is to remember where I left off and start playing from that point when I open the file again.

A VHS cassette

Remember these?

There is an obsolete piece of technology popular in the 80s and 90s that had this feature. You may remember it; the VHS cassette. Granted, it was a side-effect of the antiquated way it stored video, and not a design feature per se, but that doesn't make it any less useful. When you inserted a VHS cassette you could be pretty confident that it would start playing at the point where you left off…

It wouldn't be difficult to look up the last played position of a movie file and restore it when the file is next played. A filename and file-size is probably adequate to identify a movie file, and the player would only need to keep track of a small number of recent files. On operating systems that support it, the current play time could be stored in an extended file attribute, making it independent of a specific application.

However it is implemented, I think this is one old-school feature that deserves a come-back!


Micro-optimizing Minilight

March 24th, 2009

Today I discovered a rather cool project via Reddit. MiniLight is a “minimal global illumination renderer” (it draws 3D scenes) with implementations in various languages.

Cornell Box

The Cornell Box, rendered with Minilight

The Python version is a lot slower than the compiled languages – which is to be expected, number crunching like this is not Python's forte. All the same, I had a go at optimizing it. Using similar techniques I wrote about in a previous blog post I reduced the run-time for the test scene from 61.4 seconds to 53.2 seconds. Hardly stellar, and it's not going to change the comparisons, but it was an interesting exercise.

It may be possible to optimize it further without resorting to a different Python implementation, but that is an exercise for another day. See the following link for my micro-optimized version:



Stop the world, I want to get off!

March 17th, 2009

This morning was not a typical morning. After today I rather think I prefer typical mornings.

I woke up a little earlier than usual – at about half past seven – and rolled over in bed, only to be struck with a unpleasant sensation of dizziness. The only time I have felt similar, is when I had gotten drunk on vodka as a teenager.

The room was spinning when I opened my eyes, giving me waves of nausea. I staggered out of bed, only to flop down on the floor because I was afraid of losing my balance. After a few minutes I managed to focus and get back on my feet, only to hug the floor again when the dizziness returned a couple of minutes later.

Any movement of my head felt like it was amplified a hundred fold, and if I looked up, even slightly, the dizziness was all the more intense. The only thing that helped was being on all fours with my head down.

Between bouts of crawling about in my living room I switched on the computer to get the number of NHS direct (a medical help-line). The nice young man and nurse that I spoke to managed to ascertain that I wasn't going to meet my maker any time soon (if it's God, boy would I feel foolish).

Long story short: it passed after an hour or so, leaving only a residual nausea, and I managed to get myself to the doctor who told me it was acute labyrinthitis – which I had self-diagnosed by reading Wikipedia. Naturally I nodded and expressed faux surprise – glad my job isn't slowly being replaced by a website. :-P

Fortunately, it is most likely a one-off, caused by a virus. A good thing – not even a cup of coffee could fix this morning!

That's one more ailment I can scratch of my list of diseases I have yet to experience!


The low-down on Django-Techblog

March 14th, 2009

I figured I would write-up some of the features of Django Techblog, the blogging application I wrote to power this site. It does most of what you would expect from a blogging app, but there are a few features that it does differently. The main difference is extended markup, but there are a couple of other features that worthy of note:

  • Multi-blog capable. I want to blog on a variety of subjects, but because some of the things I post about (namely the geeky stuff) are only of interest to a select few, I risk turning away visitors who aren't interested in those techy posts. Categories and tags are one solution to this, but I prefer to have a number of blogs under an umbrella blog, each with its own posts, templates and tags. In Techblog, there is also a concept of a channel which appears exactly like a blog from the front-end, but aggregates posts & tags from one or more blogs. In this site, the home-page at / is actually a channel consisting of /blog/tech/ and /blog/personal.
  • Microblogging. Techblog has support for Twitter and potentially other microblogging services could be added. You add your twitter account details, which Techblog uses to poll your tweets and automatically post them to a specified blog. It filters out replies because they are rarely of interest to anyone other than who the reply is intended for, and also parses hashtags to create equivalent tags in the blog system. A microblog post can have a unique template (just a Django template) so they can have a different look and feel to regular posts. You can check my tweets in /blog/microblog/.

Getting the Code

The code for Django-techblog is licensed under my politeware license, which means you can use it for any purpose you see fit, but I would appreciate a thank you! It shouldn't be too difficult to set-up if you have worked with Django, but I'd be happy to help if you experience any problems with it. See the Google Code page for the SVN url:


Nesting Instinct

March 12th, 2009

I figured I'd start a series of Python challenges in my blog. Whenever I've posted questions such as these in the past, the discussion that follows is always very entertaining!

A discussion arose today at work about the best way to flatten a tuple consisting of values and other tuples (which may be nested arbitrarily). So the tuple (1, (1, 2, (1, 2, 3), 3)) would become (1, 1, 2, 1, 2, 3, 3). Now there was actually code implemented which was functional, efficient and easy to read – but where is the fun in that?

I figured I could re-write it in a more terse manner, and here is what I came up with:

def flatten(tpl):
    return eval(repr(tpl).replace('(', '').replace(')', ''))

t= (1, (1, 2, (1, 2, 3), 3))
print flatten(t)

This flatten function would actually work in the context of our app, but I would never use it in production code. My challenge today, is to tell me why this code should never be used!


I am a Billionaire!

March 10th, 2009
$50 billion note

This is what $50 billion looks like.

My little sister has returned from her travels in darkest Africa and has brought back great treasures indeed. Behold, the $50,000,000,000 note! And I didn't even need to help a Nigerian widow transfer the money out of the country.

I know what you are thinking – it's great to be wealthy, but what about all the begging letters? Well, I guess I can stop sending them now.


Live your life by the Tao of Python

March 7th, 2009

As a Godless heathen, I have no scripture from which to guide me in my day-to-day life, and I must look for meaning elsewhere. I believe I have found that meaning in the most unlikely of places; the Python shell. If you enter import this in to the Python interpreter, it will reveal to you an ancient wisdom in the guise of a collection guidelines for the Python language.

Search for Posts
© 2008 Will McGugan.

A technoblog blog, design by Will McGugan