Stephen Hawking: Idiot?

I’m using the new headline writing technique of writing something ridiculous and controversial and then putting a question mark in so I can get away with it. No Stephen Hawking isn’t an idiot. But he’s doing something that I disagree with, so I’m going to call him one. That’s how the Internet works.

Hawking intends to jump back in the popular science book arena in early 2008 with a new book on his favourite subject: the origin of the universe. Hawking is certainly qualified to write such a book, and his previous successes lead me to expect that it will do quite well. So why is he an idiot?

He’s only gone and called his new book "The Grand Design"! Let me be clear here. Stephen Hawking is clearly and evidently not a theist in any meaningful sense. Yes, he uses God as a convenient metaphor throughout his writing for a popular audience (at least; I haven’t read any of his academic writings so I can’t comment on them). But it should be clear to anyone familiar with his work that he is, at worst (or best, if that’s your perspective) a deist and most probably an atheist.

So why muddy people’s thoughts by using as a metaphor an idea that many people take to be literal truth? Even moderate religious people will no doubt interpret this title to mean that Hawking literally believes that the universe was consciously designed by some self-aware entity. Which will of course fuel the popular perception that there are a great many educated and influential scientists who hold such parochial views. They don’t.

Albert Einstein is often trotted out as a key figure in such an appeal to authority. While the argument from authority, familiar as it is to many believers, is fallacious, in this case it’s based on a faulty premise to boot. Like Hawking, Einstein used the metaphor of God extensively. But in his case it’s even clearer what his true views were. Citations and quotes abound that demonstrate beyond all doubt that Einstein did not believe in a personal god. But, like Hawking after him, he failed to realise the damaging effect of facilitating this misconception.

Metaphor is a powerful literary tool. And it is often based on myth. But surely it is prudent to wait for a myth to die before resurrecting it to spruce up book titles?

Finally, on a slight aside inspired by comments I have read about this story, when is someone going to write a book addressing the really difficult question: why do people have such trouble with Hawking’s name? It is Hawking, with a G. Not Hawkins. This has been a public service digression.

Whiteboard Erased

I have a half-hearted plan to write a work-a-like of Bebo‘s whiteboard drawing feature. I think it would be an interesting addition to Soylent Red’s comments if people were able to use drawing as well as text.

Bebo’s whiteboard is a simple Flash drawing program. I decided that my work-a-like would be a good excuse to learn about the HTML5 canvas element. I realise that this would exclude Internet Explorer users from the fun, but when have I ever cared about that? Current versions of Safari and anything based on a recent Gecko (Firefox, Camino, Seamonkey) would be able to handle it. Oddly enough (because Ian Hickson, the author of the HTML5 draft, worked for Opera Software until recently) the most recent Opera release (8.5) doesn’t support canvas, although the previews of the Opera 9 apparently have support.

Having decided that browser support was sufficient for what was essentially to be a fun addition and not a necessary part of the site I set about coding the whiteboard. I have to say that the canvas drawing API is a joy to work with. It’s very simple, and very easy to pick up. It has a great deal of flexibility without having to resort to providing a host of specific methods. It took me less than an hour from starting to read the spec to having a working prototype, with a choice of five colours and three brush sizes. By this stage there were some browser inconsistencies to work around. For example, my method of finding the correct coordinates of a mouse event is still buggy, particularly in Safari.

Thankfully I didn’t invest any more time in fixing and working around bugs before I discovered the real show-stopper (and I’m not talking about the Heart-Break Kid Shawn Michaels). It turns out that no current browser supports the toDataURI() method of canvas. That means it’s impossible to submit the image data back to a server. So I have a nice little drawing applet that has no way to save your drawings. Crud.

Top 5: Video Game Characters

It’s been a while since the last installment of Top 5. I was working on another list but it didn’t work out as well as I’d hoped so I’ve filed it away carefully in /dev/null. I have to say that finding the right subjects to cover in these lists is harder than I first thought. The subject has to be one that people are interested in so that there’ll be some amount of arguing afterwards; it has to be broad enough that I’m not just listing the five things that qualify for the list; and it has to be narrow enough that I can have some hope of knowing what the hell I’m talking about.

So, throwing that last point (as well as all caution) aside, I’m going to try to list the Top 5 Video Game Characters. Try not to get too angry at me for getting this list so badly wrong.

5. Tails

Maybe Tails was less obvious than his more extroverted Hedgehog buddy Sonic, but that really added to his charm. Tails was content to hang back and let Sonic do all of the real work. He’d just saunter along behind the action, chipping in whenever he felt like it but never making a commitment. He was a symbol for our generation of free-loaders and coasters. And he could fly.

4. Heihachi Mishima

Given that many video games are aimed at the angry and hate-filled adolecent boy demographic, and that many of my game-playing years were spent as a memebr of that group, there’s inevitably going to be a skew in favour of ass-kicking, name-taking, hurt-locker-putting badasses. Heihachi is the Tekken series’ contribution. I joined the Tekken bandwagon at its third incarnation, where Heihachi stood out as the toughest SOB in the beat-em-up genre. I remember playing a versus battle with Heihachi and King that lasted about five seconds of the most bone-crunching moves in the game and ended very close to a double knock out, Heihachi barely the victor. Unfortunately I was using King. Even now in Tekken 5 when Heihachi is suppposed to be dead he can’t be beaten easily.

3. Sarge

Quake scared the shit out of me. The haunting noises of evil foes just around the corner, the dark shades of brown and grey in the deepest dungeons. I couldn’t bring myself to play it at night. None of it seemed really to bother the game’s protagonist, the hard-as-a-nailgun GI known as Sarge. Everything great about this character is summed up in the opening video of Quake 3, when you really think he can win against his crowd of foes even if he is only armed with a cigar. This is even before we consider that he’ll be played by The Rock in the Doom movie.

2. Sephiroth

Long black coat, cool-ass Japanese sword, chanting music in the background. The villain of Final Fantasy VII is himself most of the reason that it’s the best in the series. Nothing I can say will really evoke the awesome cool that radiates from this character during 70+ hours of playing FF7. Look for him in Advent Children.

1. Pac-Man

This is the second Namco entry on the list. Interestingly it has been rumoured that Pac-Man is actualy Heihachi Mishima’s biological father. Make of that what you will. He’s just a yellow disc with a wedge cut out of it but, as one magazine put it, he oozes more cool than a Zanussi in the arctic. He’s got an indellible retro chic, like a lava lamp that never went out of fashion. He’s also big business, being the most played arcade game in the world.

That’s my Top 5. What? No Mario, no Donkey Kong, no Street Fighter characters? No Ecco the Dolphin? Have I gone completely insane? You tell me. Who deserves to be on this list and who doesn’t?

Incidentally, I’m going to break with tradition and give a single honourable mention. This is the special category of ‘hottest video game character’, and my number one is Tanya from the Red Alert series. To hell with Lara Croft. Tanya, played by Kari Wuhrer in Red Alert 2, is the reason cut scenes were invented.

JavaScript Annoyances: for (i in array)

I got bitten by a JavaScript annoyance today that I figured I’d describe here in case other people have the same problem. I’m not going to call it a bug, because technically it isn’t.

I was looping through an array, using the syntax for (i in a) where i is the array index and a is the array. Inside this loop I needed to do some simple arithmetic, just a basic i + 1. What can go wrong? As it turns out, everything.

Since JavaScript is loosely-typed it just happily converts your variables from one datatype to another whenever it needs to. This is handy when you want to concatonate an integer on the end of a string, or do arithmetic on a number stored as a string. Unfortunately the combination of this loose typing and the overloading of the + operator can lead to problems.

The for (x in y) construct is used to iterate over all of the keys in an object, but the keys it returns are all converted to strings. When you try to add 1 and 1 (to get 2), you actually end up concatonating "1" and "1" (getting "11").

The solution is to use the slightly more verbose for (var i = 0; i < a.length; i++) construct, which leaves i an integer throughout. Alternatively you can use the parseInt() function to turn a string into an integer, or do one of the ugly tricks like subtracting zero or multiplying or dividing by one (we’ve seen that adding zero won’t work because of the overloaded +).

Hopefully in taking the time to write this up I won’t fall for this again.

Powerbook

I just placed an order for an Apple 12" Powerbook, which I’ve been planning for weeks. Thankfully my employer got around to paying me the correct wages this week, as well as a few weeks’ back-pay. Combining that with what little credit I’m allowed on my student credit card, and with Apple’s student discount, I was able to place the order this morning. Hopefully I’ll have better luck than others have had with their Powerbooks.

Amazingly I had not yet even saved the order confirmation page before AIB’s credit card services rang me to make sure I had really placed a €1400+ transaction on my card. Literally—and this isn’t one of those annoying mis-uses of that word; I mean literally—it took them less than one minute from the time I clicked the order button. It’s nice to feel safe.

Greasemonkey Insecure

Update: There’s a neutered version available until this bug can be fixed. Thanks to maca for pointing this out in the comments. I should also add that the maintainers are doing a great job sorting this problem out.

Since I’ve spouted here about the virtues of the Greasemonkey extension for Firefox, I should probably point out that, as of right now, Greasemonkey is completely insecure. That is, if you have it installed you should uninstall or disable it. I’m not kidding. There’s already a proof-of-concept exploit that demonstrates that any page that you run a Greasemonkey script on (which usually means any page at all since Greasemonkey scripts execute on all pages by default) can access any file on your computer and send its contents to any server.

Uninstall Greasemonkey altogether. At this point, I don’t trust having it on my computer at all. I would think that whoever is in charge of addons.mozilla.org should immediately remove the Greasemonkey XPI and post a large warning in its place advising people to uninstall it.

Mark Pilgrim

Reading a Numbered Email from an Mbox in PHP

We’ve settled on the name Email Activity Assitant for the project I’m doing this summer. Inspired by the name, I’m going to try to find time to work a helpful paper-clip character into the interface. Like Clippit, only more dynamic and proactive.

Today I had to write a Web application that sends a series of pre-stored emails. We’ll use it to test our application’s ability to classify emails as they arrive. This will save us the embarrassment of ordering five hundred Lindsey Lohan Original CD Clocks, one for each time we have to test the mail grouping and activity-identifying algorithms.

We have a few sets of emails in a series of mbox files. Mbox is the mail storage format used by many mail applications, including Thunderbird. It’s exact specification can be found in the mbox man page but the gist is easy: Emails are stored one after another, each one preceded by a line beginning "From " (note the space; quotes not included, obviously) called From_ lines, and succeeded by a single blank line.

My application had to extract each email in turn, given only the path to the mbox file and the number of the required email. Here follows my solution. It’s somewhat broken, as I’ll explain below.

The basic idea is that we really don’t want to have to read the entire mbox file, split it into seperate emails, and then count up to the one we want. That’s just bad. Imagine trying to get the first email, a one liner asking if you’re free on Thursday, from an mbox representing the ensuing multi-week life-altering intellectual and spiritual debate about the nature of freedom and, for that matter, the nature of Thursday. So we only want to read up to the end of our email. PHP doesn’t have any built-in methods for reading a file a line at a time, so I’ve gone for a different approach.

We read in the file a chunk at a time; I’ve hardcoded the number 4096 bytes because it’s nice and round. If you don’t think that 4096 is a round number you probably shouldn’t be reading this. I chose 4096 since it’s not too large — I don’t want to read much more than I have to of the file — and it’s also not too small — being too small would be catastrophic for this code for reasons noted below. Anyway, once we’ve read the first chunk we split it on any occurance of /\nFrom [^\n]*\n/. I would have preferred /^From .*$/ but PHP’s preg_split doesn’t treat ^ and $ as beginning and end of line unfortunately. Instead it treats them as beginning and end of string, which is useless to us here.

If our required email hasn’t been reached yet — say we’re looking for the fourth and only three emails (or parts of emails) form our chunk — then we read the next chunk and continue as before. If our email, or part of it, is in the chunk we just read then we extract it. In this case we will have to read the next chunk only if we didn’t get the complete email from this one, ie. if it spans the boundary. On the next chunk we’ll just take the first part, up to the first From_ line if there is one, and append it to what we have. We keep doing this until we get a chunk with the beginning of another email or an end-of-file.

We now have our email. We also have some additional information we could use. If we hit and end-of-file we might want to do something to indicate there are no emails remaining. If we hit the EOF before finding our email we could throw a little hissy fit; alternatively we could show a helpful error.

Here’s an edited version of the code I used. $msgnum is the number of the email we want to retrieve. $mbox is the path to the mailbox.

$fHandle = fopen($mbox, r);
$currentMail = 0;
$mailContent = "";
while (!feof($fHandle) && $currentMail <= $msgnum)
{
	$chunk = fread($fHandle, 4096);
	$mails = preg_split("/\nFrom [^\n]*\n/", $chunk);
	if ($currentMail == $msgnum)
	{
		// we're in the middle of reading our mail so append the first part of the chunk:
		$mailContent .= $mails[0];
		$currentMail += count($mails) - 1;
	}
	else if ($currentMail + count($mails) < $msgnum)
	{
		// we haven't reached the mail we want yet so move on:
		$currentMail += count($mails) - 1;
	}
	else
	{
		// our mail starts (and might end) in this chunk:
		$offset = $msgnum - $currentMail;
		$mailContent = $mails[$offset];
		$currentMail += count($mails) - 1;
	}
}
if (feof($fHandle))
{
	// you might want to add some code here to be run if your email was the last one in the mbox
}
fclose($fHandle);
// $mailContent contains the contents of your email, if it was found

I promised I’d tell you why this method still sucks. You might have spotted it. The most important thing, the show-stopper if the bug is ever met, is that if a chunk contains some but not all of a From_ line, that line will be lost and the two emails it separates will be considered to be one. The chance of 20-ish character line being broken when we split into 4000+ character chunks is small but significant. This bug wouldn’t be acceptible in a live application; the only reason I let it slide is that it would be easier for me to just pad the offending mbox if we ever see this bug. It’ll show for, on average, one in 200 emails so we might well see it at some point in our testing.

The second bug, not so catastrophic, is that this method leads to a Shlemiel the painter’s algorithm. If we want the nth email we read the first n emails. So when we put this function into an application which goes through each email in turn, this is what happens: We read the first email, we read the first two emails, we read the first three emails, etc. It’s like a road painter whose work rate decreases dramatically as he gets further and further from the paint bucket. In this case the function calls are all made on seperate page views so there wasn’t much I could do short of saving a pointer to the last read chunk in a session variable. That would have been overkill, but it would be an important improvement if our mboxes got quite large. I tested on a 30+ message mbox, which looks like an extreme case for our purposes, and saw no noticeable slowdown on the later emails so I don’t anticipate this being a practical issue in this case.

Far From Obvious

Shamelessly jumping on the bandwagon Douglas Bowman provides these instructions:

  1. Grab the nearest book.
  2. Open the book to page 23.
  3. Find the fifth sentence.
  4. Post the text of the sentence in your journal along with these instructions.

It may not surprise any of you that the result of my following these instructions was this sentence:

It arises, in fact, in responce to the “starting vortex” in §1.1, but why this should be so is far from obvious, and rests on one of the deepest theorems in the subject (§5.1).

The “it” refers to the circulation around an aerofoil, the book is Elementary Fluid Dynamics, and the section is about the only part of the book not relevant to my course. Now go find a book longer than 23 pages and report back here (or elsewhere).

Credit Where Credit is Due

I wanted to send a text message today. I know this is an unusual occurance; my usage patterns of mobile phones could be measured in geological timescales. When I thought of sending the message, I wanted to type it on my familiar and comfy keyboard instead of the hard and, more importantly, small number pad of my phone. First stop netsoc‘s free SMS message system. No dice. They only send to Vodafone and O2 (still mislabeled as 087 and 086 – why can’t people keep up?).

It seemed I’d have to brave the corporate registration process at O2.ie. I gritted my teeth and assured myself that it would pay for itself in the long run. So I started to fill out the forms, the usual stuff: name, six phone numbers, two email addresses, family history traced to the famine, internal rectal radius. Then a surprise.

Hello, registration worked (yes, on your browser). It seems we haven’t given you any free money in a while and you bought that credit back in January 2003. Have another €40. No, wait. €60.

At my current rate of phone spending, I’ll need to buy more credit in February.

Network Woes

It was sheer naivety – and I apologise for the horrible auto-interjection, but I have to quote Fowler’s The King’s English stating that "it is to be wished that [naïveté] might be disencumbered of its diaeresis, its accent, and its italics" because I genuinely had no clue how to spell that word – to expect to set up my home wireless (802.11G) network without difficulty. A considered soul would be left only to consider where the difficulty would lie.

Though I was quickly made aware of the existence of gaps in my knowledge – not wholy unexpected – and in my ability to fill said gaps, it took surprising time for me to discover the exact form of my network’s malady. Though I enjoy learning more than most any other of life’s fine persuits, I generally prefer my progress not to be stifled by learning’s absence. Sadly, in this case, it was.

By this point you may reasonably expect to be told the nature of my troubles, but you may yet be surprised to discover that I have not yet fully remedied them. I do posess something that at this point I value almost as highly as a complete solution, and that is the hope that one is forthcoming.

You see, in a most frustrating circumstance, my initial conception of the ultimate nature of the network was indeed accurate and workable. However my chosen means of manipulating the current state of the equipment into the desired final state was misinformed – or, more accurately, underinformed.

I have now recieved at least some relevant education relating to the issue – in the form of unexpectedly useful email technical support from Eircom – which has shown itself to alleviate at least one irritating symptom, and which I hope will indeed constitute the entirity of the ultimate solution. I therefore look forward to tomorrow with catious optimism. Fingers crossed.