Posts tagged: PROGRAMMING

The "path" module

Somewhat belatedly I’ve started using Jason Orendorff’s path module for Python. It’s great. Here’s a comparison with the stock os.path facilities, grabbed from Jason’s site:

# with os.path.walk
def delete_backups(arg, dirname, names):
    for name in names:
        if name.endswith('~'):
            os.remove(os.path.join(dirname, name))
os.path.walk(os.environ['HOME'], delete_backups, None)

# with path
d = path(os.environ['HOME'])
for f in d.walkfiles('*~'):
    f.remove()

The second snippet is not just shorter, it’s easier to read and easier to write. I’m writing some code to recursively process a tree of short text files (Blosxom entries), and the path module is a godsend. If you’re curious, see the description and examples on Jason’s site; he also posted some interesting comments on Ian Bicking’s blog about the design of the module.

Software for determining image similarity?

This is a lazyweb request – I’m looking for something but I don’t even know if it exists. I have about 200 photos (headshots) and I’d like to make an animation that runs through them in order of, for lack of a better term, visual similarity. I’m not talking about morphing or just fading between the images in arbitrary order. Is there software out there that, given a reference image and a set of images to select from, can choose the most similar image? Open source would be best, as there’s no budget for this, and command-line-only is fine, but I am on a Mac.

Johnny can too code

David Brin, in a piece at Salon.com entitled “Why Johnny Can’t Code”, complains:

almost none of the millions of personal computers in America offers a line-programming language simple enough for kids to pick up fast

Maybe Apple’s marketshare is so small that they equal “almost none,” but all OS X Macs come with Python and Ruby among other options. But wait, Brin seems to have heard of some of these newfangled scripting languages:

A MAC address regex

Today I worked on a form and script used for registering users on a restricted-access wireless network. Here’s a nice compact regex for checking that MAC addresses have been entered in the correct format. (If you’re using this in a double-quoted PHP string, escape the “$” with a backslash.)

/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/i

Bjoern commented on Mon Jun 4 09:09:14 2007:

Hi,

great regex! exactly what I was looking for.

It only does not match lower case also the windows output of ipconfig/all (using a dash as delimiter) is not covered

Rails security hole hullabaloo

Oops So, a serious security hole in Rails was announced this week. There’s a lot of bashing going on about “security through obscurity.” I’ve always understood STO as sustained secrecy about known (or possible) vulnerabilities, which seems different from the Rails team’s provisional waiting period between the initial announcement and the full disclosure. (And the patches themselves told the story, for those familiar with the source.)

Not that there weren’t legitimate problems with their patch release process. They definitely made mistakes they can learn from.