Justin Richard's blog



Justin RichardJustin Richard
5/15/12 Standup - setting the template in database.yml
edit Posted by Justin Richard on Tuesday May 15, 2012 at 06:04PM

Interesting Things

You may need to specify a template in your rails database.yml to use the rails connection to create a Postgres database via your rake scripts that has your preferred configuration.

Specifically, a team found they needed to specify a template (template: template0) in their database.yml to create UTF8 encoded databases for their project running on Ubuntu 11.04.

Note that your milage may vary here, since the settings on the template database will vary by platform, config and compilation. You might not get the same results using template0, but its interested that you can set it since it wasn't obvious that it was even available.

Justin RichardJustin Richard
Standup 5/14/12 - Watch your SafeBuffer
edit Posted by Justin Richard on Monday May 14, 2012 at 06:03PM

Interesting Things

ActiveSupport::SafeBuffer do not work with all the features of #gsub. Mind your strings, or fix this bug in ruby!

# normal: 
1.9.3-p125 :004 > "foo".gsub(/(?<my_string>.*)/) { $~[:my_string]*2 }
 => "foofoo" 

# broken:
1.9.3-p125 :005 > "foo".html_safe.gsub(/(?<my_string>.*)/) { $~[:my_string]*2 }
 => "" 

# round trip, back to working
1.9.3-p125 :006 > "foo".html_safe.to_str.gsub(/(?<my_string>.*)/) { $~[:my_string]*2 }
 => "foofoo"
</my_string></my_string></my_string>

Justin RichardJustin Richard
Standup 12/8/11
edit Posted by Justin Richard on Thursday December 08, 2011 at 07:11PM

Interesting

The Pivotal Webstache Movember network cleared $40,000 raised to stop Dude Cancer

Joda-Time provides a quality replacement for the Java date and time classes. Months are not zero based!

EC2 is scheduling restarts for their physical machines and your instances. In some cases you can manage your own restart. Make sure you check your email and your EC2 console.

Help

Google Chrome seems to be caching and rendering the last resource served from a URL regardless of its content-type when you navigate via the back button to a page. Specifically, a client's site serves both HTML and JSON from the same URL. The JSON is the last request made because it's an async request on the page. When the user navigates away from this page then back the JSON data is rendered instead of the HTML resource. Any HTTP header change suggestions we can use to get Chrome to only render the HTML content?

Capybara seems to not allow #click on elements depending on how you call #find. What's up with this?

find('tr', :id => 'foo').click  #not clickable
find(:css, 'tr#foo').click      # is clickable

Justin RichardJustin Richard
Standup 12/6/2011
edit Posted by Justin Richard on Tuesday December 06, 2011 at 09:53PM

Interesting

A Ruby Class's default 'initialize' method takes zero or any number or arguments depending on the version of Ruby you use.

Given the Foo class:

class Foo
end

And then attempting to instantiate an instance of Foo with arguments like so:

Foo.new('any argument')

You get an invalid number of arguments error in 1.8.7 and 1.9.3.

However, 1.9.2 and 1.9.1 will just accept any number of arguments.

Ruby spec documents this behavior: https://github.com/rubyspec/rubyspec/blob/master/core/object/new_spec.rb

It appears that this difference between versions was introduced as a feature in 1.9.2 and back ported to 1.9.1 and then reverted in 1.9.3. Perhaps the reversion should be back ported now? http://redmine.ruby-lang.org/issues/2451

Help

Does anyone know of an API that provides a sales tax lookup service?

Justin RichardJustin Richard
Standup 5/3/11 - It's Tuesday All Day
edit Posted by Justin Richard on Tuesday May 03, 2011 at 02:12PM

Interesting

  • Check your instance variable and methods names for conflicts with libraries or frameworks you are using if you get unexpected failures

    Example 1: defining @response in your RSpec test setup when expecting to use the response from a HTTP request overwrites the result of the request. (don't expect @request or @url to do you any favors either)

    Example 2: Don't define a #process method on a Rails controller

  • SF Dev Ops meetup is tonight

Help

"Some of our requests are not timing out in the time specified in our mod_proxy settings in Apache."

This team's problem was later refined to the fact that these timeout settings were not being respected on all requests when the server hit a spike in load. The solution is to recompile Apache with the --with-mpm=worker option. The default option value is --with-mpm=prefork. With Apache compiled with the 'worker' value all requests respect the timeout settings.

"When using Rafael and jQuery together in our project our click handlers throw errors in IE 7 and 8"

After further investigation IE seems to keep propagating the click event even though it was handled. The following javascript was added only in IE browsers to make it behave like the other browsers.

if(document.attachEvent) {
  $(divContainingCanvas).find("*").click(function(event) {
    event.stopPropagation();
  });
}

Interesting

Modulr is a Ruby implementation of a CommonJS module that combines your multiple javascript files into a single file that is executed in dependency order. It does this by ordering the execution of your code by the require() method call. What's interesting is that you can collapse your NodeJS code into a single file to include in a browser and run Jasmine tests against. This is possible because NodeJS uses require() to link your dependent files together.

Justin RichardJustin Richard
Standup 2010.10.4 getting SWFUpload to work with Rails 3
edit Posted by Justin Richard on Monday October 04, 2010 at 02:10PM

Help

"We're trying to use SWFUpload in Rails 3 by using Rack middleware to rewrite the session cookie passed in via request param. In a Rails 2.3.x your Rack middleware could clobber the session cookie and reset it before it hits your main app. However, this isn't happening in Rails 3. Has anybody run into this before?"

The answer is that as of Rails 2.3.4, the session handler was moved to Rack middleware. So you need to make sure that your middleware manipulating the session is running before the Rails session middleware is run. You can do this with something like this:

config.middleware.insert_before(config.session_store, FlashSessionCookieMiddleware)

Brian Racer has a good description of getting SWFUpload working with rails 2.3.4

Justin RichardJustin Richard
Standup 2/5/2010: Jasmine has shared examples
edit Posted by Justin Richard on Friday February 05, 2010 at 12:15PM

Interesting##

If you're using Jasmine to test your JavaScript code and you miss the shared examples functionality you used in RSpec, you can achieve the same result by just using a plain old function. Name your function something like "mySharedBehavior" and call it in each of your describe blocks that share the behavior. Jasmine will execute the function and print your results just as if you repeated all the shared examples in each of your describe blocks. Be careful not to modify the scope of the function that contains your shared examples (Jasmine needs to control the scope).

Help

What remote screen sharing or VNC clients are people using for remote pairing?

Chad described his optimal remote pairing setup in 2008, but since then Apple removed the ability to do true full-screen sharing in the included Screen Sharing application with the 10.5.8 update. We've been looking for other solutions since. Apple's Remote Desktop does this, but it gets expensive on a per seat basis and isn't focused on solving our simple use case.

We're interested in finding out what you're using? Do you have a favorite VNC client?

Interesting

  • Pivotal's Pulse is now open source. It's a nice big view of the state of your multiple CI builds. Check out our public projects here: ci.pivotallabs.com

  • Refraction was updated to v0.2.0. It's a testable replacement for mod_rewrite that's implemented as Rack middle ware.

  • Calling #destroy on an ActiveRecord instance associated through a has_many relationship removes it from the database, but not the collection. #delete removes it from the collection and database, but you don't get the before and after callbacks.

Other articles: