Carl Jackson's blog



Carl JacksonCarl Jackson
Standup 3.25.2011:
edit Posted by Carl Jackson on Friday March 25, 2011 at 01:20PM

Help

  • fonts.com is giving 404s, it appears their CDN is down
  • How do you style a File Input? There are several jQuery plugins that do this, one that worked well (and includes drag & drop support) is jQuery-File-Upload
  • Selenium + Webrat, oh my: If you try adding selenium tests to an existing test suite you may find that your test database data gets blown away. A good solution to this is to separate your selenium tests into another test suite and run them separately

Interesting

  • assert_template is just doing a regex, which means that it may incorrectly be passing if you are asserting on a string that is a substring of the actual template name you expect

Carl JacksonCarl Jackson
Standup 3.23.2011: update your rvm, bundler 1.0.10 fix, autofocus in WebKit
edit Posted by Carl Jackson on Wednesday March 23, 2011 at 10:20AM

Interesting things

require 'yaml'
YAML::ENGINE.yamler= 'syck'
  • autofocus attribute + hover css rule in WebKit may not play nicely with each other

Carl JacksonCarl Jackson
Standup 3.21.2011: Deactivating users in devise
edit Posted by Carl Jackson on Monday March 21, 2011 at 09:19AM

Interesting Things

All strategies that inherit from Devise::Strategies::Authenticatable (which may be all right now) check for user.active?. To deactivate a user, just add an active column to User model, and a message to present with inactive_message:

# User model

def active?
  !!active
end

def inactive_message
  "Sorry, this account has been deactivated."
end

and to test:

# Any session controller spec

it "should throw an error with an inactive user" do
  user = Factory.create(:user, :password => "password")
  user.active = false
  user.save!

  error = catch(:warden) do
    post :create, :user => {:username => user.username, :password => "password"}
  end

  error[:message].should =~ /deactivated/
end

Ask for Help

"How do I get the cursor to appear in Firefox after resizing a textarea?"

After resizing a <textarea> using jQuery with an animation, you can type in the <textarea> but the cursor is gone.

Ideas to try include resizing the <textarea> without animation, and try triggering a blur or focus event.

"Is anyone using underscore.js to add enumerable support with jQuery?"

Nobody here has tried it officially yet, looks promising.

Interesting Things

  • <iframe> and Safari

Seeing this in Safari only which has a more strict default setting to handle same origin policy. If you load a page from your own site with an <iframe> with a page from another site, that other site is not able to set cookies, and is is a problem on one project trying to use Facebook connect in an <iframe>. The solution was to redirect the entire page to Facebook connect, and then redirect back, which is not an ideal user experience.

Ask for Help

"How do I create a model without a backing store?"

One way to do this is to use the active-form plugin (or here), which lets you create model objects that support ActiveRecord Validations but are not backed by database table. Not to be confused with the other ActiveForm, which is a DSL for defining XHTML forms with validation.

TODO

"How do I turn an association into an array?"

You can access the underlying array by using .target or .proxy_target. If you want to cause the association to load all it's data pass any parameter, for example

blog = Blog.find(:first)
posts = blog.posts(:force_load)

Interesting Things

  • AWS gems log spew and SSL

Noticed that when using the RightScale Amazon Web Services gem that a lot of log output is going to STDOUT. To capture this output specify a logger wherever you create your AWS service object, for example:

development:

RightAws::S3.new(access_key, secret_key, :logger => Logger.new(File.join(File.dirname(__FILE__), '..', '..', 'aws_sqs.log'), 'daily'))

demo/production:

RightAws::S3.new(access_key, secret_key, :logger => Logger.new(File.join(File.dirname(__FILE__), '..', '..', 'aws_sqs.log'), 'monthly'))

To prevent even more warnings from appearing in your log output you can also set the @http.verify_mode as follows:

original:

      @http.use_ssl = true
      ca_file = get_param(:ca_file)
      if ca_file
        @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
        @http.verify_callback = verifyCallbackProc
        @http.ca_file = ca_file
      end

patched:

      @http.use_ssl = true
      ca_file = get_param(:ca_file)
      if ca_file
        @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
        @http.verify_callback = verifyCallbackProc
        @http.ca_file = ca_file
      else
        @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end

Ask for Help

'How do I get growl output using ruby-growl in irb?'

Seen at a RubyConf lightning talk, ruby-growl (aka "g") is a library that provides a global "g" method that you can use to inspect objects much like Kernel#p. Instead of printing the output to console the output goes to Growl, a popular OS X global notifications tool.

require 'ruby-growl'

g = Growl.new "localhost", "ruby-growl",
              ["ruby-growl Notification"]
g.notify "ruby-growl Notification", "It Came From Ruby-Growl",
         "Greetings!"

Trying this out we are seeing the following error message:

Errno::ECONNREFUSED: Connection refused - send(2)

Tried these instructions to enable incoming notifications but still doesn't work. Anyone?

'Keycastr' not working

KeyCastr is a Mac OS X application that displays your keystrokes in a small floating window much like growl - useful for overhead projection, and we use it around here for everyday pair programming to answer the question "What key did you just press?"

If you are having troubles getting this to work, try enabling the checkbox in System Preferences -> Universal Access in the "Seeing" tab called "Enable access for assistive devices"

Enable access for assistive devices

Interesting Things

Tweet from Chad Fowler

When you are doing development in JavaScript using js shell and you try to inspect an object, all you can see is [object Object]

js> x = {foo: 'bar', baz: 1}
[object Object]

A convenient if obscure way to see more detail is uneval()

js> x = {foo: 'bar', baz: 1}
js> uneval(x)
({foo:"bar", baz:1})