Archive for the 'Programming' Category

Capistrano via Cron or FreeBSD Periodic

Tuesday, May 5th, 2009

Running Capistrano from cron or FreeBSD’s periodic can be tricky—both (wisely) limit your environment. Scripts may run just fine in a SSH session, but fail when run by cron.A couple of standard gotchas:

  • Command not found: your PATH is usually chopped down. Either explicitly set PATH to include you commands, or execute commands with their full paths.
  • No terminal. On Linux, try sudo’s -i option.

More puzzling:connection failed for: (RuntimeError: can’t get terminal parameters (Inappropriate ioctl for device))I assumed this was a tty/SSH/login session problem. Turns out it was a permissions problem. The current user couldn’t login to the remote server via SSH, and the remote server was prompting for a password. Of course, it worked when running this script by hand.

Rails 2.3 Plugin Routes

Thursday, March 19th, 2009

As noted here and here, Rails 2.3 will load routes from a plugin. If the plugin is considered an engine. A blank “app” directory in your plugin’s root is enough for the plugin loader.

Google Group for Racing on Rails

Tuesday, July 29th, 2008

There was a burst of interest in WSBA website development on their mailing list—enough to annoy a few non-coders at any rate. So Racing on Rails has its own Google Group for development. Here’s hoping it’s the tip of the volunteer Rails coder cyclist iceberg.

For those late to the party or too lazy to click the link above, Racing on Rails is the Ruby on Rails application behind several bike racing association websites like the WSBA and OBRA. It’s all open source (except for the association-specific parts), and it pretty much works OK at this point.

I’ve put a lot of time into this code in the last few years. Plenty of cool ideas abound for these sites—it would be great to have more developers to make those ideas happen.

We’re Hiring Another Rails Developer

Wednesday, February 6th, 2008

“We” means Analog Analytics. It’s fun, personally, to be hiring now instead of trying to be hired. Here’s the job description:

“Terrific opportunity for talented developer to join an exciting team helping to change the advertising industry.”

It’s a remote position — Pacific time zone strongly preferred — I’m in Portland, the CTO is in Los Angeles, and the CEO is in San Diego. There’s no home office. We deploy and develop Rails (and a little C) on OS X, Linux, and Solaris.

Light on the details? Sure. We’re not hung up on any many specific qualifications. Want to earn your salary coding in Rails? Email me at

Rails 2 upgrade: .rhtml to .html.erb Script

Wednesday, January 16th, 2008

This is less a post, than a note to myself, but anyway, here’s a handy script to change your view extensions while preserving Subversion history.

#! /usr/bin/env ruby
require 'pathname'
for path in Dir['app/views/**/*.rhtml']
pathname =
p `svn mv #{path}#{pathname.dirname}/#{pathname.basename.to_s.split('.').first}.html.erb`

Obscure Oracle JDBC Exception du Jour

Thursday, December 6th, 2007

I ran across this exception again today, and Google didn’t anything useful until I dug in a bit. Hopefully, this will help someone else searching for UnsatisfiedLinkError and free_c_state exceptions.

Your JDBC URL syntax is wrong.

You need something like jdbc:oracle:oci:@RPTD

java.lang.UnsatisfiedLinkError: free_c_statejava.lang.UnsatisfiedLinkError: free_c_state
at oracle.jdbc.oci8.OCIDBAccess.logoff(
at oracle.jdbc.driver.OracleConnection.(
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(
at oracle.jdbc.driver.OracleDriver.connect(

undefined method `dbman’

Sunday, November 18th, 2007

Upgrading to a Rails app to 2.0 and seeing this error?

undefined method `dbman' for #<ActionController::TestSession

You need to add this line to config/environments/test.rb:
config.action_controller.allow_forgery_protection = false

Obvious to you, maybe, but not to me.

Dumb Thing I Did Recently With Rails

Tuesday, October 30th, 2007

Turns out that dashes are not really valid hostnames in URLs. So, ‘’ is valid, but ‘’ is not.

Now, Apache virtual hosting will work with underscores just fine, as did 1.1 versions of Rails and Safari 2.0. I think IE never liked it. By “worked” and “liked,” I mean that the browser accepted cookies from the host. If the browser doesn’t accept the cookies, then Rails creates a new session for each request, and that prevents you from logging in to sites like

Safari 3 show the same behavior. In fact, with Rails 1.2, the only browser that “works” is Firefox.

Anyway, long story short: don’t use underscores in hostnames.

Advanced Spring by Rod Johnson

Wednesday, August 8th, 2007

The Spring man himself, Rod Johnson, gave this talk. He looks better in person than he does on this book cover.

O’Reilly-mandated audience poll:
Using Spring: 90%
Strong knowledge: 50%
Written a BeanPostProcesser: Me + someone else (not that I remember what it was for)
33% of the audience use Spring for data access.
Use Spring version 2: 40%
Use Spring version 1: 10%

Rod says: Spring is easy to customize because of its component model.

What is Spring? Well, it’s a Java framework that makes it easier to work with J2EE, and offers alternatives to the weak spots or omissions in J2EE. That’s my description. Since this was an “advanced” talk, the presenter offered:
Core components with Inversion of Control (IoC), but IoC is really just an enabler.
The triad:

  1. Consistent patterns
  2. Integration
  3. Portable (decouples your business logic from infrastructure)

Gives you: Universal POJO programming model

Spring uses good APIs abstractions like DataSource, and replace bad ones like JTA. and Spring uses configuration meta-data to wire together POJOs.

Rod shows us an example of using AOP pointcut using matching rule. Man, I don’t know. Pointcuts makes sense when I really stare at them, but they are nasty looking.

With Spring and AOP, you can add remoting to any POJO without forcing the POJO to know about it. Likewise, you are not forced to make all service classes remote. Nasty magic AOP and XML config aside, this really is pretty cool. A big practical advantage when you are working with code or writing tests.

Now we talk about FactoryBeans. Rod asks: “who can tell me what a Spring FactoryBean does?” Weak audience response. Uh oh, Rod can tell that we’re not really advanced Spring users. Contempt. (A FactoryBean creates other beans.)

Back to our feature tour programming. You can add the JMX API to you Spring beans. “Very cool.” Of course, only 5% of the audience use JMX.

Spring can use weave any bean with aspects. Example: can audit calls to particular method. Yikes, another pointcut example. I still find the syntax confusing as hell. But, the EJB interception model “sucks” because it’s not typesafe.

We start to pick up to whirlwind tour pace. Rod is cramming his 90-minute JavaOne presentation into 45 minutes.

There are (will be?) new extension points:

  • New XML tags to produce zero or note Spring bean definitions
  • Properties
  • Tags for transactions

What’s coming in Spring 2.1;

  • increased use of annotations for config. and can mix XML and annotations
  • JCA 1.5
  • Improved JPA support
  • Aims: Make Spring still easier to use

Bayeux and CometD: Open Source Comet Infrastructure by Alex Russell

Wednesday, August 8th, 2007

Bayeux and CometD: Open Source Comet Infrastructure
Alex Russell, Project Lead, SitePen

OK, this is a hard one to explain without going into a lot of background. And I felt a bit sorry for the presenter, because it appeared that half of the (small) audience was already familiar with the topic. Part of the social networking/CometD/Dojo “community.”

The presenter works on Dojo, and he’s got a great summary of CometD and Bayeaux.

Essentially, he’s trying to solve a fundamental problem of social networking websites. Each users has a page from the website in their browser. They need to send messages to each other — to each others’ browsers — but they can’t do this directly with peer-to-peer networking. Everything must go through a central server and the browsers must poll for messages.

This network architecture is difficult to scale and has high latency. High latency is bad. Users notice latency and they stop using the site.

So, what to do? Responsiveness matters, but the total amount of data isn’t a big deal.

There’s a protocol called Comet that keeps an HTTP connection open, but it relies on “brittle hacks.” (I think. Sorry if I muffed this bit.)

Bayeux is a new replacement protocol. It’s goals:

  • Browser native, no plugins
  • Easy to digest (simplicity is key, so that anybody can do use it)

What it is:

  • JSON-based
  • Hierarchical channels with simple globbing
  • Transport negotiated in handshake
  • Explicitly extensible
  • Stateless
  • Small number of verbs: handshake, connect, …

What it is not:

  • Authentication
  • Guranteed delivery

The client API is simple:
dojox.comet.publish("topic", { /* payload */});

CometD is the reference server implementation of Bayeaux, but there are more:

  • Jetty
  • WebSphere
  • Tomcat