Vagrant synced directories

I’ve often been wanting to mount a dir on the host system, when spinning up a vagrant server.

Here is how I did it. First I had to install the vagrant-vbguest plugin. With this one liner

vagrant plugin install vagrant-vbguest

Then I added this to my Vagrantfile

Vagrant.configure("2") do |config|
 config.vm.synced_folder "tmp/", "/opt/tmp", owner: "root", group: "root"

and did a vagrant reload and presto - vagrant mounted the tmp folder inside /opt/tmp

Turn off echo in pry or irb

When you do something in pry or irb that returns a looong result, sometimes you don’t want the result in your terminal. So to turn it off you can do this.

# In irb
irb_context.echo = false

# In pry
_pry_config.print = proc {}

# If you want to restore echo in pry, save the print proc before overwriting it.
pry_print = _pry_config.print
_pry_config.print = proc {}

Asking for help

Be strong enough to stand alone. Smart enough to know when to ask for help, and brave enough to ask for it.

source unknown

Ruby & Rails Date ranges

So I found myself wanting to iterate over a date range in Rails. Naively I started out doing this:

 ( { |d| puts d }
TypeError: can't iterate from ActiveSupport::TimeWithZone

Which of course is wrong, since the expression 5.days.ago is not a date.

Things weren’t entirely obvious. So I broke out irb, and started to experiment.

First off lets try ranges in plain ruby

require 'date'
(,12,8) { |d| puts d }
=> #<Date: 2014-12-08 ((2457000j,0s,0n),+0s,2299161j)>..#<Date: 2014-12-12 ((2457004j,0s,0n),+0s,2299161j)>

So that works pretty good - remember to add the parens, or you’ll be having a hard time.

And in Rails, mixed with the wonders of ActiveSupport::TimeWithZone

( { |d| puts d }
=> Sun, 07 Dec 2014..Fri, 12 Dec 2014

The lesson learned is

Always use the same object in the range, don’t mix apples and bananas

Web Development With Elixir

About a month ago @jamiemhodge talked me into giving a talk about web developement with Elixir for the Copenhagen Ruby Brigade.

So this post contains the recorded talk and links to the code used in the talk.

The source from the talk can be found here:


Language Options Result
Ruby 2.1.1 MRI none 788 req/s
Ruby 2.1.1 MRI puma 10700 req/s
Ruby 2.1.1 MRI puma -q -t 10 -w 4 22356 req/s
Elixir 0.13.2 Weber 23126 req/s
Elixir 0.13.2 Dynamo 31295 req/s
Go   53071 req/s

The talk produced some additional talk on twitter afterwards. @gudmundur made a hello world example in Go.

All tests were performed using

wrk -t 10 -c 400 <url>

Resources for learning more

Thank you to the Copenhagen Ruby Brigade for being an awesome audience.