GFX::Monk Home

- page 21

I'm so metal, I hardlink *directories*

OSX only (Leopard and above). Apparently Apple added this for time machine’s use, but didn’t expose it in the ln tool.

Yes, this means you can shoot yourself (and your computer) in the foot (and, err, power supply). However, it has its uses as long as you take care.

Right now I’m using it to serve up content in my web sever that lives outside ~/Sites (because the content is a subfolder in a git repo, and I don’t want to have to keep mirroring it). This can’t be done with symlinks or aliases, as far as I could tell…

(view link)

Lego hacking minions

What do you do when you need to try thousands of different memory injection exploits on a device, where each attempt requires multiple physical button presses? With friggin robots, of course.

Robots made of lego, no less. Sweeet.

Recursively Default Dictionaries

Today I was asked if I knew how to make a recursively default dictionary (although not in so many words). What that means is that it’s a dictionary (or hash) which is defaulted to an empty version of itself for every item access. That way, you can throw data into a multi-dimensional dictionary without regard for whether keys already exist, like so:

h["a"]["b"]["c"] = 5

Without having to first initialise h[“a”] and h[“a”][“b”].

A dictionary with a default value of an empty hash sprang to mind, but after trying it out I realised that this only works for one level. Recursion was evidently required.

So, here’s the python solution:

from collections import defaultdict
new_dict = lambda: defaultdict(new_dict)
h = defaultdict(new_dict)

And the ruby, which seems overly noisy:

new_hash = lambda { |hash, key| hash[key] = Hash.new &new_hash }
h = Hash.new(&new_hash)

Understanding git submodules

I had to refer to this today, when I discovered (much to my surprise) that git submodules update does, for the most part, nothing.

You might expect it to update all my git submodules to the latest revision. Nope, I’m supposed to cd into each of those directories myself and run git pull myself.

The only hint that git update will do nothing of use is a single sentence in the help page, which mentions as part of the update command’s summary: “This will make the submodules HEAD be detached”. Which is a fairly unintelligible statement, even to someone who’s been using git for about a year now.

I can’t imagine when you would run git submodule update after the initial checkout - why doesn’t git submodule init just do update’s job (actually fetching the initial content), and then maybe we could have an update that actually pulls updates? I’d even be satisfied to have to use a flag, like --hard, --please or --come-on-old-chap-just-do-it-would-you

I’m pretty new to git’s submodules, and so far they just seem to take far too many manual steps (I don’t understand why they’re not fetched by a clone, for starters). I feel wrong saying so, but I miss svn:externals.

Tell me, how are things in the land of the other DVCS’s?


Update: Looks like my git is outdated, the newest version (1.6) allows a --merge or --rebase flag to update which sounds like it does what I want. Now I just need to sort out my mac’s package management :s

(view link)

Windows: easy and reliable

A vulnerability Visual Studio relating to ActiveX components (exploitable via Internet Explorer).

Microsoft warns that exploiting it is “easy and reliable”. Ahh Microsoft - making the tough things easy again ;)

(via Matt, in turn via Security now)

(view link)

A thought or two about application launch window focus models

Note that here I’m talking about windows getting focus when they launch, rather than focus-follows-mouse or window click-through (I’ll leave that one to Gruber).

Recently, I’ve learnt something about how window focus works on OSX, and subsequently been fairly disappointed by how it works in X (and probably Windows, but correct me if I’m wrong).