Photo-1 Photo-2 Photo-3 Photo-4 Photo-5 Photo-6



Full-time web developer. Part-time smart ass.

I'm Brent Collier.

After a year and a half as an engineer on Twitter's Trust & Safety team, I'm looking for my next gig. Contact me if you know of something interesting.


Rails 3 asset compilation problem

Posted on 12/30/2013

Is your Rails 3.2 app showing errors like this in the log file?

ActionController::RoutingError (No route matches [GET] "/assets/bootstrap-responsive.css"):
  actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.8) lib/rails/engine.rb:479:in `call'
  railties (3.2.8) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Users/brent/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /Users/brent/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /Users/brent/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

Or like this in the browser console:

$ is not defined

If you've got all the necessary manifest files included in your layout, and those manifest files all have the correct import statements, then you may just need to update your Rails gem version.

My 3.2.8 Rails app was showing these symptoms and a quick bump to 3.2.14 in the Gemfile fixed everything.


Net::HTTP "End of file reached"

Posted on 03/25/2013

While writing some code to consume Twitter's v1.1 api, I was continually running into this error:

EOFError: end of file reached

I began adding and removing bits of code around the http request, until I eventually discovered it was the gzip encoding that was causing the problem. Removing this header declaration seemed to fix everything up:

request["Accept-Encoding"] = "gzip"


I ran into the same issue again, this time with a different solution. I was including an HMAC signature in the header, but wasn't encoding it properly.

I changed it from

request['X-Hmac-signature"] = generate_signature


request['X-Hmac-signature'] = URI.encode(generate_signature)

and the EOFerror went away.


Configuring Redis Store for Rails 2.3.x

Posted on 05/23/2012

I wanted to use Redis as the cache store for a Rails 2.3.8 app. After a little shopping around, I settled on RedisStore as the cache adapter. I following the configuration directions on the RedisStore website and restarted the app, expecting everything to be hunky-dory. Instead, I was kicked in the face with this:

uninitialized constant ActiveSupport::Cache::RedisStore

My redis-store configuration looked like this:

redis_config = YAML.load_file(RAILS_ROOT + '/config/redis.yml')[RAILS_ENV]
config.cache_store = :redis_store, redis_config

I took another look at the config instructions and realized I was using the Rails 3.x setup. Following the 2.x instructions, I updated the configuration to look like this:

redis_config = YAML.load_file(RAILS_ROOT + '/config/redis.yml')[RAILS_ENV]
config.gem 'redis-store'
config.cache_store = :redis_store, redis_config

After restarting the app, I was still seeing the same uninitialized constant error. Finally, a bit more googling revealed that v1.1.0 of redis-store didn't jive with Rails 2.3.8. Evidently what I needed was v1.0.0.1. I'm not sure why it's v1.0.0.1 and not v1.0.1, but I checked and saw that v1.0.0 was yanked for some reason.

alt text

Anyway, so I updated my Gemfile to specify version v1.0.0.1 of redis-store and bam! The app starts up without yelling at me. Good stuff. Or so I thought.

Everything was hunky-dory in my local development environment, but when I started testing in our staging environment, something was up. Our staging environment consists of two app servers, one of which has the Redis instance running on it.

Attempts to connect to Redis repeated failed with an "unable to connect" error on one web server, but not the other. Examining the redis connection, it was clear that the app was trying to access Redis via localhost, the default when no valid connection options were supplied. This explained why it worked on one app server and not the other, since Redis was in fact running locally on one of them.

A little console debugging demonstrated that the redis config expected a hash with symbol keys, whereas the config hash loaded from the yaml file had string keys.

config.cache_store = :redis_store, redis_config.symbolize_keys

Updating the redis-store config to symbolize the keys allowed the connection to be properly created, and everything was working as intended.


Psql: could not connect... Oh fuck you!

Posted on 04/24/2012

My wife was out of town and I wasn't in the mood for Xbox, so I thought I'd resume work on a personal project that I hadn't touched in a while. I cd'd into the project directory, started the rails server, and hit up localhost:3000 in Chrome. That's when I was hit with this lovely little gem:

psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

Ahh, fuck. I knew, or at least I thought I knew, that Postgres was running. I had a launch agent set up for it, so it should be running. I consulted the process list...

ps aux | grep postgres

...which returned nothing. Well shit. I tried a quick reboot. No luck. Still not running. Tried to start it manually with:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
pg_ctl: another server might be running; trying to start server anyway
server starting

Sure it says "server starting", but what does that really mean? Nothing evidently. After a bit more console hackery and rabid googling, I determined that Postgres was probably in a bad state after one of several recent kernel panics as a result of simultaneously using POW and Cisco's AnyConnect VPN client. This would explain why there was a postmaster pid file, but Postgres wasn't running.

Google told me that my transaction logs were probably in shit-shape, which meant they would need to be cleaned up using pg_resetxlog like so:

$ pg_resetxlog /usr/local/var/postgres
pg_resetxlog: lock file "/usr/local/var/postgres/" exists
Is a server running?  If not, delete the lock file and try again.
$ rm /usr/local/var/postgres/
$ pg_resetxlog /usr/local/var/postgres
The database server was not shut down cleanly.
Resetting the transaction log might cause data to be lost.
If you want to proceed anyway, use -f to force reset.
$ pg_resetxlog -f /usr/local/var/postgres
Transaction log reset

Finally, after a manual start up:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting

Things were in good working order, and I was able start up the dbconsole and connect without a problem.