Archive for August, 2005

The Temporary Expert

Sunday, August 21st, 2005

If you read this blog you may notice that from time to time I tend to write short, obscure and deeply technical posts, like yesterday about dynamic JavaScript in Safari, or a few weeks ago about MySQL parameter substitution in Python, or back in May about installing MSDE over remote desktop. Why the randomness? Well, it’s part of my programmer community service.

Back at Gnomedex I was having lunch with Josh from TinyScreenfuls and somebody from Microsoft whose name I didn’t catch. Josh was talking about his evangelism of blogging and RSS inside Intel, and how he tries to convince people that even though there is a large set of stuff (IP related information, release dates, etc) that they might not be able to talk about, there is an even larger set of stuff that they can. At which point, our lunch mate from Microsoft remarked (and I’m paraphrasing horribly) that in all fields, but especially technology, every now and then we are all temporary experts. When you’re sitting at your desk on Tuesday afternoon with seven opened browser windows and a dog-eared O’Reilly book going deep on a particular problem, chances are good that for that brief moment you are one of a handful of people across the globe that knows as much as you do about the problem you’re trying to solve. For that brief moment you are a temporary expert. And a blog entry is a great way to bottle that knowledge up.

So excuse the randomness in some of my posts. I’m just trying to help some poor sod get through his Tuesday afternoon.

Ron Bloom’s PodShow Pitch

Sunday, August 21st, 2005

I just finished listening to the latest Gang where Ron Bloom outlines the challenge and opportunity for PodShow in light of their recent funding. Thus far I have had a bad impression of Bloom, he always seemed like the scheming villain behind Curry, but in this show he gives a really compelling pitch. In particular he talks about podcasting being able to take a shot at the radio advertising dollar where existing product is somewhat weak and stagnant. (As opposed to the digital/internet dollar which, between search and blogs and mainstream sites, is hotly contested.)

I still think, though, that putting together the technology and infrastructure to support advertising and sponsorship on such a large scale within a long-tail environment like podcasting is very non-trivial. So little text, so much production.

Safari JavaScript Oddities

Sunday, August 21st, 2005

One of the pieces of technology that we manage up here in comScore’s Toronto office is SiteRecruit, our website visitor recruitment software. Recently, despite the copious accolades, we discovered that parts of the software were not working correctly on the Mac when using Safari.

SiteRecruit is a fairly serious piece of software, as far as JavaScript software goes, and because we run on such high traffic sites it’s important that we’re as lightweight as possible, so one of the tricks that we use is to do a just-in-time script include, by dynamically adding a script tag to the document.

document.write('<script src="foo.js" />')

Safari seems to handle that fine. What it doesn’t deal with, however, is dynamically adding JavaScript code to the document itself, either through the DOM directly:

var body = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('language', 'JavaScript');
var someText = document.createTextNode('alert("foo")');
script.appendChild(someText);
body.appendChild(script);

Or by simply writing to the document:

document.write('<script>alert("foo")</script>')

Neither gets parsed or executed correctly. It’s a funny little corner of the browser to be working in. I wonder whether there are rules or specifications around adding inline JavaScript content to a document dynamically? My guess is that it’s a grey area, and the fact that you can do it in IE and Firefox is more a happy coincidence of the particular implementation than a conscious design decision.

So if you’ve landed here on the tail end of a Google search and are experiencing the same problem, apart from ending your misery quickly, I can’t help you. Luckily for us we generate our JavaScript programmatically with a tool that we’ve written (pictured above), so with a little effort we were able to factor some of the code that was being written dynamically into templates that end up as static JavaScript files.

Oh, and while I’m at it I have another odd Safari tidbit. The window object in pages opened with a target of _blank have no opener reference, so scripting between pages becomes difficult. A work-around is to open pages with window.open inside an event handler (so it doesn’t get blocked by popup blockers), which sets the opener correctly.

Note: If you’re reading this in an aggregator somewhere it’s likely that some of the content in the code examples above was stripped out. Writing about writing dynamic markup within markup that is getting XMLized and escaped all over the place is very meta and complicated. If you’re interested, just come and read on the site.

Image Scaling in .NET

Sunday, August 7th, 2005

A well written article and chunk of tutorial code by Joel Neubeck illustrating how to use C# and GDI+ to scale, crop and pad images. Exactly what I needed. (Or if all you need is a quick and dirty thumbnail, this 4GuysFromRolla article should do the trick.)

Links of Late

Sunday, August 7th, 2005

This week’s nutritious links:

  • APIs and SPIs and What I Like About REST - I meant to link to these a while ago. I sat a few seats down from Jeff at Gnomedex, and while I didn’t introduce myself, I did subscribe to his blog.
  • Dare vs Tantek - On the importance of microformats.
  • Hitting the High Notes - Joel digs into programmer productivity. An excellent piece. Timely too, we’re in the middle of interviewing at the moment.