Posts

Rails Rumble, Apprenticeship, and a Running Website

Image
Apprenticeship is a big part of Obtiva (the consultancy where I work) so I introduced my friend Leah to Obtiva, they hit it off, and now she's an apprentice in the studio. Now apprenticeship at Obtiva is a paid, billable position. She's pairing everyday on a medium sized Rails business skill development project and learning a lot, but what just blew me away was the development of the "Run. Track. Run." project. Leah is a runner and for years she's been talking about how she'd like to create a decent running website that could import Gamin GPS data and produce useful graphs for runners. Apparently all the sites out there plot every single point of data returned from the GPS device, with little-to-no smoothing, and so the graphs are extremely noisy and hard to read. Wouldn't it be great if an actual marathon runner designed a website for runners? At which point I would usually say: "Yeah, that's a great idea -- we should do that someday....

If you use Mocha and RSpec then read this

I like RSpec, but I'm not a huge fan of it's built in mocking framework. So, when I have the choice, I swap it out for Mocha. However, I really miss mock_model. If you haven't used it, mock_model is an RSpec method where you pass in an ActiveRecord object and it stubs out a whole bunch AR magic so you don't have to. This is crazy useful when testing controllers because when you controller has a line like this: redirect_to(@model) I don't want to dig through a ton of Rails code to figure out what I need to stub on this model, I just want it to work. But I just found out that Mislav Marohnić has written a plugin that implements mock_model for Mocha -- so now I can get the best of both worlds. You can find it here: http://github.com/mislav/rspec-rails-mocha Thanks Mislav.

Naked Hashes are Trouble

So I had this form in a Rails view that needed some changes so, amongst other things, I changed this: form_tag(:action => 'search') to this: form_tag(:action => 'show', :method => :get) I had noticed that the show and search methods essentially did the same thing (and had the same views) -- which I why I refactored. However, when I made the change I got a 500. I was using restful routes and this form needed to be a get -- which I thought I had indicated. But I had not -- what should have put in the view was this: form_tag({:action => 'show'}, {:method => :get}) There's this idiom in Ruby where we don't put curly braces around hashes if we don't need to, but I've consistently lost a bunch of time to mistakes like the one above. So I'm thinking about explicitly denoting hashes with curly braces in my future Ruby code just to improve intentionality.

Photos from Ruby Conf 2008

Image
The Omni Resort was beautiful -- this was our view during lunch: I liked the Hotel but everything was very expensive. Breakfast buffet? 20 bucks. Awesome (really good bacon) but still 20 bucks. Dinner? 40-50 bucks. Cab ride there from the airport? 80 bucks. There was a tanning bed convention being held right next door. They got a security guard in front of their door while we did not. The next 2 pics are of the lazy river. I did a couple of laps (assisted by the current) and it was very nice. A fountain and one of the many pools. During the Matz Q&A my friend and fellow Obtivan Andy Maleh got up and asked some questions.

Ruby Conf 2008 Last Day

A wonderful, awful idea: ruby in the browser (and oh by the way it actually works!) by Christopher Nelson Chris thinks that while Javascript is an excellent programming language, he likes choices so why not provide people with the option to run Ruby in the browser? Also, while programming rich web apps he found that oftentimes he ended up with business objects in Javascript and in duplicate objects in Ruby. Not very DRY. He wanted to be able to use his Ruby logic server-side and in the browser. Two ideas that didn't work out: JRuby - the java security manager stopped him from doing just about anything Silverlight wasn't available for his operating system when he started the project Rubyjs is what he ended up using. Rubyjs is a ruby compiler that uses ParseTree to produce javascript. http://github.com/superchris/rubyjs The translation is, of course, not without some changes: Strings become Immutable strings Procs become Functions Hashes becomes custom hash object Chris then...

Ruby Conf 2008 Second Afternoon/Evening

What Every Rubyist Should Know About Threads by Jim Weirich Concurrency is becoming bigger as computers get more cores. If you look at a graph of clock speed they flattened out in 2003. Past performance gains: clock speed (not so much anymore) execution optimize cache results So if clock speed is not going up at a rapid pace anymore, now what?: hyperthreading multicore (the new saviour) caching Applications will need to be concurrent to exploit multicore machines. 100 CPU machines are on the horizon. Race conditions are trouble: If thread one has this: shared_variable += 1 And thread two wants to do the same thing: shared_variable += 1 What if the first thread looks up the shared_variable and find that it's 25 but before it can change it the second thread reads the value (still 25 because it hasn't changed). Now the first thread will add one (shared_variable becomes 26) and write the result back to memory, then the second thread will add one to the...

Ruby Conf 2008 Second Morning

Aristotle and the art of software development by Jonathan Dahl How do you identify a good programmer? Jon says Ethics. Ethics is about how you live your entire life. He thinks the what makes a good software developer and what makes a good person have parallels in their answers. Kant -- Only act on principles that you would like to become universal law. Kant would have loved Haskel. There are principles in software, but sometimes they conflict such as DRY vs write understandable code. DRYing something up can make it hard to read. John Stuart Mill Utilitarianism -- what matters is the effect of the action. The ends justify the means. However, It's hard to know whether the effects will be good ahead of time. The Pragmatic Programmer is a good outcome of Utilitarianism. But Utilitarianism may lead to sloppy code and processes. Or the Cowboy coder. Aristotle - ethics as virtue. The person is the important part. For Aristotle: ethics == a life well lived == happiness == virt...