DRY: Do Repeat Yourself

This is a repost promoting content originally published elsewhere. See more things Dan's reposted.

I am increasingly of the opinion that the general software engineering adage “Don’t Repeat Yourself” does not always apply to web development. Also, I found that web development classes in CS academia are not very realistic. These two problems turn out to have the same root cause: a lack of appreciation of what browsers do…

recruit.ox.ac.uk Permalink Generator

If you’ve ever applied for a job with my employer, the University of Oxford, you’ll have come across recruit.ox.ac.uk, one of the most-frustrating websites in the world. Of its many problems, the biggest (in my mind) is that it makes it really hard to share or save the web address of a particular job listing. That’s because instead of using individual web addresses to correspond to individual jobs, like any sanely-designed system would, it uses Javascript hackery and black magic to undermine the way your web browser was designed to work (which is why, you’ll find, you can’t “open in new tab” properly either), and instead provides its own, inferior, interface.

Some day I might get around to writing e.g. a userscript and/or browser plugin that “fixes” the site – from a user’s perspective, at least. But for the time being, because this morning I needed to share via social media a link to a UX developer post we’ve just advertised, I’ve come up with a little bookmarklet to fix this single problem:

recruit.ox.ac.uk Permalink Generator

Drag the bookmarklet to your bookmarks toolbar, then - when on the recruit.ox.ac.uk site - click it to use it.

This tool makes it easy to get permalinks (web addresses you can save or share) for job listings on recruit.ox.ac.uk. It might be adaptable to make it work with other CoreHR-powered systems, if it turns out that this missing feature comes from the underlying software that powers the site: it could also form the basis of a future userscript that would automatically fix the site “on the fly”. Here’s how to use it:

  1. Drag the link below into your browser’s bookmarks (e.g. the bookmarks toolbar).

    recruit.ox.ac.uk permalink

  2. When you’re on a recruit.ox.ac.uk job page, click on the bookmark. A permalink will appear at the top of the page, for your convenience. If you’re using a modern browser, the permalink will also appear in the address bar.
  3. Copy the permalink and use it wherever you need it, e.g. to share the link to a job listing.

If you have any difficulty with it or want help adapting it for use with other CoreHR systems, give me a shout.

jQuery Is Awesome. Yet Again.

I know that this probably isn’t news to any of you who care about such things and follow the world of web development even a little… it’s not even news to me, really – I’ve been an advocate of this particular programming library for a while now. But today in particular, I just felt so enamoured by the elegance of the jQuery Javascript Framework that I had to tell you about it.

This line of code:

$('.alpha').not(':has(.beta:visible)').hide();

Hides all elements with the class “alpha” which contain no visible elements with the class “beta” (i.e. if it contains any visible elements of class “beta”, the “alpha” is not hidden).

And it’s just beautiful. Just to compare how elegant it is to something else, here’s the equivalent code in Prototype, another popular Javascript framework, which in itself still shortens the amount of code that this would take in plain-old vanilla Javascript:

$$('.alpha').each(function(element){
var has_visible_beta = false;

element.childElements().each(function(inner_element){
if (
inner_element.hasClassName('beta') && inner_element.visible()) has_visible_beta = true;
});
if (
has_visible_beta) element.hide();
});

(okay, that Prototype code could probably be a hair simpler, but you get my point)

Wow.

The Most Terrifying Thing A Web Developer Will Ever See

Want to see something quite terrifying: DHTML Lemmings. I kid you not – this is scary shit, particularly when you realise that it’s all being done client-side, using script, over the web: no Flash, no Applets, no ActiveX <spits> – just pure unadulterated CSS and JavaScript. I got scared.

Royal Welsh Show

I’m writing this from the (badly-protected: just had to go to a page with a particularly funky JavaScript to break out of their front-end browser) BBC Wales bus at the Royal Welsh Show, where Alex and I are working on behalf of SmartData.

Suppose I’d better get back to work and let these kiddies have the ‘net connection back…