Lately

Maids of honor

Tuesday, August 5th, 2008 – no comments

So you’re reading a profile of Chinese musician Yang Yang in The New Yorker (link leads to an extract only) and you come across a passage that goes

When he is handed flowers, the first thing he does after smiling and saying thanks, is look around, eyes darting, for somewhere to ditch the flowers. For nine days I felt like a maid of honor.

… and then you flip back a few pages to check that, yes, it was David Remnick, the editor of The New Yorker himself, who wrote the piece, and who is now graciously subordinating himself to the subject of his profile.

CSS files for embeddable fonts

Sunday, June 15th, 2008 – no comments

[Update The site webfonts.info has a list of the fonts available for embedding, and two of the three fonts I list below (Liberation and Vera) aren’t present. So although these fonts are freely redistributable, it seems they’re not actually available for embedding. I’m not what the legal distinction is—?]

Safari now supports downloadable fonts, meaning that—from a technical perspective—web pages can appear in pretty much any font the designer chooses. (A clumsy Flash-based technique called sIFR made it possible to use different fonts for headings, though not body text.) In fact, if you’re using a recent version of Safari, and are viewing this on the web, this sentence will appear in Gentium Basic.

Unfortunately, the license agreement for almost every high-quality font prevents them from being redistributed, and therefore from being used on web pages in this way. However, there are a few exceptions:

An article on A List Apart describes how to create web pages with embeddable fonts; here’s CSS files for Gentium, Liberation and Vera.

For some reason quite a few browsers seem to be erroneously downloading these fonts: only Safari supports embedded fonts at this point, but the server log files indicate the clients with IE 6.0 and IE 7.0 user agents are downloading them as well. Does anyone know why this is happening? Are they indiscriminately downloading all url() links?

[On a separate note, the reason why the SIL are interested in fonts is somewhat interesting: they’re an evangelical Christian organisation with a focus on unwritten languages. (I’m guessing their ultimate aim is to expose as many people as possible to the Bible, though their academic linguistic work seems reasonably separate from their missionary activities, and their work is respected in academic circles.)]

London’s hierarchy of high street stores

Sunday, June 8th, 2008 – 3 comments

Something that’s been interesting me recently: London’s surprisingly strict hierarchy of high street stores (chains/franchises). There’s shops that are found in rich areas, and shops that are found in poor areas, and never the twain shall meet—you can get a pretty feel for how rich an area is from its shops, as well as what other stores might open up soon. Similar “rules” probably apply to other big cities, but I think London is particularly consistent—you don’t often find a shop in the “wrong” area.

Pearlie and I made up this list (most affleunt to least affluent):

Space NK
Muji
Paul’s
Body Shop
Wagamamas
Pizza Express
Eat
itsu
Pret
Starbucks
Office
Costa
Caffe Nero
Coffee Republic
Blacks
Fat Face
Odd Bins
Sainsburys Local
Tesco Express
Network Mobile Phone Shop (e.g. O2 shop)
Threshers
Rymans
Carphone Warehouse
Snappy Snaps
Holland & Barrett
Foot Locker
JD Sports
Boots
Blockbuster
Londis
Somerfield
Superdrug
Domino’s
McDonald’s
Burger King
Subway
KFC

The rules for what gets included are a little loose, but basically any chain with at least 10 stores in London were included. We didn’t count bigger stores (like H&M, supermarkets) because they’re often destinations in their own right. In some cases, there is a small amount of movement upward. (The fast food chains, for example, are sometimes found about Starbucks level.) Betting shops (William Hill, Ladbrokes) are pretty much the only shops we could think of that can be found pretty much anywhere.

Geohashes and the problem of Greenwich

Sunday, June 8th, 2008 – 2 comments

A geohash is a way to encode latitude/longitude into a string such as gcpvjk3c that includes only number and letters, making it easy to pass around in URLs, etc. The Wikipedia entry makes the algorithm seem more complicated than it actually is. The steps are:

  1. normalise latitude and longitude to the range [0, 1)
  2. convert normalised latitude and longitude to binary (in the conventional way)
  3. interlace the bits of the two binary representations to create one binary number
  4. convert this number to base-32 (i.e. every 5 bits becomes a character) using a alphabet that includes all the numbers and all the alphabet, with the exception of a, i, l, o

A geohash also supposedly has the property that similar locations have a similar prefix, making it easier for computer programs to figure out similar locations, without resorting to complicated and slow trigonometry that won’t scale to hundreds of thousands of points.

Geohashes do have this property for many geospatial neighbours, but there’s still a most significant bit, and locations either side of it are going to have very different geohashes. Unfortunately, given the location of Greenwich—about 10km to the east of central London—a whole bunch of London locations have very different geohashes. u10hb7951 and gcpuzewfz, for example, are very close to each other.

Moving the 0, 0 point to into the middle of the Atlantic (or anywhere not as inhabited as London) helps with this, but it’s obviously not a robust fix. I wonder how the geospatial extensions to MySQL and PostgreSQL actually work? It’s fairly efficient to convert hashes based on one origin to another, so perhaps they store multiple hashes per location? There must be some clever algorithms for this.

Disabling accesskeys (shortcuts) in WordPress

Tuesday, June 3rd, 2008 – one comment

OS X comes standard with many Emacs keybindings (Ctrl-A to move the cursor to the start of the line, Ctrl-E to go to the end, Ctrl-N and Ctrl-P for next and previous line, etc.), and since I’ve been using these keybindings for about 15 years it’s pretty difficult to not hit, say, Ctrl-P when it happens to conflict with WordPress’s shortcut to publish a post… This is pretty much guaranteed to happen at least once whilst writing a post, so this needed to be fixed.

There’s no configuration option to turn this off, and accesskey=”p” is buried in the HTML source and I couldn’t figure out a way to filter it out—so the only thing left is JavaScript.

The fix I came up with is below; I’m just dumping this here instead of packaging it up because I haven’t tested it on IE and it doesn’t work at all on Firefox (though see below for a solution for Firefox). You basically need a plugin like this:

function disable_accesskeys() {
    ?>
        <script type="text/javascript">
        jQuery(function () {
        var l = document.getElementsByTagName("input");
        for (var i = 0; i < l.length; i++) {
            if (l[i].accessKey) l[i].accessKey = '';
        }
        });
        </script>
    <?php
}

add_filter('admin_head', 'disable_accesskeys');

Note: for some reason this doesn’t work with Firefox. (Though neither does Wikipedia’s JavaScript solution, upon which this is based.) However, there’s a better solution for Firefox: you can disable access keys/shortcuts completely by setting the ui.key.contentAccess (access via about:config) preference to 0 (i.e. zero). (Is there an equivalent for Safari?)

Access keys are a bit of a failure, I think. They’re not consistent, not transparent (you don’t know what’s going to happen before hitting a combination), and they can conflict with whatever bindings your users might be using already.

*  *  *

Turns out that the original Emacs keybindings were fixed the way they are because, when Guy Steele was putting them together, about 20 people at the AI lab at MIT were already using Emacs, and so he couldn’t change the bindings without alienating existing users

A few years ago I asked Google answers for a good, authoritative, durable reference for Emacs keybindings (I wanted to pass this on to people) and didn’t get any good replies. I wonder if one exists now?

Final Emacs keybinding-related note: on OS X, putting DefaultKeyBinding.dict in ~/Library/KeyBindings makes a whole lot more Emacs keybindings available, as well as making Home and End work the way they do on Windows. (i.e. move cursor to the beginning and end of the line.)

Link tracking via JavaScript and Cookies

Sunday, June 1st, 2008 – no comments

This site, like just about every other, links to itself from the header, footer and sidebar. It’s somewhat interesting (and maybe even useful) to know which of these regions are actually being used, and the other day I realised this can be tracked fairly reliably and non-invasively using a cookie with a very short lifetime to store the region.

The way it works is, if you’re on a.html and click on a link that takes you to b.html, as you click on the link on a.html, some JavaScript runs that figures out which region you’re in, and writes this to a cookie with a very short lifetime. Then b.html loads as normal. Then, once b.html has finished loading, the tracking code pulls the region value out of the cookie and sends it on.

The Prototype code to trap clicks:

document.observe('click', function(v) {
    var e = v.element();
    while (e.id == "" && e != document.body) {
        e = e.parentNode;
    }
    Cookie.set("region", e.id != "" ? e.id : null, 20); // short lifetime
});

This finds the first ancestor of the clicked-on element that has a id attribute, and saves that as the region. It is run on every click—not just links—but my site is mostly flat HTML so most clicks do end up as page loads. (If this is not the case, you could add some code to filter out the non-page load clicks.) The 20 seconds is basically a guess that b.html will have loaded completely in 20 seconds—too long and you risk capturing regions from different sessions or browser tabs, too short and you won’t capture regions at all.

In b.html, the region is extracted with Cookie.get(”region”); see init.js (which also defines Cookie.set() and Cookie.get().)

JavaScript frameworks hosted by Google

Tuesday, May 27th, 2008 – no comments

For a little while the YUI has been hosted by Yahoo; now Google is doing the same for jQuery, Prototype et al. There’s some documentation available but essentially you do e.g.:

<script 
type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js">

(You can select specific major/minor versions via different URLs, though this places some limitations on the expiry headers that get sent back.)

Google recommends that you load the frameworks via google.load(). What is the advantage of doing this? It seems to do nothing other than add overhead unless there are complicated dependencies.

The headers that come back are

HTTP/1.0 200 OK
Last-Modified: Sat, 24 May 2008 00:39:29 GMT
Content-Type: application/x-javascript
Expires: Wed, 27 May 2009 20:51:04 GMT
Date: Tue, 27 May 2008 20:51:04 GMT
Cache-Control: public, max-age=31536000
Content-Encoding: gzip
Server: GFE/1.3
Connection: Close

which seem pretty sensible. (Curiously, you only get a gzip response with a Accept-Encoding that includes gzip and a User-Agent Google recognises, like that of Firefox. wget –header=”Accept-Encoding: gzip,compress” won’t do it.)

I don’t know of any privacy or service guarantees. However, as Dion Almaer points out, they’re served from a ajax.googleapis.com, not google.com, so users’ google.com cookies aren’t available for tracking. As of now the service doesn’t set any either.

I’ve done a few quick tests, and serving prototype.js (30k, compressed) from Google to the UK and US is 4-5 times as fast as prototype.js from beebo.org (in Paris). For Australia, though, it’s only slightly faster.

When you aim at the king you had better kill him

Monday, May 19th, 2008 – no comments

The punishment meted out to an unfortunate Robert François Damiens, who attempted to assassinate Louis XV on 5 January 1757:

The said Robert-François Damiens has been convicted of having committed a very mean, very terrible, and very dreadful parricidal crime against the King. The said Damiens is sentenced to pay for his crime in front of the main gate of the Church of Paris. He will be taken there in a tipcart naked and will hold a burning wax torch weighing two pounds. There, on his knees, he will say and declare that he had committed a very mean, very terrible and very dreadful parricide, and that he had hurt the King … He will repent and ask God, the King and Justice to forgive him. When this will be done, he will be taken in the same tipcart to the Place de Grève and will be put on a scaffold. Then his breasts, arms, thighs and legs will be tortured. While holding the knife with which he committed the said Parricide, his right hand will be burnt. On his tortured body parts, melted lead, boiling oil, burning pitch, and melted wax and sulphur will be thrown. Then four horses will pull him apart until he is dismembered. His limbs will be thrown on the stake, and his ashes will be spread. All his belongings, furniture, housings, whereever they are, will be confiscated and given to the King. Before the execution, the said Damiens will be asked to tell the names of his accomplices.

Tim Blanning notes: “In the event, the actual execution was even more ghastly than this scenario suggests. The four horses proved unable to tear Damiens apart, not even after reinforcements had been hitched up, so the executioner was obliged to employ an axe to sever what parts of the limbs were still attached. The victim remained conscious throughout, repeatedly shrieking, ‘My God, have pity on me! Jesus, help me!’, and—according to one observer—was still alive when his torso was thrown on to the pyre.”

(From The Pursuit of Glory: Europe 1648–1815, by Tim Blanning, p. 203.)

Fortunately, peasants are human beings

Sunday, May 18th, 2008 – no comments

Late 17th C. attitudes towards peasants:

It is true that peasants are human beings, but they are somewhat less refined and are coarser than the others. One only has to observe their behaviour and their gestures to see how easy it is to distinguish a peasant from someone with manners … Their odious way of speaking and behaving is obvious to everyone … When they eat, they don’t use cutlery but thrust their hands straight into the bowl … It might almost be said that peasants should be treated like dried cod: they are best when they have been given a full load of work to do, for then they are disciplined and regimented. The peasant always wants to be master, if his master allows him to give himself airs and graces. No one knows better how stubborn the peasants are than he who has lived among them for a long time. And one thing is certain, no amount of just saying the right thing will change a peasant, the only thing that he understands is firm language supported by threats of corporal punishment.

(From The Pursuit of Glory: Europe 1648–1815, by Tim Blanning, pp. 186–187.)

Where your money goes

Wednesday, January 23rd, 2008 – no comments

The price of a thing is largely wages. (What proportion is wages? I guess it depends on the thing. But, say, a computer or car is mostly wages; a restaurant meal has a larger real estate component.) Anyway, if you buy a Prius, but Toyota’s workers spend their money on virgin forest furniture and dirty electrical power, have you really achieved anything at all? Does the environmental behaviour of a company’s employees matter? If your Prius is chauffeur-driven, do you need to monitor your chauffeur’s spending?