JRubyConf: The Best Conference Ever?

This past week, I had the pleasure of attending JRubyConf in Washington, DC on the campus of Gallaudet University. It is possible that this was best conference I’ve ever attended.

What’s so good about it?

  • The talks – they were almost all great, especially the keynotes. Normally I skip a talk or two to hang out in the hallway or just to take a break, but not this time. The talks were recorded – I recommend watching them whenever they get published.
  • The people – it was great to talk to so many smart, enthusiastic folks. It gives me great hope for the future of JRuby.
  • The food – the conference fed us breakfast & lunch both days, and dinner the first day. The food was top notch – no bag lunches or ‘continental’ breakfasts.
  • The wifi – since the conference was on a university campus, the wifi was excellent. Coming home to my slow DSL was painful :)
  • the whisky – the organizers brought in @whiskycraig from Scotland to run a whisky tasting. It was almost three hours of whisky history, along with five whiskies to taste. I’ve never had whisky, and just assumed they were all kind of the same. It was interesting to see the large variety in flavor across different brands, and the history of whisky was fascinating.

Thanks

I’d like to thank Joe O'Brien and the other folks at EdgeCase for knowing how to put on a conference – I’m already looking forward to the next JRubyConf!

Freedom from Wordpress

Greetings! I just ported this blog from Wordpress to awestruct, the best static site generator out there (translation: the one with which I’m most familiar). What better way to celebrate independence on this July 4th than freeing my blog from unnecessary and insecure dynamic generation?

Maybe this will spur me to post more. Then again, maybe it won’t. I am planning to blog the conversion process so you can follow along at home.

Access commonly used credentials quickly in irb

I often deal with multiple Amazon AWS accounts in irb, and grew tired of copying and pasting my credentials, so I added code to my ~/.irbrc to make them available from a constant. Here is the relevant chunk of my irbrc (explanation follows):

I load the credentials from a separate yaml file, with the keys as symbols (I’ll explain why in a sec):

The yaml is parsed and loaded in to an OpenCascade from the Hashery gem, which works like ruby’s builtin OpenStruct, but provides deep ‘structing’ of the source hash. Since it requires symbols as keys, I store the keys as symbols in the yaml to avoid an ugly symbolize_keys step.

Now, inside irb, I can access the credentials with:

EC2.account_a.access_key_id
EC2.account_b.secret_access_key

Since I use RVM gemsets for almost everything, I’m often switching between gemsets, some of which have not had an irb session. To handle that case, I have the force_require method that will automatically install missing gems.

open_exception gem: now with better emacs support!

I just released v0.3.1 of the open_exception gem. This release does a better job of handling exceptions that have been munged by Rails, and now provides a tempfile containing the full stack trace to the open command.

If you are using emacs, you can use the :emacs_with_trace open command, and get the stack trace as a navigable compilation buffer (next to || below) the source file in a split frame. For this to work, you’ll need to add the following function to your emacs init:

See github for the code and README.

open_exception gem: auto open exceptions in your editor

open_exception opens an exception in your favorite editor when developing locally. It works by parsing the backtrace, and opening the offending file at the offending line in your favorite editor (assuming your favorite editor supports remote open commands).

You can add filters that allow you to ignore some exceptions, and filters that allow you to scope the backtrace search. The backtrace scoping is useful for opening the last call in your application code when the exception occurs in a framework or lib.

If you are on MacOSX and have the growl gem installed, you will get a growl notification with the exception message when the file is opened.

Editors

Out if the box, the gem supports three editors (with the following open commands):

:emacs => '/usr/bin/emacsclient -n +{line} {file}',
:textmate => '/usr/local/bin/mate -a -d -l {line} {file}',
:macvim => '/usr/local/bin/mvim +{line} {file}'

Note: if using emacs, you will need to be running emacsserver. To start the server: M-x server-start

or add (server-start) to your init.

Configuration

To configure, pass a block to the configure method:

OpenException.configure do |oe|
    # open_with can be one of the built in editors (:emacs, :macvim, :textmate)
    # or a command to execute to open the file, where {file} and {line} will be replaced
    # with the file path and line number, respectively. See 'Editors' above for an example.
    # The default editor is :emacs.
     
    oe.open_with = :emacs
     
    # you can add exclusion filters to ignore exceptions. A filter can be an exception class to 
    # ignore, or a proc that is passed the exception, and should evaluate to true if the exception 
    # should be ignored. Be careful with using a class - it uses is_a?, so any subclasses of the
    # passed class will be ignored as well. The list of filters is [] by default.
     
    oe.exclusion_filters << SomeErrorClass
    oe.exclusion_filters << lambda { |exception| true if exception_should_be_excluded }
     
    # you can scope the search for the file:line to open with a filter as well. A filter can be a 
    # regular expression that is matched against the line, or a proc that is passed the line and 
    # should evaluate to true if the line should be used. The first line that any filter passes for 
    # will be the file:line that is opened. This is useful for opening the point in the stack just
    # before control passes out of your app code when the exception occurs in an external 
    # lib/framework. The list of filters is [] by default. 
     
    oe.backtrace_line_filters << %r{/app/root/(app|lib)} 
    oe.backtrace_line_filters << lambda { |backtrace_line| true if line_should_be_used }
     
end

Rails Integration

The gem also alias chains in to rails’ ActionController#rescue_action_locally method to automatically open exceptions in development mode. The gem also adds the following filter to the :backtrace_line_filters to scope the opened files to the app:

%r{#{Rails.root}/(app|lib)}

To replace or remove this filter, you will need to reset the :backtrace_line_filters in your configure block:

OpenException.configure do |oe|
    oe.backtrace_line_filters = []
    oe.backtrace_line_filters << my_new_filter
end

This has been tested with rails v2.3.5, but should work fine with 2.1 <= rails < 3. It may work with rails 3 as well, I just haven’t yet looked at rails 3.

Standalone/Other Frameworks

# To manually open an exception, or wire it up in another framework, you call:
OpenException.open(exception)
 
# You can override the default (or configured) options by passing a hash as the second arg:
OpenException.open(exception, {:open_with => :textmate, :backtrace_line_filters => [filter, another_filter])

The source is on github, and the gem is on rubygems.