There's enough for everyone

गते गते पारगते पारसंगते बोधि स्वाहा गते गते पारगते पारसंगते बोधि स्वाहा

Puma for raw tcp with ssl

I stumbled on the fact that Puma has a raw tcp mode, also known as Lopez Express. This bypasses rack and provides access to the TCPSocket that’s just connected. Handy, because then puma can handle all the threading etc, and I just get a tcp socket to talk non-http to the client. What!? No http?! Are you mad??

Dataflow concurrency in Ruby

This is the workshop I presented at Rubyfuza 2015. I had some requests to put it online, so here it is. It has exercises so you should be able to work through it.

Please let me know if you find errors.

Nicer YAML Deserialisation

Ruby’s current yaml support is good, but under-documented. Syck (from 1.8.7 and 1.9.2 IIRC) had some easily understood and well-documented features for de/serialising. But Psych … well it works, obviously. But I’ve bashed my head on it a couple of times trying to do the stuff that took 5 minutes with Syck.

Action Module

A little while ago I was ranting about rails controllers, and a bit after that about @ivars in views. More recently I realised you can do class ActionHandler < Module; end and I’ve been wondering what one could usefully do with that.

Miniature Memoize

Just for fun, a small clean memoize in “about a page of code”.

No eval, which is possible because it just uses method objects.

Tries to use closures wherever possible to minimise lookups, partly driven by the functional workshop after rubyfuza 2014.

Quite naive because it just raises for methods with parameters, and will more than likely fail with singletons.

Just uses instance variables, so you can reset them at will.

Definitely works in 2.1, untested in 2.0.

instance_eval with access to outside scope

In Ruby, it’s always been a minor annoyance to me that when you’re working with DSL code, you have to choose between losing access to the surrounding scope (implemented using instance_eval), or prefixing every call with a local variable (implemented using yield self)

Turns out there is a way to get the best of both. Which works well, almost all the time. And ends in two rather unexpected places: one is a really odd error; and the other is CoffeeScript-style function definition/call syntax. Sortof.

FICA requirements for property transactions

If you are asked for FICA documents when you give an estate agent a mandate, it is legal to decline. However, you are legally required to provide FICA documents when the sale is concluded – arguably this would be when you have an offer you’re going to accept.

In fact, this applies to any ‘single transaction’ contemplated in the Act.

DISCLAIMER: I am neither lawyer nor estate agent.

Rails 2.3 With Ruby 2.0

So of course we want to run our rails-2.3.17 apps on ruby-2.0, cos it’s faster and damn the consequences. But there’s a problem with Gem.source_index:

Local gem cache to accelerate bundler

I’ve been finding that bundle install is really slow for me. It downloads the entire specs file from every time I run it. Maybe that’s because I’m using rvm, and it can’t find previously downloaded specs. Or something. I haven’t investigated.

And Gemfile.lock is constantly causing conflicts when I switch between branches. Which is a Right Royal PITA.

After some not insignificant frustration, I realised that I could do something like this in Gemfile. It is after all just ruby code:

Do it yerself, Rube!

I presented this talk at the rubyfuza 2013 conference. /^\ to Marc and everyone else.

The written version of the talk as a PDF. Sorry, you had to be there to get chocolates ;–) Do it yerself, Rube!.

The Cog on youtube. Worthwhile for the soundtrack.

And the code snippets, which I didn’t have time for: