John Pelly's blog



Helps

No helps today

Interesting

  • write_attribute and "type inference": By default, in AR property assignment calls write_attribute which performs some nice type inference that can be very handy. If you override property assignment you have to call this explicitly if you want that behavior. Note that type inference inference is not available for hashed attribute assignment.

    As a motivating example, consider checkboxes. From the form the value is represented as "0" or "1" (String). Assuming you use automatic property assignment, write_attribute is called and it will convert "0" to false and "1" to true. If you override the assignment and don't call write_attribute, or try to use hash-based attribute access, it will view both "0" and "1" as true values; it only considers the empty string or a nil value as false.

  • View paths in RSpec Helper tests: Note that view paths are not present in the load path in RSpec Helper Tests. Therefore, if you're testing a helper that attempts to render a page or a partial, you'll get an exception. There are at least 2 solutions to this.

    1. Mock out your render method
    2. Return the string for the page/partial from the helper and test that value

John PellyJohn Pelly
Thursday 5/7 Standup
edit Posted by John Pelly on Thursday May 07, 2009 at 11:29PM

Help

  • Marshal.dump oddity: Marshal.dump is squirrelly with ActiveRecord objects in Rails. If you dump multiple AR instances that represent the same entity but have different in memory states, the serialization will basically "collapse" those two instances to a single instance. This means you'll lose changes to one of the instances. Anyone out there know why?

Interesting

  • Disabling system pagefile in XP on Parallels: If you disable the Page File in XP it will run super fast in Parallels. This makes sense when you think about it; there are two operating systems on the machine that are trying to manage memory. Both swapping out to disk. Assuming the XP instance has enough RAM (and you're not running that many processes), turn off paging in XP for a big speed boost.

John PellyJohn Pelly
Wednesday 5/6 Standup
edit Posted by John Pelly on Wednesday May 06, 2009 at 06:15PM

Help

  • Can't remove git tag on remote: Anyone know how to ensure that a git tag is removed on the remote repository? We've tried to remove the tag locally, then push to remote. The tag is removed for a while, but at some point in the future it magically comes back.

Interesting

  • Soap4r (courtesy of Adam Milligan): If you're using soap4r in a Rails app, you know that it generates a module based on a WSDL that you feed it, so you can make SOAP calls by calling Ruby methods. Simple and nice, right? Right. Be careful where you require the generated files though. If Rails loads them too soon they won't have the necessary information from the WSDL, and your SOAP calls will fail in subtle and frustrating ways.

    If you require the generated files in the class that uses them, your SOAP calls will work in development mode but fail in any environment with class caching turned on (it may work if you have eager class loading disabled, but why take the chance?). If you require the generated files in an initializer, your SOAP calls will fail in every environment. We made this work by including the generated files at the very end of the environment file. An after_initialize block may work as well.

John PellyJohn Pelly
Tuesday 5/5 standup
edit Posted by John Pelly on Tuesday May 05, 2009 at 08:06PM

Help

No Helps today.

Interesting

Beware of using OpenStruct. It is very slow to create instances. Evidently it defines a new class for every instance created. When you need to create lots of instances of a struct-like object, use Struct.

John PellyJohn Pelly
Monday 5/4 standup
edit Posted by John Pelly on Monday May 04, 2009 at 04:31PM

Help

Feed Validation: There are a couple of options for validating feeds.

  • http://feedvalidator.org: You can enter a URL and view the validation results. Pretty self explanatory. However, we can't figure out how to get it to access resources that are protected with basic auth. If you like, you can download the validator and run it locally at http://feedvalidator.org/docs/howto/install_and_run.html
  • Google Feed Reader API: A great resource is the Google Feed Reader API. Rather than rehash too much here, browse over to Niall Kennedy's post for a great introduction to the API and how to use it.

Firefox shortcuts for bookmarks: In Safari, you can use shortcuts like Apple-1 to load the first bookmark. Is there an equivalent for Firefox?

Interesting

Nothing interesting to report today. Check back tomorrow.