Carl Jackson's blog
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"

Interesting Things

- Using uneval in SpiderMonkey JavaScript shell
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})
