Monday, December 25, 2006

Splendid Box



Also: good pie.

[A:41758 B:3278 C:346 D:9187 E:64522 Total:119091]

Saturday, December 23, 2006

Draft 3

[reading: Tanya Huff, "Smoke and Mirrors"]

Finally got around to taking another pass over my scribblings on software engineering. It's been a fair while since I last looked at it—around eight months—which means I've now got enough distance to be able to spot (some of) my own typos.

I'm also finding that I rather like it as I re-read it, which is a slight surprise (almost no-one else that I've shown it to seems to have been able to wade through it, which augured badly). I've got a couple more small sections I'd like to add, but I think it's in fairly decent shape.

[A:40878 B:3278 C:346 D:9187 E:64522 Total:118211]

Thursday, December 14, 2006

Scanned Scan


I've seen ultrasound scans before, and I could never quite understand the enthusiasm with which they were presented. They always seemed like a grainy collection of vague blobs to me, and so I thought the enthusiasm was just early-onset baby obsession.

Now that I've seen the scan in action, it makes a lot more sense. Any individual still image is grainy and vague, but as the 'camera' moves around you build up a 3D image in your head which is much more impressive. It's like being in a really dark room with a single lightbulb swinging far overhead, so that the shadows gradually converge into shapes. (Actually, that makes me think of Doom 3, which probably isn't the best association).

Wednesday, December 13, 2006

Django Su

It's always a sign of good design when adding a new feature turns out to be easy.

In the Django authentication system, I wanted a way for an administrator to view the site as if they were a particular user; effectively an equivalent to su in UNIX-land.

The first easy step was to invent a URL to correspond to this action, which gets encoded in

  (r'^su/(?P<username>.*)/$', '', {'redirect_url': '/qlockdata/'}),   

That done, the second and final step is to write some view code.

  @user_passes_test(lambda u: u.is_staff)
  def su(request, username, redirect_url='/'):
      su_user = get_object_or_404(User, username=username)
      if su_user.is_active:
          request.session[SESSION_KEY] =
      return HttpResponseRedirect(redirect_url)

Seven lines of code and we're done (modulo a bunch of import statements).

Expanding what's going on here:

    (r'^su/(?P<username>.*)/$', '', {'redirect_url': '/qlockdata/'}), 
  • When an HTTP request arrives at the framework, Django goes through its list of URLs until it finds a match. In this case, going to http://mysite/accounts/su/fred/ ends hitting the line above; the /(?P<username>.*)/ part of the regexp pulls out "fred" and this gets passed as a parameter named username into the function su in qlockweb/accounts/ This function also gets passed a parameter called redirect_url with value '/qlockdata/'.
  • @user_passes_test(lambda u: u.is_staff)
  • Actually, we need to rewind one step before we get into the su function. The line before the function definition is a Python decorator: some extra code wrapping the function that gets executed just before the function itself is executed. This decorator needs some expansion of its own:
      @user_passes_test(lambda u: u.is_staff)
    • The @ sign is the syntactic sugar that indicates that this line is a decorator for the function that comes immediately afterwards.
    • @user_passes_test(lambda u: u.is_staff)
    • This is the decorator function (from contrib/auth/; its first argument test_func is a function that does the test. This test function is given a single parameter: the current User. If the test function returns true, the wrapped view code is called; if not, then the user gets redirected to a login page.
    • @user_passes_test(lambda u: u.is_staff)
    • More syntactic sugar. We want a function is_this_a_staff_user(u) that checks whether its argument u is an administrator. However, as this is the only place that the function is used, we don't bother to give it a name—we just use a lambda expression to give the definition right here and now.
    • @user_passes_test(lambda u: u.is_staff)
    • Finally, the body of the lambda expression just uses the method of the User class that indicates whether the user is an administrator or not.
  • def su(request, username, redirect_url='/'):
  • So now we're in the su function itself, and if we've got this far we're guaranteed that the person viewing the page is logged in as an is_staff user. The function has the username and redirect_url parameters mentioned earlier; it also has a request parameter that holds all of the information about the original web request (in a HttpRequest object).
  •   su_user = get_object_or_404(User, username=username)
  • The next line of code gets a User object for the username that was specified—fred in other words. If there isn't a user called fred, then a Http404 exception gets raised, which will percolate up the stack and display a (surprise, surprise) 404 page.
  •   if su_user.is_active:
  • This particular version of our code only allows impersonation of active users, helpfully provided by the is_active field in the standard User model.
  •     request.session[SESSION_KEY] =
  • The next line of code is the one that actually does the work. The requesting user's session is modified so that its user ID is the impersonated user's.
  •   return HttpResponseRedirect(redirect_url)
  • The final line of code redirects the web browser off to the redirect_url page.

(Statutory disclaimer: I am not a security expert, nor do I play one on TV. Adding this to a production system is probably not a good idea.)

Another Django snippet: I finally discovered that the follow argument to the standard Manipulators allows you to list fields in the model that the form should leave untouched. Very helpful: the end result is more compact and less brittle than the code I'd put together to manually override all of the hidden fields.

[A:37385 B:3278 C:346 D:9187 E:62544 Total:112740]

Saturday, December 02, 2006

Mind Hack #39

[reading: Jón Árnason, Alan Boucher (translator), "Icelandic Folk Tales"]

One of the MindHacks that doesn't include an easy demonstration is Hack 39, where you're less likely to notice a trigger event if it occurs soon (say, <0.5s) after another trigger event.

(Now that I've got into the content rather than being distracted by the typesetting, the book is turning out to be rather good.)

My first attempt to test this out is below, but I have to say that the effect didn't seem all that strong to me—so maybe there's a bug or I've implemented it wrong. Or maybe I'm just too impatient to run it for long enough to get statistically significant data.

After hitting "Go", this applet will display letters for a tenth of a second each. You should hit a key whenever the letter displayed is either "X" or is displayed in white. To stop the applet, hit "Stop" or press the Escape key.

After running the applet, the bar graph shows the time between triggers (on the X axis) against how many triggers there were with that delay; the white is the total number shown, the black is the subset of them that were missed. Hitting "Go" again accumulates more data.

(Download source code)

Technical Details: letters are picked uniformly (so there's a 1/26 chance of a letter X trigger) and white is used for the colour 1/20 of the time. A trigger is considered hit if there's a keypress within 1 second after the trigger, but each keypress only counts once (so "trigger, trigger, keypress, letters…" would count as one hit then one missed trigger, with a delay of 1).

[A:37385 B:3278 C:346 D:9187 E:46445 Total:96641]

Thursday, November 30, 2006


[reading: William Faulkner, "As I Lay Dying"; recently Neil Strauss & Bernard Chang, "How To Make Money Like a Porn Star"]

Now that I've got Django installed and running, I've been setting up my first web application with it.

I spent a bunch of time yesterday trying to figure out how to get extra parameters passed through a generic view; in the end I had to UTSL to get a method that worked.

So of course today I find a nice page that concisely and coherently explains it, rather more quickly than the couple of hours it took me to figure out.

Perhaps I can suggest *knolp* (the reverse of *plonk*) as the sound of an RSS feed hitting my aggregator. (It looks like I'm not the first person to think of this.)

[A:37385 B:3278 C:346 D:9187 E:46320 Total:96516]

Saturday, November 25, 2006


[reading: Derek Young, "Rock'n'Roll Dancing"]

Here's a question: is there a Unicode character for an N with an umlaut?

(Triggered by eating a splendid dessert of brownies and Häagen-Dazs ice cream, which made me think of that most famous of fake umlauts, the one in the name of "Spinal Tap").

Oh, and compounds like U+006E U+0208 (i.e. 0x6e 0xcc 0x88 in UTF-8) don't count.

[A:37385 B:3278 C:346 D:9187 E:39180 Total:89376]

Tuesday, November 21, 2006

Editing Hacks

[reading: Tom Stafford & Matt Webb, "Mind Hacks"]

Started reading "Mind Hacks", which looked interesting in the bookshop but the formatting is already starting to annoy me. In that respect, it's the worst book-that's-just-a-printout-of-a-cool-website ever, and that's up against some pretty stiff competition.

  • A large fraction of the hacks refer the reader off to movie files or Flash animations on the web. Not very helpful for a physical book that you might want to read on a train.
  • "Color: The second color is used to indicate a cross-reference within the text". Except that there is no second color—the relevant parts just come out in a hard-to-read light gray.
  • The halftoning for photographs and some of the diagrams is poor—it looks like the output of an 1980's laserprinter.
  • I don't know what system they used to produce the book, but it's generated some real oddities in linebreaking (mostly around URLs). Favourite so far: a line break after the decimal point in "3.3" (page 144).

Still, the content might be OK once I get into it, and at least they include lots of references to the original literature.

[25-Nov-06] Edited to clarify that I'm complaining about the formatting rather than the content. Feeling slightly guilty given that one of the authors came over and commented. You'd think I'd have learnt my lesson about who finds what on tha intarweb.

[A:37385 B:3278 C:346 D:9187 E:34361 Total:84557]

Monday, November 20, 2006


[reading: Martin Amis, "The Rachel Papers"]

Grr. The spammers seem to have found me. I've been using my current email address for three years now, and I've not had any spam at all until the last week or two. (There's occasional spam to webmaster@ or info@, but they're easy to ignore). I guess I must have gotten complacent and signed up to something dubious with my real address. Drat.

[A:37385 B:3278 C:346 D:9187 E:33570 Total:83766]

Thursday, November 09, 2006

One Year In

[reading: Seamus Heaney, "North"]

Just noticed: it's a year since the original idea for the company.

Tuesday, November 07, 2006

Strike One

[reading: Lois McMaster Bujold, "The Sharing Knife: Beguilement"]

One down, two to go. Still, at least it was a swift response; strike while the iron is hot for the next scary email….

Monday, November 06, 2006

Post Hoc

[reading: Seamus Heaney, "Beowulf"]

I know it's entirely back-to-front, but I keep encountering things in Beowulf that feel like they were stolen from Tolkien: there's a minor character called Eomer, and I've just read the bit where  a drowsing dragon  is raised to wrath*  because a thief has  snuck in and stolen  a cup from his hoard. I had a similar experience in Iceland—I kept on spotting businesses apparently named after dwarves: "Balin Shipping" and "Thorin Warehouse" (or þorin) and so on.

In other news, I finally succumbed to nagging and sent off a scary email….

* Anglo-saxon alliteration is irresistibly infectious.

Wednesday, November 01, 2006


[reading: Scott McCloud, "Making Comics"]


Over the last few weeks we've had our flat roof re-felted. (This involved an unexpected amount of hassle, as we seemed to end up in the middle of a dispute between management and workers. The dispute was nominally about health & safety, but I suspect it was really about something else—probably money.)

The trigger for getting the work done was how much it had been raining…indoors, particularly around the skylight. A quick examination revealed the primary problem: there were large, ragged, holes torn in the flashing around the skylight. The flashing was silvery, so the most likely explanation for the holes was that they had been pecked out by birds.

So when I heard a loud tapping sound this morning and looked up to see two crows attacking the newly-repaired skylight, it was time to do something about it.


* And yes, I know that "scarecat" isn't a logical variant of "scarecrow" in this context.

Tuesday, October 31, 2006


[reading: Tom DeMarco & Timothy Lister "Peopleware: Productive Projects and Teams"]

On the plus side, this is an absolutely fascinating advert:

On the minus side, when I emailed* Dove to see if there was a higher-resolution, downloadable copy anywhere (for a teacher friend who wanted to use it as the basis for a school assembly), I got a swift response of:

Due to licensing reasons we are unable to send the Dove Evolution Film to other organizations. We invite you to log on to to play the film live.

I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a response.

*When I say "email", obviously I mean "fill out a ridiculous web form that requires me to fill in my postal address". And when I say "my postal address", obviously I mean a random invented address because a) I don't want junk mail for the rest of my days and b) the address form doesn't allow non-US addresses.

Sunday, October 29, 2006

Top Tip

[reading: Alistair Reynolds, "Pushing Ice"; recently Neal Asher, "The Voyage of the Sable Keech", Steven Brust, "Dzur", John M. Ford, "The Dragon Waiting", Scott McCloud, "Understanding Comics"]

Today is my third attempt to fill the cracks in the grouting around the bathroom tiles. I have high hopes that this iteration might actually work, for I have encountered a Top Tip: fill the bath with water while the grout is drying, so that the gaps are stretched to their biggest during the drying period.

I did wonder why the cracks seemed to appear and disappear at random; I now realize that it depended on whether I was checking on them when I was sitting in the bath, or when I was standing by the bath. Doh.

[A:37385 B:3278 C:346 D:9187 E:26863 Total:77059]

Monday, October 09, 2006

Mugging Shock

Bit of excitement this evening; I was reading a bit before bed (about instruction pipelining on the PowerPC 970FX, as it happens) when I heard someone shouting for help outside. This was different from the normal young-drunk-giggly-female shouting we sometimes hear (being close to a pub)—this was an older male voice that sounded in genuine trouble.

So I trundled out to discover that it was indeed someone with trouble—a chap who'd just been mugged, around the corner. After I'd retrieved a torch and an ice pack for him from the house, I ended up tagging along with him and a policeman as we wandered down the nearby alleyway looking for the muggers and to see if they'd abandoned his bag (they had).

From his description of events: he was walking down the alleyway towards three youths coming the other way, and he had advance warning that something was up because they didn't move apart to let him pass. They hit him a couple of times, then started demanding his stuff. He handed over his bag (knowing it had nothing of value in it), and his watch when they demanded it, and was in the process of handing over his mobile phone when they started after his wallet. This triggered him to start resisting, and he grabbed back his phone and ended up keeping his wallet—but ended up being hit more (net result: a nasty looking swelling above his right eye, but fortunately no loosened teeth) before they scarpered.

It was interesting to observe someone who presumably had a touch of shock: he was fairly calm and coherent, but he kept talking continuously and repeated almost everything he said several times. He insisted he didn't need anyone to look at his eye, but I wasn't so sure myself (hence the icepack); I guess I was probably overly worried—I got one of the policemen to take a look at it (assuming he's probably got vastly more experience with black eyes than I do) and he didn't seem too concerned.

So overall he didn't come off too badly: he lost his watch, but kept his wallet, phone, briefcase and all of his teeth. Still, a bit disturbing to have a mugging 100 yards from my house….

[A:37385 B:3278 C:346 D:9187 E:15988 Total:66184]

Friday, October 06, 2006


[reading: Amit Singh, "Mac OS X Internals"]

So I finally gave in and scratched my itch about the 5¼" floppy, by sending it away to a data recovery place. It was a little bit expensive (although still considerably cheaper than calling out a plumber) and time-consuming (two weeks, five phone calls and an email later), but worth it just for the satisfaction of never having to think about it ever again.

Amazingly, my very first TeX files (from 1989) still produce exactly the same page layouts in the TeX system on my 2005 laptop.

Learning TeX was actually driven by embarrassment. When I originally wrote the essay, it was in WordStar. Dealing with accented characters was a bit annoying in WordStar, so I decided to deal with it in batch mode. While I was writing the essay, I used 'Godel' instead of 'Gödel' all the way through. Then, just before submitting it, I ran a search-and-replace to change all instances of 'Godel' to 'Godël'.


So when someone eventually pointed it out to me, I persuaded the college to let me have the submitted hardcopy of the essay back with the excuse that I was going to replace it with a better-typeset version—and hence my introduction to TeX.

[A:37385 B:3278 C:346 D:9187 E:13011 Total:63207]

Saturday, September 30, 2006

In Extremis

[reading: Lenny Smith, "Chaos: a Very Short Introduction"; recently Terry Pratchett, "Wintersmith"]

Last Globe trip for the season, for another modern play. It's not as brutal as Titus—a piffling single mutilation and no murders (although there is some, er, hot nun-on-nun action)—but it does have some rather good theological sparring.

[A:37385 B:3278 C:346 D:9187 E:12683 Total:62879]

Sunday, September 24, 2006

The Hot Seat

I'd not noticed before, but it seems that the parking meters around Haringey are at least partially solar powered. A neat idea, and I'm not the only one who thinks so:


[A:37385 B:3278 C:346 D:9187 E:10615 Total:60811]

Saturday, September 23, 2006


Kewl. Just had my tax assessment back, and even with my earlier monster tax refund, they still owe me more money.

(Not that this was really a surprise, as I'd already figured out what they would owe me. But on previous history, it was slightly a surprise that they got the numbers right—more often that not, I have to ring them up to get them to correct it).

[Edit: Also, I guess this explains why my bank balance was mysteriously much higher than I expected last week…]

[A:37385 B:3278 C:346 D:9187 E:9502 Total:59698]

Tuesday, September 19, 2006

Thursday, September 07, 2006

Reg Ringtone

Some people are of the opinion that Reg, the the cat who doesn't live here, could generate a good ringtone. Even though he's incredibly loud, he seemed to view microphones with suspicion (when he's not trying to eat them) and so the samples are quieter than they should be.

Believe it or not, this isn't the sound of a cat in any sort of pain or distress—except for the distress of having to wait thirty seconds for his sixth meal of the day (provided by four different neighbours). It's a sound that was once described as "someone torturing a granny to death".

Wednesday, September 06, 2006

If you build it, they will come

[reading: Tom Reynolds, "Blood, Sweat and Tea"]

W00t, we have customers!

Well, except for the paying money bit, obviously. We haven't actually set up a way for people to pay us money yet (which might be a bit of an oversight).

But we shifted our website around last week so that random members of the public could actually get to the beta download page and get an evaluation copy of the product, and today a couple of people found and followed the relevant links.

Sunday, August 27, 2006

Reykjavík to London

[reading: Alfred Bester, "The Stars My Destination"]

Just time in the morning to go back to Hallgrímskirkja

View_West_from_Hallgrimskirkja_@_Reykjavik,_Iceland.jpg Hallgrimskirkja_@_Reykjavik,_Iceland_7.jpg View_East_from_Hallgrimskirkja_@_Reykjavik,_Iceland.jpg

Then off to the airport and back to London.

Saturday, August 26, 2006


First activity for the day was a couple of hours of horse riding on Icelandic horses. They're fairly small, but still move at an impressive pace (too much so for one poor chap, who got thrown off when his horse unexpectedly cantered—he ended on the ground with one foot still attached to the stirrup) and have an extra gear compared to normal European horses.


After that, back to Reykyavík for some culture: the Culture House, the Einar Jónsson sculpture garden and the ASÍ art gallery (which demonstrated that weird-ass conceptual art isn't just confined to the UK). Sadly, it seems that the Phallological Museum is no longer in Reykyavík, so we had to skip that particular bit of culture. (We also tried to get into Hallgrímskirkja, but it was shut for a couple of weddings.)

Friday, August 25, 2006

Hella to Reykjavík

[reading: Samuel R. Delany, "Babel-17"]

A waterfall day, starting with Seljalandfoss and a smaller waterfall nearby.

Smaller_waterfall_through_rocks_@_Seljalandfoss,_Iceland.jpg Waterfall_@_Seljalandfoss,_Iceland_3.jpg

Then on to Skógafoss.


The town of Skógar also has a folk museum, which seems to be international standard terminology for "eclectic collection of junk" (although still interesting for all that).


Icelanders seem very fond of sculpture; most towns seem to have a piece or two, even very small towns. (Every town also seems to have an interestingly-architected small church—I've seen many innovative designs).


On the way back, there's a stop for ice cream in Hveragerði. The trip notes have this to say about Hveragerði:

Minor earthquakes are common and quite harmless. In the middle of the town the ground is too hot for buildings and a fence has been built to keep pedestrians safe! We can either stroll around this green oasis or use the opportunity to soak ourselves in the wonderful geothermal baths of Hveragerdi.

The reality seems to be rather more along the lines of the Rough Guide description:

There's not a huge amount to see in Hveragerði itself, though some fine hiking hereabouts might encourage a stopover.

Finally, back to Reykjavík for a puffin dinner at Lækjarbrekka.

Thursday, August 24, 2006

Reykholt to Hella

First, a quick stop at Barnafoss.

River,_falls_@_Barnafoss,_Iceland_5.jpg River,_falls_@_Barnafoss,_Iceland_7.jpg River,_falls_@_Barnafoss,_Iceland_12.jpg

Then on to the mountain road, across the barren lava fields near Langjökull.


Reaching Þingvellir, ancient home of the Alþing.

Gorge_@_Thingvellir,_Iceland_5.jpg Stream_@_Thingvellir,_Iceland_2.jpg Rock,_stream_@_Thingvellir,_Iceland.jpg Rocks,_stream_@_Thingvellir,_Iceland_3.jpg

On to more hot springs by the lake at Laugarvatn, this time feeding a steam room.

Whale_bones_@_Laugarvatn,_Iceland.jpg Lake_@_Laugarvatn,_Iceland.jpg

Another waterfall at Gullfoss.

Waterfall_@_Gullfoss,_Iceland_3.jpg Waterfall_@_Gullfoss,_Iceland_9.jpg

Last stop was at Geysir, to watch the reliable Strokkur do its thing. I mostly take landscape pictures, so I think this is the first time I've ever used the motordrive on this camera.

Strokkur_D_@_Geysir,_Iceland_3.jpg Blesi_@_Geysir,_Iceland_3.jpg

Ended the day at a "hotel" in Hella, which had the smallest rooms ever encountered. A twin room had two beds…end to end, with about as much space again next to them, in between walls made of plywood.

Wednesday, August 23, 2006

Langaholt to Reykholt

This morning's excursion was a boat trip to see the islands and birds off Stykkishólmur.

Birds_on_island_@_boat_off_Stykkisholmur,_Iceland_3.jpg Island,_markers_@_boat_off_Stykkisholmur,_Iceland_3.jpg

Next was the reconstructed Viking house at Eiríksstaðir, complete with frolicking kittens.

Hut_@_Eiriksstadir,_Iceland.jpg Kittens_playing_@_Eiriksstadir,_Iceland_4.jpg

The last stop on our way to Reykholt was the hot springs at Deildartunguhver, the largest in Europe.


Reykholt is the home town of Snorri Sturluson, who was murdered in his cellar in 1241. Apparently he tried "the old Viking trick of screaming and begging for mercy", but to no avail.

Tuesday, August 22, 2006


Exploring the Snæfellnes peninsula today, although Snæfellsjökur itself stayed stubbornly hidden by clouds all day. The landscape feels like a younger version of Scotland (but with the addition of lava fields); the weather certainly feels similar to Scottish weather.

We started with a quick visit to a narrow gorge at Rauðfeldargia.


Next was a walk along the sea cliffs from Arnastapi to Hellnar, with various blow-holes along the way.

Harbour,_house_@_Arnastapi,_Iceland.jpg Bay,_sea_@_Arnastapi,_Iceland_4.jpg Rocks,_bay,_sea_@_Arnastapi,_Iceland.jpg

A little further around the coast are the Þúfubjarg cliffs (where legend has it that a poet won a rhyming competition with the devil).


On to Djúpalónssandur (with the remains of a wrecked ship, originally from Grimsby, strewn around the beach) and from there to the ruins of an old village at Dritvík (in the driving rain).

Beach,_shipwreck_@_Djupalonssandur,_Iceland.jpg Beach,_stones_@_Djupalonssandur,_Iceland_2.jpg

Finally, round the coast road to Ólafsvík, and then over the mountain road to a soak in an hot swimming pool at Lýsuhóll.

Reading the guidebook, I came across what has to be the earliest recorded instance of marketing:

The country which is called Greenland was discovered and settled from Iceland. Eirík the Red was the name of a man from Breiðafjörður who went out there and took possession of land in the place which has since been called Eiríksfjörður. He named the country Greenland and said it would make people want to go there if the country had a good name.

  (From Book of the Icelanders by Ari the Learned)

Monday, August 21, 2006

Reykjavík to Langaholt

Driving out from Reykjavík, we followed the road round Hvalfjörður to our first stop, a walk up to the waterfall at Glymur.

Overhang_for_cave_@_Glymur,_Iceland.jpg Waterfall_@_Glymur,_Iceland_4.jpg

Next stop was the Eldborg volcano crater. A quick Icelandic lesson on the way, and in proper English fashion the first word anyone asks for a translation of is "sorry".

Icelandic_horses_@_Eldborg,_Iceland_4.jpg Volcano_crater_@_Eldborg,_Iceland.jpg Volcano_crater_@_Eldborg,_Iceland_3.jpg

Finally, before we reached our (excellent) guesthouse at Langaholt, there was another stop to look at some basalt columns at Gerðuberg.


Iceland must be the largest per-capita consumer of JCBs anywhere in the world—there seem to be diggers and lifters and trucks and dozers everywhere.