Conclusion of the QR-on-the-back-of-my-shirt experiment

Fri Aug 03 2012 17:21:00 GMT+0000 (Coordinated Universal Time)

After extensive field testing in the midst of central Stockholm with a QR-code the size of a football on the back of my shirt, I’ve come to the conclusion that Swedes are shy beings who won’t even take a photo of someone (even if nobody is looking) to satisfy their curiosity.

"Fixing" annoying behaviour of the Alt key in Photoshop

Sun Jul 01 2012 22:24:00 GMT+0000 (Coordinated Universal Time)

Something that has been bugging me for a while now is how the Alt key behaves in Photoshop (CS5), or rather the behaviour of the Alt key in Windows programs in general. When you press the Alt key in a Windows program with a menu bar, the menu bar is highlighted for navigation using the arrowkeys or letter shortcuts. This becomes a problem in Photoshop though, where lots of keyboard shortcuts involve just pressing or holding the Alt key.

For example when zooming using Alt+Mousewheel or holding Alt to activate an alternate feature of the current tool you’re using, the menu bar is highlighted. Then when you press another key, either to select another tool or pressing Alt again, either a menu option is chosen or you hear a “beep” and nothing happens.

Earlier versions of Photoshop didn’t have this issue, but for whatever reason CS5 does. To fix this, I threw together an AutoHotkey script that makes it somewhat less annoying:

; Fix alt key behaviour in photoshop
#IfWinActive ahk_class Photoshop
        Send {Alt}

Whenever you release the Alt key inside Photoshop, it will send an another Alt keystroke, which will deselect the menu bar instantly.

Map-reduce with Mongoose, the easy way

Sun Jul 01 2012 22:24:00 GMT+0000 (Coordinated Universal Time)

Update: Since the time of writing, Mongoose now has a proper support for Map-Reduce.

What’s with all the poor documentation of many node modules out there? You could expect widely adapted modules to at least have a function reference, but they keep insisting on only providing “guides” and if you want to know more you have to look at the (often very messy) source code. When it comes to Mongoose, the guide leaves a lot to be desired, but the annotated api docs comes to the rescue.

When I wanted to preform a map-reduce though, neither the guide nor the api docs were of any help. Google gave me a bunch of outdated methods, like calling executeDbCommand on the raw mongodb connection. According to this issue on github opened 6 months ago “its not included in the docs b/c its not really supported yet”. There’s a commit that has added support for mapReduce in response to that issue, but it has yet to be merged with the master branch.

Until then, it turns out, you can just call Model.collection.mapReduce which is a shorthand for the native MongoDB MapReduce command documented here.


For example, this is what I use (with the help from the map, reduce and finalize functions from this gist) to get a random 50 documents out of a collection:

    "function(k,v){var a=[];v.forEach(function(x){a=a.concat(x.a?x.a:x)});return{a:a.sort(function(a,b){return a.v-b.v}).slice(0,50)}}",
        query: query,
        out: { inline: 1 },
        finalize: "function(k,v){return v.a?{return x.k}):[v.k]}",
    function(err, doc) {
My personal portfolio of things I come up with when I'm bored.