24 August 2010

Measure twice, cut once

A simple, brilliant idea: README Driven Development.

...you're giving yourself a chance to think through the project without the overhead of having to change code every time you change your mind about how something should be organized or what should be included in the Public API.

(Link via The Code Project.)

19 August 2010

Post-modern obsolescence

I don't know whether to be tickled or appalled: USB Typewriter.

(Link via IEEE Spectrum's iCandy.)

Empirical observation

Gorsline's Corollary to Osborn's Law ("Variables won't; constants aren't."): Temp directories aren't.

17 August 2010

Small victories

This is a puzzle I had failed to solve a few weeks ago; I finally figured out how to do it. Given a modal that you've opened with jQuery's dialog(), and given that it has some buttons (like "Save" and "Cancel") that you've added as options, how can you programmatically disable or hide a button? dialog() doesn't give the buttons IDs or distinguishing classes. And you don't want to look at everything in the DOM, just the row of buttons on your modal.

I already have as part of our framework the DOM ID of the <div> that makes up the body of the modal: it's in a variable called overlay.context. The trick is to walk up two levels of the DOM to the common ancestor of the body and the buttons. So, to hide the button with a label of "Cancel":

var grandParent = $(overlay.context).parent().parent();
$(":button:contains('Cancel')", grandParent).hide();

02 August 2010

Primality test

kottke.org pointed out this egregious abuse of regular expressions some time ago, but the page he referenced never made it into my post, and I can't find Kottke's post in his archives. In the course of trying to track down the page, I found several variations and amplifications of /^(11+)\1+$/ as a regular expression to find prime numbers in Perl, Python, or what have you.

See posts from Brontosaurus, Peteris Krumins, Neil Kandalgaonkar, Avinash Meetoo, and this Stack Overflow thread. There is a Perl one-liner by Abigail (last name?) from a 1997 Perl Journal that perhaps takes historical priority.