Top Gear in the Sun

I just watched the latest Top Gear episode where the intrepid team flew to the U.S. The aim was simple – buy a car in Miami for $1000 or less, drive to New Orleans and sell it. Oh, and there were some challenges to complete along the way.

Sounds easy, right? Nope, not a bit of it. As ever it was part hilarious, part educational. But this episode had other parts which were downright frightening, and in some ways absolutely damning about Americal culture in the deep south.

If you don’t find people making fun of rednecks, eating roadkill, and joking about how many murderers have owned a car before, or are just easily offended, then don’t watch it. Otherwise, do, as it could be one of those bits of film that is hailed as a classic in years to come.

[Update] A bit of browsing round the BBC website came up with this interesting little environmentally-friendly app, thanks to Kate Russell. I’m giving it a go.

Cartoons I have Known and Loved

There are some hugely talented cartoonists out there in WebWorld (not to be confused with WaterWorld, which is more wet in any number of ways). Thanks to the wonders of feed subscription I can keep up to date with all of my favourites very easily.

So here’s my top 5 favourite cartoons available on the web:

5) In at number 5 is OK/Cancel drawn by the esteemable Kevin Cheng. It’s like Dilbert (see number 4) but in an even more believable world. In fact I sometimes wonder how his bosses at Yahoo let him get away with it; no doubt they have meetings behind his back in which they discuss how to avoid becoming the next Cheng target.

My favourite recent cartoon was this subtle dig at online advertising*.

* This link was brought to you in association with ChumpMonkey Enterprises, manufacturers of high-quality chumpmonkeys.

4) At number 4 (only at number 4?! I hear you cry) is the insightful and oh-so-true Dilbert. OK, Dilbert is a classic amongst anyone in the IT industry, but he only makes number 4 for me, mainly because of the vagaries of my brain, but partly because Scott Adams’ blog is, on the whole, funnier. Not funnier in a ‘that’s funny’ kind of way, I mean funnier in a … remember those monologues that Kryten used to have in Red Dwarf? You get the picture.

My favourite recent cartoon was this one which illustrates why, sometimes, carts are better before horses.

3) Slipping in at number 3 is Bug Bash by Hans Bjordahl, a delightfully colourful cartoon showing the lighter side of programming. More than once have I used a technique directly from this cartoon to cover my ample behind when something has not gone as … optimally as it could have.

Take this, for example. My favourite recent cartoon shows how words can be used to give someone the slip. Funny, and true.

2) Just missing the top spot at number 2 is one of the web’s most popular sites: gapingvoid. While Mr MacLeod may be doing more wine promotion than cartooning at the moment (he has a living to make) his extensive archives are full of absolute gems. And with quite often anything up to a dozen new cartoons appearing even on an average day, there is plenty to be going on with.

This little beauty is my recent favourite. Partly because his simple but brutal style still amazes me, but mostly because he makes public what goes on in all our heads.

1) Ranking in the top spot is my very good friend Dave with his Cartoon Church. He’s not an A-lister like Hugh MacLeod or Scott Adams, and he’s not into software like Kevin Checng or Hans Bjordahl. But, and this is the key for me, his sense of humour ties very closely with my own. Sure, I’m quite a bit more manic than he is (he’s actually a quite shy, retiring sort of chap) but his skewed way of looking at the world is something I find resonates with me at a deep level. Or perhaps that’s just the three bean soup repeating on me.

So many favourites to choose from. However recently I have sniggered repeatedly at the perfect gadget, even if I am one of those idiots with white headphones.

So, long may internet cartoons continue. Special mention must also go to a very recent discovery, XKCD, which is proving to be a worthy find. This 90’s flowchart nearly made me fall off my chair.

What is Web 2.0

It’s been a bit of a mad week, what with work, more work and a brief timeout to recover from a cold. However this video has been aking the rounds recently, and I think it’s great. It’s certainly a great use of showing abstract ideas in a concrete way.

Unobtrusive Javascript – the stillbreathing way

It’s been a while since I posted a decent code sample in JavaScript, so here’s a quick idea that I’ve been formulating for a while. It’s to make JavaScript unobtrusive – which means it doesn’t clomp it’s heavy boots all over your nice flowers. Sound too good to be true? Not really.

For this example I’ll be using the Prototype library (take a look at their shiny new website, too) as it’s my framework of choice. There are plenty of other frameworks available any one of which will work with this technique, so don’t worry if you’ve got a hankerin’ for another flavour of framework.

OK, onto the article. The problem is that I want to attach a JavaScript command to certain elements, in this case a series of links, the command in question will load content from an external resource into the page at a specified point in an AJAXy manner. Well, actually it will be an AJAHy manner, as we’re using HTML rather than XML as the return data type. What does that mean to you? That you don’t have to do any Javascript transformations of XML data. Vive la innerHTML.

So, first things first. We slip a little onClick goodness into our links … er, hang on. No we don’t – that would be extremely intrusive. So what can we do? Let’s think about what we need to do with this link:

  1. Make the browser aware it’s a special type of link so that we can access it with our Javascript.
  2. Somehow make the link set the Javascript content loader function to access the right server-side script. Hmm.
  3. Somehow make the link tell the Javascript content loader function to put the content returned from the server-side script into a certain element. Hmm again.
  4. Not be shown if the user doesn’t have Javascript enabled/available.

The first thing we do is group all the special links together by giving them a special CSS class name. In this case as our links are going to be refreshing parts of the page we’ll use a CSS class of ‘refresher’. That makes our links Refresher links, and everyone likes refreshment, don’t they?

So we’ve got our class set on all our Refresher links, which means we can use the Prototype DOM function getElementsByClassName to access them all. But what about hiding the links when Javascript isn’t available.

Simple. Let’s set some CSS in our stylesheet to hide the Refresher links by default:

.refresher
{
  display: none;
}

And they’re gone! Now we just need to turn them on again using Javascript – that means only people with Javascript will see them. Here’s the CSS:

.refresheractive
{
  display: inline;
}

And here’s the Javascript:

for (var i=0; i<document.getElementsByClassName('refresher').length; i++)
{
  document.getElementsByClassName('refresher')[i].removeClassName('refresher');
  document.getElementsByClassName('refresher')[i].addClassName('refresheractive');
}

So now those links will only show for people with Javascript. Great. But what about the other two bits of information we need to pass from the link – the processing server-side script and the target element? Well, here’s where we dust off some little-used attributes. Namely rel and rev

I should say at this point that rel and rev do have specific semantic meanings, denoting the documents’ relationship with the target of the link. They are used quite a lot for microformats, and rightly so, but I don’t think this technique is stepping too far away from correct use of those attributes. And at least this way is better than making up non-standard attributes (I’m looking at you, Spry) or forcing convoluted encoded strings into the links id attribute.

So, how do we do it? Easy, like this:

<a href="#targetElement" id="MyFirstRefresherLink" rel="updater.php" rev="targetElement">Click to update</a>

See? Easy. A bit of Javascript magic and we’re up and running.

for (var i=0; i<document.getElementsByClassName('refresheractive').length; i++)
{
  var targetElement = document.getElementsByClassName('refresheractive')[i].getAttribute('rev');
  var processingScript = document.getElementsByClassName('refresheractive')[i].getAttribute('rel');
  // do the updater thingy here
}

That technique works great for me, so I hope it’s useful for you.

Invaluable CSS techniques (and people)

Here’s one for you CSS jockeys to bookmark: 53 CSS techniques you couldn’t live without. I knew about half of these, but the others will come in really handy as well.

UPDATE: If you’re looking for the best of the best CSS gurus to handle your large web project this bunch will do you proud (tell them I sent you, they’ll say "Chris who?"). But if you just need a small project doing then you could hire me (tell me I sent you, he’ll give you a good deal).