David Stevenson's blog



David StevensonDavid Stevenson
Standup for 2/5/2009: Looking for processes with pgrep & pkill
edit Posted by David Stevenson on Thursday February 05, 2009 at 05:28PM

Interesting Things

  • pgrep is a sweet tool for finding processes. You can find all your mongrels, for example, without having the problems of running ps aux | grep ruby. It's in the proctools package on most linux/unix operating systems. For example, on osx use sudo port install proctools
  • kill -482 kills all processes in the group 482. This is great for killing all the children of a daemon like mysql or backgroundrb. ps shows the process group id next to the process id.
  • monit doesn't have great support for figuring out what happens when a start/stop command runs. It can fail silently, for example. One (bad) way of debugging this is to add echo to dump debugging info to a temporary file before and after these commands. Rumor has it that god doesn't have these problems...
  • we've heard a rumor that Marshal.dump(object) uses a temporary file on disk! This would be slower than it needed to be. Perhaps this is to deal with dumping objects to large to fit in RAM?

David StevensonDavid Stevenson
Standup for 2/3/2009: SOLR & rails fails with IPv6
edit Posted by David Stevenson on Wednesday February 04, 2009 at 05:18PM

Interesting things

  • When we used localhost in our solr.yml configuration, we couldn't run tests on our OSX 10.5.6 machines. Commenting out the IPv6 localhost entries in /etc/hosts fixed the problem. The better solution would probably be to use 127.0.0.1 in SOLR configuration.

David StevensonDavid Stevenson
Standup for 2/3/2009: Enemerable#sum vs ActiveRecord#sum
edit Posted by David Stevenson on Tuesday February 03, 2009 at 05:17PM

Interesting Things

  • When you call user.purchases.sum(), you are invoking ActiveRecord::ClassMethods#sum rather than Enumerable#sum. If you want to invoke Enumerable#sum (which takes a block and is more powerful though less performant), you'd have to call user.purchases.target.sum() {|p| p.price * p.quantity}.
  • NewRelic sometimes makes our app servers malfunction. Several of us reported having these sorts of problems on different projects. It's always fixed by the NewRelic team with a new version or a configuration change, but we wish that we felt safer about our production server stability. Some projects feel that the value is certainly worth it, and Engineyard uses NewRelic data when discussing scaling, so it's worth hanging in there.

Ask for Help

  • What's the deal with using the OSX terminal and bash/readline messing with the terminal? We're always typing some ridiculously long command and bash starts writing over itself. Especially when we use Ctrl+A and Ctrl+R and edit the line. Anyone know how we can stop/fix this once it happeneds?

David StevensonDavid Stevenson
Standup 2/2/2009: Rails 2.3 is gonna be sweet
edit Posted by David Stevenson on Monday February 02, 2009 at 05:18PM

Interesting Things

  • Neat Plugin: Caio Chassot suggested a patch to rails that makes rails template finder traverse the controller inheritance chain when looking for templates. This would make the view system work "correctly" with inheritance, which one of our projects needed. The patch wasn't applied, but the code was released as a plugin called inheritable_templates, which we are now using and enjoying.
  • What's the opposite of {:a => 1, :b => 2}.to_a? It's Hash[:a, 1, :b, 2].
  • Rails 2.3 is going to be awesome! We're most looking forward to
    • Nested model assignment and views
    • Nested transactions, even on MySQL!
    • Default Scopes, no more adding :order => "position" on every acts_as_list model
    • Smarter rendering of partials
    • Rack support
    • Bringing of Engines back. Pivotal is still going to support Desert at this time. Desert is similar to engines, but loads every class that matches in the load path, not just the first one. This allows you to build plugins that extend previous plugins. Using engines, however, we are hoping to make the source code for desert even more trivial.