I slept through the earthquake last night. I put this down to the fact that I’ve just had 4 nights of getting a maximum of 2 hours’ sleep at a time due to coughing and fever.
Rachael was probably woken, but didn’t realise it was an earthquake as she was already being regularly awoken by my snoring.
The positive aspect: if an independent observer cannot tell the difference between my snoring and a force 5.2 quake at 65 miles’ distance, that should give me a fair starting point to work out where my snoring measures up.
Simon and Garfunkel once nearly made a record where the B-side consisted entirely of them playing a game of “Tag”. The record was never made because they were stuck on the one important question:
Was Art It?
""" Template Dictionary module An enhancement to python's template stuff. At present you must supply all parameters to instantiate a string template. We want to be able to instantiate only the paramaters that we have right now, and leave the others for instantiation later. Without TDict: >>> "%(greeting)s %(person)s"%{'greeting': 'Hello', 'person': 'World'} 'Hello World' >>> "%(greeting)s %(person)s"%{'greeting': 'Hello'} Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'person' This module provides class TDict (template dictionary) that, if you try to read a non-existent key "keyname", returns "%(keyname)s". Hence, it "passes through" any undefined names. >>> from TDict import * >>> a=TDict({}) >>> a['a']='bibble' >>> a['a'] 'bibble' >>> a['b'] '%(b)s' >>> "%(greeting)s %(person)s"%TDict({'greeting': 'Hello'}) 'Hello %(person)s' >>> tdict("%(greeting)s %(person)s",{'greeting': 'Hello'}) 'Hello %(person)s' """ class TDict(dict): def __init__(self,d={}): dict.__init__(self) for k in d.keys(): self[k]=d[k] def __getitem__(self, key): try: return dict.__getitem__(self, key) except KeyError: return "%%(%s)s"%key def tdict(template,dict): d=TDict(dict) return template%d
The birthday boy, and the birthday boy’s girlfriend’s dad some bloke:
“I fucking love you!”
“Did you just say what I thought you said?”
“No.”
“…”
“Did you think I said I fucking loved you?”
“Yes”
“Oh, yes, then.”
“Do you do wrapping paper?”
“Yes, is it for a boy or a girl?”
“I was thinking High School Musical”
“Oh, sorry, there’s no High School Musical wrapping paper, just princesses and things”
“Mm, yes that could do fine”
“How old is she?”
“It’s a boy… and he’s 33″
It was fun watching about 104 different expressions fighting for space on her face.
I’m now half-expecting them to be on the phone to the CIA about un-American activities.
When posting the python below, I used the non-breaking space HTML entity to make sure the indentation of the code was correct. But what if you want monospaced text with word wrap? You can simply use regular spaces, but multiple regular spaces in a row are contracted to a single space. So the following:
1 2 3 4 5 6 7 8 ← count x x x x x ← clave
comes out as:
1.2.3.4.5.6.7.8. ← count
x x x x x ← clave
Not a whole lot of use. What I want is a non-breaking space that breaks. Or better, a space that doesn’t collapse. Let’s see what HTML entities we have to play with.
|   | em space |
|   | en space |
| | no-break space = non-breaking space |
|   | thin space |
| ‍ | zero width joiner |
| ‌ | zero width non-joiner |
well,   and   are, as their names suggest, a space-as-wide-as-an-n and a space-as-wide-as-an-m. What does this mean in a fixed-width font? One might be forgiven for thinking they are the same as one another.
But they’re not. In the fixed-width Courier font, we get this:
[nnnnnnnnnn] ← 10 ens
[ ] ← 10 en spaces
[mmmmmmmmmm] ← 10 ems
[ ] ← 10 em spaces.
(Oo, I notice that works fine in Internet Explorer! Firefox got it wrong though!)
Well, thought I, in a moment of genius, how about a zero-width non-joiner then? If I have a non-breaking space followed by a character that can break, surely that’s like a fixed-width breaking space?
← I don’t know about you, but I see a whole load of crappy lines there.
Executive summary: the web is STILL broken.
Addendum: wordpress’s editor HATES this post!
Virtuoso percussion and rhythm section drawing from a rich, complex, spiritual drumming tradition, spoiled by a guy with a fecking saxophone.
#!/usr/bin/python
"""
py2html
Prepare a python script for posting on a wordpress blog
USAGE:
py2html <mypython.py >myhtml.html
"""
import sys,re
mapping=[
('&','&'),
("'",'''),
(' ',' '),
('"','"'),
('<','<'),
('>','>')
]
print '<PRE>'
for l in sys.stdin:
for (fro,to) in mapping:
l=l.replace(fro, to)
l=l.strip()
print '%s<BR />'%l
print '</PRE>'
(I only posted that so I could have the pleasure of running a program with itself as input)
/edit: I just re-did the other listing with http://tom.idealog.info/blog/20031205-1070600658.shtml … though I needed to re-do the “quote” function in there to use the “mapping” from above.
#!/usr/bin/python """ yield.py Demonstrates a recursive generator method. This allows very large nested Container structures to be created, and when rendering to a string, we don't need to create the whole thing in memory (handy if, like me, you want to create 160,000 line XML files. """ class Container(object): def __init__(self, name, contents=[]): self.tag=name self.contents=contents def lines(self): """ Iterate over the text representing the Container and its contents. """ # This is a generator function; really it returns an iterable object. The # only reason you know this is that it contains the yield statement. On # one hand, a nasty gotcha for the rookie pythoneer, on the other hand, a # lovely concise way of doing something you will want to do often. yield "<%s>"%(self.tag.upper()) if isinstance(self.contents, str): yield self.contents else: for x in self.contents: if isinstance(x,Container): for l in x.lines(): yield l else: yield x yield "</%s>"%self.tag # Declare a structure of nested Container objects c=Container('HTML', [ Container('HEAD', [ Container('TITLE',[ "The quick and the Dead" ]) ]), Container('BODY', [ "The quick, that's me, and the dead, that's you.", Container('Blockquote', "Ar wuz never wun te be hackin' about this here county") ]), ]) # Now write the structure's text representation out. for l in c.lines(): print "Line: %s"%l
I used to have this DvD player that a friend referred to as “slutty” because it would play anything. Because of this, I’d forgotten about Region Encoding on DvDs. My collection includes US, UK, French and Italian DvDs, none of them stolen, all paid for. My slutty DvD player died (of some kind of electronic syphillis?) and we are currently borrowing our lodger’s similar bargain-bin player. It had a menu where you could choose the region, and so I set it to 0 and it became as promiscuous as the last one.
However this DvD player has no remote (at least not in any known location) so it’s not possible to select subtitles on my foreign titles. Dubbing’s fun for many Hong Kong movies but usually is crap at conveying the pathos in anything more civilized. Surprisingly, Kung Fu Hustle is a movie that is better subtitled than dubbed. But how to turn on the subtitles?
I decided to turn my Mac Mini into a media centre - with a slightly expensive USB peripheral it can become a set-top box, a TiVo and a DvD player all in one. As phase one, I simply moved it to near the telly and put Kung Fu Hustle into the drive.
Which isn’t region free.
And probably never will be.
So my £(hundreds) mac mini media centre can only play half my DvDs, whereas the £20 DvD player from a bargain bin in Glasgow can play all of them?!
I’m currently faced with a choice of replacing the drive in the Mini with a much older one, that has weaker protection that can be overcome, or hoping that someone comes up with a dodgy hack to replace the drive’s firmware.
There can be no moral defence of Region protection:
- It cannot stop commercial piracy — if you can play it anywhere, you can copy it. In fact, I would pay £3 more for a DvD that was region-free and did not have a tedious anti-piracy message on the front that you cannot skip over. There might be a lucrative market for someone in Shanghai or Bangkok there.
- Its only effective purpose is to allow distributors to charge more for the same product in one country than in another.
- Its main effect is to rob innocent consumers of the ability to watch movies not released in their country or to take their DvD collection with them when they emigrate.
- Its secondary effect is to make otherwise-straight techie geeks like myself do a lot of research into legally very shady areas in order to watch Kung Fu Hustle on the same player as Salsa: Latin Pop Music in the Cities and Les Vacances de M. Hulot.