“You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.”
Friedrich Nietzsche
San Fran apple store

San Fran apple store

It’s sad that this nitwit trumps Steve Job’s death in the headlines

It’s sad that this nitwit trumps Steve Job’s death in the headlines

Awaodori 2011

Awaodori 2011

Deep property access in JavaScript

Have you ever found yourself repeatedly writing code like this?:

if (myObj && myObj.myProperty && myObj.myProperty.foo) {
   doStuff(myObj.myProperty.foo);
}

That’s obviously because you would get reference errors if the sub-properties of your object don’t exist. I came across this too many times so I’ve written a helper function to get around this. You could do the same as above with this syntax:

doStuff(sprop(myObj, ‘myProperty.foo’));

EDIT: 

After some benchmarking it turns out that this approach is significantly slower than using the typical multiple-if-statements approach. Also an iterating proves slightly faster than recursion. string.split() also adds a lot of overhead. Please use with caution and avoid usage in heavily executed code.

I updated the gist with the new code.

How to copy/paste in OSX from VIM

Surprisingly the system clipboard still doesn’t work in OSX when using standard VIM from a terminal. Here’s the workaround a found.

To copy the current line into the system clipboard from within VIM, type this:

.!pbcopy

To paste:

.!pbpaste

iPad update. 600MB. 4hours. Lame!

iPad update. 600MB. 4hours. Lame!

“The mind is sharper and keener in seclusion and uninterrupted solitude. No big laboratory is needed in which to think. Originality thrives in seclusion free of outside influences beating upon us to cripple the creative mind. Be alone, that is the secret of invention; be alone, that is when ideas are born.”
“It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures.”
Alan J. Perlis

(Source: clojure.org)