Pivotal Labs

Standup 03/30/2007

edit Posted by Joe Moore on Friday March 30, 2007 at 05:57AM

Interesting Things

  • Rspec vs. Rails' Test::Unit Gotcha: In a Controller test, Rspec provides access to that Controller's attributes with assigns[:attr_name], or "array notation", but Test::Unit does not. Both support assigns(:attr_name), or "method-call notation."

Ask for Help

  • "How should we migrate/upgrade database when we add new versions of assets, such as photos?" The consensus is that, for now, we'll do it lazily: if an application (using our asset management plugin) needs a new version to be stored (perhaps we need a 'tiny' version...) when we will create them on-the-fly when requested rather than generate thousands of photos in one shot. If that has performance implications we'll revisit that decision.
  • Anyone want to be RailsConf roomies? Our sizable RailsConf contingent is going to try to share hotel rooms and such.
  • We're out of beer! A posse of those whom have been late to standup will make a run later today

Total Stand-up Meeting Time: 13:00 minutes

Standup 03/29/2007

edit Posted by Joe Moore on Thursday March 29, 2007 at 02:14AM

Interesting Things

  • Rails Gotcha: If you name a Rails Migration class the same name as an ActiveRecord class, you will get a non-obvious "superclass mismatch" error.
  • Javascript: Date.now() is not supported by Internet Explorer! Firefox is fine. If you use Date.now(), the cryptic and maddening "Object does not support this property or method" will be your reward. Cross-browser solution: new Date().getTime().
  • Brown Bag Lunch today: Rails performance testing.

Ask for Help

  • "Any JQuery experts in the house?" Unfortunately not, since most of us have used the Rails-favored Prototype libraries.
  • If anyone has unbiased hosting service recommendations we would love to hear them. We've used several companies with mixed results.
  • Rspec: "Does Rspec support all of the various route testing helpers that Rails' Test::Unit extensions has?". We think the answer is "yes" because Rspec extends Test::Unit, but we'll have to research that one.

Total Stand-up Meeting Time: 15:00 minutes

The Joy Of Deleting Code

edit Posted by Alex Chaffee on Wednesday March 28, 2007 at 09:03PM

dog

Mark and I were just waxing poetic about how great it is to delete code, especially code you just wrote. We pity the attitude of people who think deleting code is somehow wrong -- they feel so guilty that they won't even delete it right off, they just comment it out, and then check it in... We came up with the following simile:

Writing code is circling your way around a solution, like a dog on the hunt. When you're done, the final solution is going to be a lot smaller than your original perimeter.

This reminds me (Alex) of my favorite quote about writing: "Murder your darlings," said by Sir Arthur Quiller-Couch... or was it..?

Standup 03/28/2007

edit Posted by Joe Moore on Wednesday March 28, 2007 at 04:04PM

Interesting Things

  • One pair had this reinforced: you should not generate random data in your test case to be the subject of your assertions. In their case they were generating random usernames to test an "allowed characters" filter, but their tests would intermittently succeed or fail because the test was not deterministic.
  • "A private declaration in a Helper doesn't do jack crap!" Truer words were never spoken: private and protected declarations are not enforced in Rails View Helpers due to how that code is injected into View instances.
  • A developer suggested that we attempt to do "RESTful CSS." An explanation and debate is due soon.
  • We are officially changing Wiki technologies from Twiki to Trac.
  • Rails Gotcha: You can use Named routes to generate a URL for a link with my_named_route_url, but watch out: that URL is fully qualified! If you want a relative "URL", use my_named_route_path. Example:
<code>
# config/routes.rb

login "/login", :controller => "user_management", :action => "login"
</code>

And in a any RHTML template:

<code>
login_url    # generates http://example.com/login

login_path   # generates /login
</code>
  • People need to take more time to... blog! We have a laundry list of topics but no free time.

Total Stand-up Meeting Time: 17:00 minutes

Standup 03/27/2007

edit Posted by Joe Moore on Tuesday March 27, 2007 at 04:04PM

Interesting Things

  • Rails Observers: Observers need to be "primed" before they start working. Call Observer.instance before you start testing your Observers.
  • Cookies in Rspec and Test::Unit: Cookie keys are not symbols, unlike many collection-like constructs in Rails; they are instead always Strings. Thus, use "cookie_name" not :cookie_name
  • Rails reminder: ActiveRecord::create returns the stored object if successful, and the unsaved and invalid object in memory if the object could not be saved. If you want to know whether or not your save was successful, use ActiveRecord::save, which returns true when successful and false otherwise.
  • And on a further note, a larger discussion should be had regarding when to use ActiveRecord::create, ActiveRecord::save, ActiveRecord::new, and ActiveRecord.dependent_object.build the latter of which is created when you have a has_many relationship with another ActiveRecord.

Total Stand-up Meeting Time: 20:00 minutes

Standup 03/26/2007

edit Posted by Joe Moore on Monday March 26, 2007 at 04:19PM

Interesting Things

  • Running initialization blocks per environment
    • Set an array in environment.rb to capture your procs that will do your post-initialization: POST_LOAD_BLOCKS = []
    • Now, in your environment-specific initialization files, you can do stuff like:
    • Then, back in environment.rb, after your environment has been initialized, loop over your array:
<code>
POST_LOAD_BLOCKS << Proc.new {
  a.runFoo
  b.runBar
}
</code>

Paydirt! These procs you're appending to the POST_LOAD_BLOCKS array will get executed after your environment is completely initialized.

  • Use silence_warnings to (you guessed it!) 'silence' warnings in Ruby - only pros should use it, and only when its clear exactly what you are doing!

Ask for Help

  • None need today

Total Stand-up Meeting Time: ?

Ruby Puzzler

edit Posted by Alex Chaffee on Saturday March 24, 2007 at 05:58PM

puzzler I was just sitting around my living room listening to NPR, and heard the following Car Talk puzzler:

I want you to get a pencil and write down the numbers, 1 - 9, inclusive, and leave enough space between them. At your disposal you have one plus sign and two minus signs. You can insert those plus and minus signs wherever you want, to make the total come out to 100.

Naturally, I thought, "Gee, that would be tedious to solve it by hand. But it would be fun to write a Ruby program to solve it!" 9 minutes later I was sending the result (and the source code) to Car Talk Plaza.

So here's your challenge: can you write a program to solve this puzzle? And can you beat my time?

My solution is below the fold... don't click "more" until you've taken a stab at it yourself.

The best thing I've heard all day

edit Posted by Joe Moore on Friday March 23, 2007 at 12:32AM

"This is either the stupidest or best idea I've ever heard"

Standup 03/22/2007

edit Posted by Joe Moore on Thursday March 22, 2007 at 09:02PM

Just internal project-specific updates today!

Standup 03/21/2007

edit Posted by Joe Moore on Wednesday March 21, 2007 at 01:46PM

Interesting Things

  • We've forked several 3rd party plugins (yes, we need to send patches) and we're using the "3rd Party Branch Pattern" from Software Configuration Management Patterns. We'll keep you posted as to how it's working.
  • rake db:fixtures:load does not turn off database foreign key constraints, so be careful. We'll see if we can either fix this for our needs or make it configurable.
  • CSS: We've found a technique claiming that overflow:hidden can dispose of the un-hip <div style="clear:both;"></div> float-clearing div. This seems to have multiple side effects, including undesirable scroll bar behavior, so be very careful if you do this.
  • In FireFox for Mac, you will encounter problems if you are trying to hide a Flash components using an opaque div. There is a workaround involving a .png background image which has the desired alpha-transparency... a more detailed post will (hopefully) come in a follow-up post.
  • Even More CSS: though some suggest it's dangerous, setting an element to position:relative often saves the day if you have having layout problems.

Ask for Help

  • One of our new projects is using the Darcs source code management system... has anyone used it?
    • We have a few who've read about it, but not used it... looks like we'll have to RTFM.
  • If anyone has experience getting rake tasks to work on both *NIX and Windows, talk to AC.
  • Here's a good sign: we're out of chairs!

Total Stand-up Meeting Time: 24:00 minutes

Other articles: