Space Vatican

Ramblings of a curious coder

Stuff That in Your Pipe(line) and Smoke It

I’ve just started learning elixir (reading through the excellent Programming Elixir at the moment) and although it’s still very early days I’m already in love. Pattern matching for example is something I remembered fondly from my days dabbling with ML. As Dave says in the book though, there’s a bit of a leap of faith involved in leaving behind the object oriented world. I’m used to being able to do things like

1 {|key| key.to_s.downcase}.sort.join(';')

Keyword Surprises

I love keyword arguments. No more excuses for methods with too many positional parameters and say goodbye to all the awkward hash wrangling code that was needed when using optional hashes as poor man’s keyword arguments

Ruby 2.0 didn’t allow for mandatory keyword arguments. You could fake it by doing something like

def some_method required: (raise ArgumentError,"you must pass a value for required ")

Introducing Asset_symlink

Rails 4 made asset pipeline precompiling now lightning fast compared to rails 3.x. There were two reasons (that I am aware of) for the slowness in rails 3:

  • it would regenerate all the assets, each time (you can fix this via the turbo-sprockets-rails3 gem).
  • it used to precompile everything twice: once with the digests (the checksums in the filename) and once without.

The precompilation happened twice because your assets can reference other assets (eg a stylesheet with some image or font urls) so the difference between the digest assets and the non digest assets wasn’t just the filename.

Rickrolling With Ruby and Objective-C

In the session I presented at railsclub I finished off by showing how to use FFI to call into Objective-C (If you weren’t there on then my slides are online - I would recommend browsing through the section on FFI). I didn’t go into any detail because it was the end of what I think was a pretty technically intense session.

This definitely comes under the category of “doing something to prove it can be done” rather than anything more serious, but if you’d like to know how it works then read on!

Selectable Items in NSToolbar

NSToolbar has a mode where the toolbar items are selectable - this is commonly used to create preference windows, each item in the toolbar representing a section. If your delegate responds to toolbarSelectableItemIdentifiers: then the toolbar will allow these items to be selected.

You can do all this in IB (along with the rest of the standard NSToolbarDelegate stuff), since IB allows you to mark items as selectable.

The bit that confused me is that unless you also assign an action to the toolbar item (I’ve got mine pointing at a selectSection: method) then nothing will happen when you click the toolbar items, not even a change of selection state. Nowhere does this seem to be documented. I expected that even though I’d hooked up no actions and the toolbar wouldn’t be useful I would at least be able to play with the selection state. Hopefully this helps anyone else wondering why their toolbar isn’t working.