Hmmm. I'm not sure I'm main keen on the link-only, 'please check out our wiki' answer
here. The code sample's probably just about short enough to reproduce here. Is Github considered stable enough to avoid linkrot? Should the copyright notice at the start of the code sample prevent me from reposting it into the answer?