Computer not here…

Oliver Brown
— This upcoming video may not be available to view yet.

My new computer has still yet to arrive. I was expecting to be able to write a hands on review of MCE by now.

Silly things with JavaScript closures

Oliver Brown
— This upcoming video may not be available to view yet.

From a theoretical programming point of view, JavaScript is immensely cool. You can do some amazing things with it. Although I’m not entirely sure whether you should.

For example I had a bunch of elements on a page I needed to update using AJAX. I needed a function I could pass the URLs and ids of elements to replace with those URLs and then have it perform each replacement in turn (I’ve seen IE have problems with simultaneous AJAX requests).

First I replace a simple replace_id function that accepts three arguments. An element id, a URL to GET to replace its contents with and finally a function to be called when it’s all completed.

And then things got silly.

function chain_replace(urls, ids) {
    id = 0;
    next_id = function() {
        if (id < = ids.length) {
            return function() {
                replace_id(urls[id], ids[id++], next_id());
            }
        }
    };
    next_id()();
}

Now the next_id()(); bit towards the end should be a clue that something a little odd is going on. But I must confirm that this code does actually work. With enough arguments it might make the browser explode with some sort of call stack problem though…

Coop gaming

Oliver Brown
— This upcoming video may not be available to view yet.

Finally someone in the mainstream agrees with me.

There is a section in PC Format magazine that says cooperative play in upcoming games will be a bigger part. Coop gaming, especially in first person shooters is tremendously fun. I spent a lot of time playing Duke Nukem 3D and Doom coop on my PlayStation. Very few games after that supported coop modes (although I realise that it brings some complicated design issues).

Windows XP Media Center Edition 2005

Oliver Brown
— This upcoming video may not be available to view yet.

I’m getting a new computer. Well most of a new computer. And I’ve been considering whether to get Windows Media Centre Edition or not.

The first two versions of MCE were rather lacking but after reading a lot I’ve decided 2005 is actually quite cool.

What is Windows XP Media Center Edition 2005?

Good question. One I didn’t know the answer to until recently. It’s Windows XP a with range of new utilities for working with video, music and images (as well as bits of hardware associated with them) all wrapped inside one interface. The idea is to have your computer as the hub for your whole home entertainment system.

Digital Video Recording (DVR)

The most useful component is the built in DVR software (sometimes called Personal Video Recorder or PVR). Plug your TV into your TV tuner card and Windows can record stuff straight to your hard drive. But of course most TV tuners come with software to do this. Well MCE does it better to be honest. And you can also get a hardware bundle (ready built systems come with it) that includes a IR blaster. Basically it’s an infra-red transmitter you stick to the front of your set top box (Sky, cable, whatever) to allow your MCE computer to change channels.

Disk space

The lowest quality recording takes up between 1Gb and 1.5Gb per hour. Reasonable hard drives these days are about 200Gb which gives you about 100 hours of video (leaving space for other stuff). Not really suitable for storage but it does allow you to burn things to DVD. Most of the time. The software apparently supports any content restriction specified in incoming media and won’t let you copy such content of the computer that made it.

But it’s still a computer, right?

MCE is actually Windows XP Professional underneath. It took a while to confirm (most references are vague about whether it’s XP Home or XP Pro) but I did find a page on Microsoft’s website saying it’s XP Pro. This means you can do everything with it that you can normally do with a PC.

One final note… you could always install MCE on a Mac.

Even simpler searching

Oliver Brown
— This upcoming video may not be available to view yet.

I decided to take my idea for nicer searching in Wordpress one step further. Now if you try to get to a page that doesn’t exist it automatically redirects to the search page. So http://www.oliverbrown.me.uk/galaxia will return search results for “galaxia”.

If you want to do it yourself, you need to do two things. First you need to redirect error pages to a custom PHP page so add the following line to the top of your .htaccess file: ErrorDocument: 404error.php Now you need to create 404error.php and make it redirect to the search page by adding the following to it: header('Location: http://' . $_SERVER['HTTP_HOST'] . '/search.php?s=' . $_SERVER['REDIRECT_SCRIPT_URL']); After doing this it had me thinking about status codes. By default that will generate a 302 Found HTTP status code. A bit of reading led me to decide that 303 See Other was a better response since the request might correspond to a page in the future (and presumably a relevant page) but for now should be redirected. 3XX are somewhat confusing.

Anyway if you want that behaviour, add this line too: header('Status: 303 See Other'); Finally, you should think a little before implementing this since any random page accessed could now be cached by proxy servers and search engines etc. since the server is no longer sending a 404 Not Found code.

ASP.NET sucks

Oliver Brown
— This upcoming video may not be available to view yet.

I recently bought a book about ASP.NET: Pro ASP.NET in C# by Apress, mainly because when I was looking for jobs there were lots of ASP.NET jobs advertised. And I have to say I have no idea why. Part of the problem may be that is book isn’t very good (there are bits of vague contradictions and a general obsessive (and inaccurate) preachiness about it) but I think there are major limitations to ASP.NET.

Firstly the inability to post to a different page. Who the hell decided that was good idea? I know it can be faked but that’s just silly. And you can only really have one form on a page. Well you can only have one “rich” form that ASP.NET can access in a clever and high level way.

I’m assuming people will disagree with me (if not, why is it so popular). If you do, please explain why ASP.NET is supposed to be so amazing because I don’t see it…

Updated - Clarifying my position on ASP.net

And we’re back

Oliver Brown
— This upcoming video may not be available to view yet.

The Wordpress wp_options table manage to get corrupted. I tried MySQL’s repair but the table was still not well so I had to copy the table from another installation and reset everything.

For one scary moment nothing was displayed on the site but then I realised that was because it was trying to load a theme that didn’t exist. Everything is happy again now.

Blue screen of death

Oliver Brown
— This upcoming video may not be available to view yet.

My computer is now essentially dead. Luckily I have internet access at work and an hour lunch break :D

It’s been getting increasingly unstable for the past month or so giving me random blue screens of death. Sometimes I get a driver reference that caused the problem (and they are different drivers each time) and sometimes I don’t. Yesterday it managed to crash while trying to display the Windows log-in screen and I was left with just a cursor on black screen.

Since I now have money and it’s old anyway (Athlon 1.2GHz - back when AMD named their processor after their real speed), I’m not so bothered.

JavaScript debugging with Internet Explorer

Oliver Brown
— This upcoming video may not be available to view yet.

Ever had a problem with JavaScript? If you don’t realise that’s a rhetorical question then go away now…

I had a simple script that worked fine in Firefox and Opera but not in IE. I got the amazingly useful message “Object expected” at line 0, character 0. So after looking around for a bit I found the Microsoft Script Debugger. And it’s actually quite good. Not as convenient as Firefox (since most of my problems are syntax errors) but it solved my problem. And in a way, I can blame Firefox and Opera for the problem. Maybe.

“class” is a reserved word in JScript (IE’s JavaScript engine) but it isn’t in Firefox and Opera. Perhaps it should be. Then perhaps not since contrary to popular belief, JavaScript (or technically ECMAScript) is not an object orientated language (at least not in the traditional sense), it’s a prototype language.

The main difference is a prototype language does not have classes (which is why “class” is not a reserved word in Firefox or IE), objects are given functionality on a per instance basis.

All this is rather academic though. If you need to debug JavaScript in IE for whatever reason, get the debugger. And ignore the link that says there is a newer version available - it’s pointing to Visual Studio .NET 2003.