“ ♺ @nixiepixel: Pixel Art De-Pixelated with Easy Algorithm : http://bit.ly/kr3LNX (The world of retro gaming just got a lot prettier. ) #tech ”


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!


Django Tech Blog

February 16th, 2009

The new Django blog system I have been working on is virtually finished, I'm just testing it at the moment. Now I know that by writing my own blog system I will miss out on all the capabilities of a full featured and mature system, such as Wordpress; but my new system -- which I call Django Techblog -- has a few features that Wordpress doesn't, but more importantly, it works just the way I want it to.

One of those new features is the ability to insert syntax highlighted code in to comments, which is very useful for a techy blog! I've created a post on the beta site, and I'd like to invite you to pop over and test the commenting system. I'll delete the comments when I'm satisfied it is working nicely and I can replace www.willmcgugan.com. So feel free to play about with it...


Any comments about the design or general functionality of the blog would also be welcome!


A better Caching system for Django

February 15th, 2009

Django has pretty good support for caching, which is one of the easiest ways of speeding up a web application. The default is to cache for ten minutes, which means that if you get multiple requests for a page within a ten minute window then Django can serve up a stored copy of the page without hitting the database or rendering the HTML. The caching period can be set per-page and fragments of pages can be cached rather than the whole, but the system rests on the fact that it doesn't matter if the content doesn't change for a period of time.

Trouble is, not many web applications work that way. Consider a humble blog post with a piece of content and a list of comments. Granted, the post content isn't going to change very often and will probably never change again once the author has corrected all the typos, but a list of comments may change at any point through the life-time of the blog. If the page were cached, comments would not be visible on the page for a short period of time, which doesn't give that instant gratification that web users expect these days.

It would be nice if a web app could benefit from caching and still serve a fresh page when content changes. Alas, Django's default time-based caching is never going to achieve this. What is needed is a way of invalidating an item in the cache when there are changes that alter the content; using the blog example, this would be when the post content changes or a new comment is submitted. Django does give you the tools to do this -- using the low level cache API, you can construct a cache key (a simple string) that changes according to the page content, then store and retrieve your content manually. For example you might create a cache key with the modification date of the post, and the ID of the most recent comment. Then the page need only be rendered when the cache key isn't found in the cache. The downside of this approach is that it can take a little work to calculate the key (you may still have to hit the database to generate the cache key). This is not quite as nice as time-based caching, which will do negligible work for cached pages.

A better approach, which has the benefit of always serving a fresh page, and still requires negligible work for cached pages is to construct the cache key based on the request, then invalidate (i.e. delete) the cache key when the content changes. Again, this can be done with Django, although it has no explicit support for it. Such a system requires more work because the web app must track any event that could potentially require a fresh page to be generated, but has the major advantage that up-to-date pages are virtually always going to be available in the cache.

I've written ad-hoc page-event cache systems a couple of times and they are a major headache to maintain. Even on simple pages there can be multiple events that may invalidate a cached page. What would be nice, is some formal way of associating a model instance with a the URL(s) that depend on it, so that when the instance is saved, the associated pages will be invalidated and re-generated at the next request.

I've not yet settled on the best way of implementing this, but it will probably be a decorator that builds up a mapping of object type plus primary key to its dependant URLs, and a mixin for models that hooks in to the save method.

I'm open to suggestions regarding the most elegant implementation, and any other potential solutions!


Free Game

November 8th, 2007

In 2005 I released a fun little puzzle game called Ping Ball. It took me 9 months of spare time to write, and I did all the coding down to the hand tuned assembler code for the blitters, and even render the sprites myself with Povray. It was the first project where I used the sub-pixel sprite technique, that I recently replicated in Python. The resolution is only 640x480, but you would swear it was a lot higher. I thought it was a great game, I enjoyed working on it, and I loved playing it. So I assumed I would do well selling it. I was wrong! It sold very few copies, apparently it was too hard for the casual games market, and didn't appeal to more dedicated gamers. *sigh* Here are a couple of screenshots...

PingBall Screenshot shot41.jpg

As someone who likes to create things, there is nothing worse than creating something that few people will ever see. So I have decided to give away the full version for free, as an experiment.

Download Ping Ball (full version) Update: You will need the following license key to unlock it: PING-43a3-2a4a-cb8a-1c23

I think it will appeal to programmers. There is a slight arcade feel, but basically it is a logic game where you have to think on your feet. The basic premise of the game is to bounce 'ping balls' around the screen by dropping mirrors in front of them and collect all the crystals.

I'm toying with the idea of making it Open Source, but I really don't have the time to maintain it or port it to other platforms (currently it's Windows only). So I would only release the code if there was a demand for it.

I hope somebody enjoys playing it as much as I do!


Raising little monsters

May 16th, 2007
XenomorphA few years ago I had a tank of sea monkeys. If you are not familiar with sea monkeys - they are a kind of brine shrimp that has been marketed as a kids toy. They come as a little sachet of eggs with a plastic tank. You add water and they hatch within hours. It's the most marvelous, stress-busting executive toy you can buy. I loved my sea monkeys so much, it inspired me to write an artificial life demo (for PC).

I was thinking of buying some more of these beasties, but I ended up purchasing triops, which are a similar type of instant life crustacean. They are a little bigger than sea monkeys, and carnivorous (sea monkeys just filter nutrients from the water)! Strangely though, they are a little harder to raise. The sea monkeys were almost self-sufficient; eventualy algae grew in the tank and you didn't have to feed them any more. The triops are more fussy, they need water at a specific temperature, regular feeding and water changing.


The gravel and nutrient bag have been soaking over-night. Today I shall add the eggs to the water, and by tomorrow I should have a dozen or so hatchlings!


I want

May 15th, 2007

I use my laptop for instant messaging and picking up my email while I'm working. It's not quite as good as having dual monitors but it means I can easily work and chat / refer to emails without having to shuffle windows about. Occasionally I need to transfer something from the laptop to my main machine - which can be a pain because I have to minimize windows, find the file, drag it on to a shortcut then find it on the other desktop. What I want is to be able to access the clipboard on the laptop from my main work PC, so that all I would have to do to copy a file from my laptop would be to copy it to the clipboard then press, say Shift+Ctrl+V on the other machine to suck it over the network. And I want it to work with text, urls and anything else that can be copied to the clipboard. And I want it to be free. :-)

And I want a pony!


The smell of C

May 11th, 2007

A recent post on reddit.com sparked a debate on the following snippet of C code.

int main() { int i = 5; i = ++i + ++i; printf ("%d", i); }

The denizens of reddit have been musing over the the output of the code; is it 13 or 14? It can be either depending on the compiler used - or something else entirely - as the result is undefined, which another denizen noted. Sometimes I wonder if the C language was designed purely to provide challenging job interview questions.

Even though I was a C/C++ programmer for a lot longer than I have been a Python programmer, the entire concept of a valid language construct being undefined is offensive to me. Seriously. It's like month old milk; makes me screw my face up and turn away in disgust. In contrast, Python smells like a mixture of freshly cut grass and new car smell.

As enamored with Python as I am, it still sits on top of C (at least C-Python does) and inherits a little of its unpredictable nature. I believe there are some inconsistencies across the various Python platforms, but I can't think of them right now. Most of them were floating point unit related IIRC, because CPython has little choice but to defer to the floating point implementation of the platform. I wonder if there is a web page somewhere documenting runtime differences between platforms and Python implementations. A small and concise web page I hope!

On the subject of smells. What do other languages smell like? I reckon assembler smells kind of like ammonia.


Spam spam spam

May 10th, 2007

I hate it so much. I've had willmcgugan.com for many years, and in the early days I was complacent about posting my email address in newsgroups / BBs etc. Consequently I get an impressive amount of spam. I use SpamBayes, which worked great in the beginning, but now training it seems almost as much effort as deleting the spam manually.

Since I can't nuke the spammers from orbit, I've restricted my email address to . Unfortunately this means that you will no longer be able to email me at studmuffin@willmcgugan.com or youreallyrockmyworldiwanttohaveyourbabies@willmcgugan.com (sorry). I have also enabled SPF on my domain. I'm not exactly clear on what that is, but easydns.com claim it will cut down on spam, so I am giving it a go.

If you are reading this within 24 hours of the post, please send me a brief test email. If you don't get a brief test reply by tomorrow, then please post a comment to let me know.

And if you have any other tips for reducing spam - let me know!

© 2008 Will McGugan.

A technoblog blog, design by Will McGugan