Regex Result Access Benchmark
The question came on forrst.com about which of the following two styles of accessing the results of a regex match were preferred: "qqq100601.txt"[/\A([a-z]+)/, 1] "qqq100601.txt".match(/\A([a-z]+)/)[0] So I benchmarked it and was surprised that there was such a difference in the performance. Except on jruby, the array style access is the clear winner. Benchmark and Raw [...]
Speeding up the Haversine Formula in Ruby
A friend of mine’s work deals a lot with geographical data. He was working on clustering large sets of coordinates into .25 mile groups and sent me over a small sampling to play with. By small, I mean a 8,736 coordinates. His real data set is much, much larger. He had started off by utilizing [...]
The Danger of the Silent Fail
I came across a bug in an rails app I wrote today. This thing was driving me crazy. I was generating a random 10 digit number for my model, however about one-third of the time in production the number was getting set to the same thing, 2147483647. I wrote some specs but couldn’t reproduce the [...]
Sometimes programming problems are best solved AFK
This afternoon I ran into a problem. I was working on adding in some new form fields on an edit screen. The fields were for an associated model. I was using fields_for in the view and accepts_nested_attributes_for in the model. Everything looked great, but my specs were still failing. The form just wasn’t updating the [...]
You Failed. Autotest with a voice.
While listening to a talk from Ruby Conf 08, I heard Joe Martinez mention the say command in OS X. I figured I’d pop open my .autotest file and wire it up so it’d give me some motivation for when my specs go red. Here is what I added: Autotest.add_hook :red do |autotest| `say -v [...]
