Using find and xargs

In regular linux or unix you can recursively find the files in a subdirectory and apply some utility with arguments on them using xargs as,

find <dir> -type f | xargs <utilitiy> <args>

If the filenames in <dir> have spaces, quotation marks, or other characters in their filenames that make xargs barf, then you can use the following.

find <dir> -type f print0 | xargs -0 <utility> <args>

That should totally work–unless you’re on SunOS, then you have to do,

find <dir> -type f -exec <utility> <args> {} +

It looks crazy, I know, but that’s the honest truth.

Using Optional Values in Swift

Optional Values

Swift has a nil keyword that is sort of like the None keyword in Python; however, regular variables and constants cannot be nil. In order for a variable to be nil, it must be initialized as an optional. (Constants cannot be nil or optional.) An optional is decalred by appending a question mark the variable type. For example, the two statements below are equivalent.

Continue reading Using Optional Values in Swift

Installing Canvas for Node on OSX

I’d like to work with Processing.js, but I had trouble installing the canvas dependency. This should be as easy as,

$ npm install canvas

But there’s a thingy that doesn’t work in Homebrew. I found the answer in this thread on their GitHub. On OSX you have to call this command before you can install canvas:

$ export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig

Then we can install canvas and processing using npm like we’d expect.