Robert Nubel

a software developer with too much time on his hands

Read this first

Ruby’s Timeout

If you think you’ve been around the block a few times and know your ins-and-outs of Ruby’s funkiest details, here’s a quick Ruby quiz for you: on MRI, what does this piece of code print out?

require 'timeout'

def do_stuff
  sleep(2)
  puts "done sleeping"
rescue => e
  puts 'boom!'
ensure
  puts 'all done'
end

begin
  Timeout::timeout(1) do
    do_stuff
  end
rescue Timeout::Error
  puts 'timed out'
end

If you answered timed out, that’s not a bad start. After all, the timeout method is what raises the error, right? Or… no, actually. Ruby’s timeout method actually works by kicking off a new thread, which sleeps for the timeout duration and then raises an exception on the original execution thread, at whatever point in the code it happens to be at. The stack trace will read as if it came from a random line in your code (which can be surprising to the uninitiated).

Okay, so it prints...

Continue reading →


The Case of the Missing Commits (or, The Dangers of Git Forced Updates)

It was a cold Wednesday afternoon when I got the email. Another developer’s mundane bug fixes deployed to production. Nothing special. But an alarmed business owner’s reply caught my eye: “Did this release overwrite our updates to the homepage? The old homepage is now showing up. Please advise.”

Curious, but I had other things to distract me. Until a panicked developer dropped by my desk with a bombshell: not only were the homepage updates gone, but the commits that made them were entirely missing from the commit history! Where did they go? How could we restore them? And how could we tell which other commits had gone missing?

Interlude: Git refresher

Git, our version control system, models commit history as a tree. When you make a new a commit, it becomes the new tip of the tree; if you merge two branches, you create a new commit that joins the two. Each branch and tag has it’s own...

Continue reading →