Nate Clark's blog



Nate ClarkNate Clark
Standup 9/17/2009: silly Ruby tricks, unstub!, iPivotal => PTCruiser
edit Posted by Nate Clark on Thursday September 17, 2009 at 09:40AM

Interesting Things

  • silly Ruby trick of the day -- does anyone know what this does?
while gets
  print if /foo/
end

This is an example from the Ruby "Pickaxe" book. No respected Rubyist actually writes such difficult-to-understand and obfuscated code. Though, it was mentioned, that terse syntax like this is useful for command-line hacking.

  • unstub! is a useful Rspec method that removes a stub from a previously stubbed object. This can be useful if you have stubbed, then mocked the same method, and you want to remove the stub.

  • The unofficial community-developed iPhone app for Pivotal Tracker, is changing its name from iPivotal to PTCruiser. See the author's Twitter for more.

Interesting Things

  • One team had trouble deploying via capistrano to Engineyard's Solo environment because SSH keys weren't being sent correctly. Setting ssh_options[:forward_agent] = false in their Capistrano config fixed the problem.

  • After upgrading to Rails 2.3, Rails started sending two content-types down with each page's headers, text/html, application/json. This was causing Selenium tests to choke.

  • If you scp a file to /etc/cron.d, cron will not notice the new file until you touch it.

Nate ClarkNate Clark
Standup 9/15/2009: Hashing a String, Nginx Security Patch
edit Posted by Nate Clark on Tuesday September 15, 2009 at 09:13AM

Interesting Things

  • String#hash does not always produce the same hash on different machines and/or different architectures. Don't use the hash of a string across machines to identify it.

  • Nginx has released a security patch to fix a remote execution security vulnerability.

Ask For Help

"Anybody use an off-the-shelf State Machine plugin for Rails? Which one?"

Our team recommends using the rubyist-aasm gem from Github. It works well for our current applications, and it appears to be the most actively developed and frequently updated. This gem is the successor to the acts_as_state_machine plugin.

Interesting Things

Don't use comments in ERB. Writing comments (or any '#' character, for that matter) inside an ERB evaluation block was never right, but some versions of Ruby 1.8.6 allowed it anyway. This is trouble if you upgrade to Ruby 1.8.7 (for example, when upgrading to Snow Leopard) which does not allow comments within ERB.

This is wrong:

<%= link_to "/", home_path #link to the homepage %>

If you really need comments in ERB, do it this way:

<%# link to the homepage %>  
<%= link_to "/", home_path %>

test-unit 2.0.3 breaks RSpec. If you upgrade to test-unit 2.0.3, you may notice that your RSpec specs no longer run. Roll back to test-unit < 2.0 (or remove the test-unit gem completely) and you should be back in business.

RubyMine 1.5 early release is available for trying out. Preliminary reports from one Pivot are positive. If you are using Snow Leopard, which ships with Java 1.6, you'll need to do this hack to get it to run