The Wayback Machine - https://web.archive.org/all/20061205033023/http://simon.incutio.com:80/

Freeing the postcode

UK postcodes have some interesting characteristics: a full six character post code identifies an average of around 14 house holds, and postcodes are mainly hierarchical - W1W will always be contained within W1 for example. They're useful for a huge range of interesting things.

The problem is that the postcode database (of nearly 1.8 million postcodes) is owned by the Royal Mail and licensed at a not inconsiderable fee of between £150 and £9,000 per year.

Free the postcode was set up a while ago to try to remedy this situation, by asking people to enter their postcode along with the latitude/longitude coordinates collected from a GPS. Having people enter coordinates from online mapping services is no good as EU database law may see that as a derivative work. It's had some success, but the GPS requirement has seriously stunted its growth.

Then a few weeks ago, npemap.org.uk launched. It's an interface for browsing scans of out-of-copyright maps from the 1950s (credits at the bottom of the FAQ). The site asks people to enter post codes based on that old mapping data, which can then be placed in the public domain.

If you haven't already done so, you should go and add any postcodes that you know about now. It takes no time at all, and is especially important if you live in one of the 230 districts for which no data has yet been collected.

You can grab the data they've already collected from here. There's a really cool interactive visualisation of their data here, based on previous work by Chris Lightfoot using the commercially licensed postcode database.

WriteRoom

I had a look at WriteRoom a few months ago and wasn't impressed, but Leonard just convinced me to give it another look and I'm completely sold. It's a free text editor for OS X with two killer features:

  1. A full screen mode (toggle with ESC) that hides the rest of your screen, letting you type in glorious green-on-black courier with absolutely no distractions.

  2. Autosave. You never have to save a document, even when you quit WriteRoom. It maintains a list of your WriteRooms in the file menu, keying each on the first few words. If you want to move text to an actual file you need to either export it or use copy and paste.

I've lost count of the number of times I've lost some notes to a crash having scrawled them in TextMate or SubEthaEdit without saving to a file. Auto-save / auto-recovery should be built in to every application.

Tamarin

On Tuesday, the Mozilla Foundation and Adobe announced the Tamarin project, an open-source ECMAScript virtual machine based on the ActionScript engine used by Flash Player 9.

Frank Hecker's overview of what this means is useful, but the Tamarin source code itself provides this interesting piece of historical insight:

AVM+ is the ActionScript Virtual Machine

AVM+ offers an order of magnitude performance increase over the "Classic AVM" in Flash Player 7. Our performance target is 10X.

AVM+ implements ActionScript 3.0, the new version of the ActionScript language that is compliant with the ECMAScript Edition 4 standard.

AVM+ is also built for modularity. It will be part of the Flash Player, but is a self-contained module which can be incorporated into other programs with ease. It may also be submitted to the ECMA standards organization as a reference implementation of ECMAScript Edition 4.

Adobe's reputation for solid engineering shines through here - it seems that what is now Tamarin was designed for integration with other applications from the very start.

The most important thing we can expect from this is a serious improvement in JavaScript performance in the Mozilla family of products, thanks to Tamarin's JIT compiler that can convert ECMAScript bytecode to machine code at runtime. JavaScript/Ajax applications will run faster, and the Mozilla applications themselves will perform better as much of their UI is written in JavaScript and XUL.

This performance boost will benefit other applications as well. Tamarin is being integrated with SpiderMonkey, which is used in a variety of applications such as the Yahoo! Widget Engine.

Reading through Brendan Eich's technical overview of Mozilla 2, it looks like the Mozilla team also plan on taking advantage of this performance boost to move code from C++ to JavaScript 2 in many places, simplifying their code base and reducing the likelihood of security flaws in the code.

Even in these buzzword filled days of Ajax and Web 2.0, JavaScript is still seen as a poor cousin to so-called "real" programming languages. With a high performance open-source VM like Tamarin available, maybe more developers will start to re-examine JavaScript's role outside the browser.

Fun with ctypes

This probably only works on Intel-based OS X machines:

>>> import ctypes
>>> print ctypes.c_char_p(
    -16 * 4096 + 0x1600
).value
Your karma check for today:
There once was was a user that whined
his existing OS was so blind,
he'd do better to pirate
an OS that ran great
but found his hardware declined.
Please don't steal Mac OS!
Really, that's way uncool.
   (C) Apple Computer, Inc.U??VWS?5P

Adapted from dsmos.c in Understanding Apple's Binary Protection in Mac OS X by Amit Singh.

Graphing requests with Tamper Data

I spent the weekend in Boston, speaking at GBC/ACM's Deep Ajax seminar with Alex Russell and Adrian Holovaty. I'll be posting some notes on this later, but I wanted to share a really neat Firefox extension that Alex showed me: Tamper Data.

Tamper Data is an extension for intercepting HTTP requests and modifying them. I have very little interest in this functionality myself, but hidden deep within the extension is the ability to do this:

Screenshot of Tamper Data graph of www.yahoo.com

That's a graph showing what happens when you load up www.yahoo.com. It shows every component of the page - JavaScript, CSS, images - and when each component started and finished loading. You can use it to get an idea for how long it took between the HTML starting to load and the browser beginning to pull in the CSS, then the images, and so on. It's a superb visualization of what happens when a page is loaded.

Unfortunately, if you install and run the extension (Tools -> Tamper Data) you'll see this instead:

Screenshot of Tamper Data user interface

To get the graph, you have to right click in the main data grid and select "Graph All" from the context menu. Be sure to hit "clear" before loading a page that you want to graph or you'll end up seeing data from other pages too (you should shut down GMail or similar to prevent their polling requests from polluting the graph).

It's a great tool but it's pretty well hidden. If you're looking for a side project, implementing the same functionality in a smaller extension (maybe as an extra tab in the Page Info screen) would be a significant service to the web development community.

Keep your JSON valid

I'm a big fan of JSON, and it's great to see it turning up as an output option for so many Web APIs. Unfortunately, many of these APIs are getting the details slightly wrong and in doing so are producing invalid JSON.

JSON isn't just the object-literal syntax of JavaScript; it's a very tightly defined subset of that syntax. The site has a spec (illustrated with pretty state machine diagrams) and there's an RFC as well.

By far the most common error I've encountered relates to object keys. In JSON (unlike in JavaScript) these MUST be double-quoted strings. In fact, ALL strings in JSON must be enclosed in double quotes (JavaScript also allows single quotes; JSON does not).

Valid:

{ "name": "Simon" }

Invalid:

{ name: "Simon" }
{ 'name': "Simon" }
{ "name": 'Simon' }

It's worth reviewing the other key differences between JSON and JavaScript. Remember, all valid JSON is valid JavaScript but the opposite is not true; JSON is a subset.

This stuff matters. Python's excellent simplejson module is a strict parser; it refuses to consume invalid JSON. If you're building a JSON API it's worth taking the time to ensure you are valid - I suggest installing Python and simplejson and trying the following:

$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) 
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
>>> import urllib, simplejson
>>> url = "http://your-api.org/your-api/json"
>>> simplejson.load(urllib.urlopen(url))

Try it against a few JSON supporting sites. You might be surprised at the amount of invalid JSON out there.

As with outputting XML, the best way to avoid these problems is to use a pre-existing JSON generation library rather than rolling your own. I've had good experiences with simplejson for Python and php-json for PHP.