Trevor Turk

A chess-playing machine of the late 18th century, promoted as an automaton but later proved a hoax.

Month: June, 2009

Config vars and Heroku

I don’t really care for the suggested approach in the Heroku docs for setting configuration variables locally. I have an open-source project that I’m working to get onto Heroku, so I decided to do a little work to come up with a solution that I prefer. I think this would work well for open source projects, as well as projects with multiple developers.

Here’s the basic idea:

You have a config file that contains all of your local configuration variables. It looks a lot like database.yml.

# config/config.yml

development:
  session_key: example_development
  session_secret: ESl6X3oKM1i1RRrD2QLwUUzz9jr1zxNO
  domain: http://example.com

test:
  session_key: example_test
  session_secret: vrwPpJTvwnMVLP1wTSgqigSl7PMI7QcE
  domain: http://example.com

production:
  session_key: # any string identifying your app
  session_secret: # a random, secret string at least 32 characters long
  domain: # http://example.com
  mailer: # noreply@example.com

You perform a little trickery in environment.rb to prefer the Heroku ENV storage of config vars (in the production environment), but you fall back to your config.yml if the config vars aren’t found in ENV (in the development and test environments).

# config/environment.rb

Rails::Initializer.run do |config|
  require 'yaml'

  # support yaml and heroku config vars, preferring ENV for heroku
  CONFIG = (YAML.load_file('config/config.yml')[RAILS_ENV] rescue {}).merge(ENV)

  config.action_controller.session = {
    :key => CONFIG['session_key'],
    :secret => CONFIG['session_secret']
  }
end

Then, you create a rake task (rake heroku:config) that can be used to send all of the config vars for your production environment up to Heroku. This task can be invoked once to set things up, but can also be run again if you need to make any additions or changes.

# lib/tasks/heroku.rake

namespace :heroku do
  task :config do
    puts "Reading config/config.yml and sending config vars to Heroku..."
    CONFIG = YAML.load_file('config/config.yml')['production'] rescue {}
    command = "heroku config:add"
    CONFIG.each {|key, val| command << " #{key}=#{val} " if val }
    system command
  end
end

This way, you’ve got all of your config vars stored with the project (.gitignored, of course)…

# .gitignore

/tmp/**/*
/log/*
*.log
/tmp/restart.txt
/config/config.yml
/config/database.yml
/db/*.sqlite3

…and you can easily set what you need on Heroku, like so:

$ rake heroku:config
Reading config/config.yml and sending config vars to Heroku...
Adding config vars:
  session_key => example_production
  session_secret => 1WlkMkYYi5611vtF...0ZMS2G3Xl67s4lEIK4sj65
  domain => http://example.com
  mailer => noreply@example.com
Restarting app...done.

The result is a pretty nice, I think.

You can see the installation and deployment instructions for my open source project El Dorado if you’re curious about the overall flow.

I’d love to get some feedback on this approach, but I really like it so far :)

Install Ruby Enterprise, Phusion Passenger and El Dorado on Debian Lenny

This post has been moved to http://demongin.org/blog/817

Weekly Digest, 6-22-09

How to speed up gem installs 10x

Answer: Turn off ri and rdoc installation.

Perch

Perch is a really little content management system for when you (or your clients) need to edit content without the hassle of setting up a big CMS.

Installing Ruby on Rails and PostgreSQL on OS X, Third Edition

Over the past few years, I’ve helped you walk through the process of getting Ruby on Rails up and running on Mac OS X. The last version has been getting a lot of comments related to issues with the new Apple Leopard, so I’m going this post will expand on previous installation guides with what’s working for me as of January 2008.

Thoughts on Opera Unite

Opera’s CEO Jon von Tetzchner claims that “Opera Unite now decentralizes and democratizes the cloud.” I call bullshit. Opera Unite does indeed rely on a P2P-like network to function, but the big problem is that you must push all your traffic through Opera’s proxy service.

LESS – Leaner CSS

Less is Leaner css. Less extends css by adding: variables, mixins, operations and nested rules. Less uses existing css syntax. This means you can migrate your current .css files to .less in seconds and there is virtually no learning curve.

YC Company Hosting Stats

[Interesting stats and discussion on hosting.]

Rip: a RubyGems Replacement?

This makes package management as simple as passing files between friends. Email me your latest library, and I can run rip install path/to/lib. That’s it — you don’t need spec files, and you don’t need to build anything before your send me your code.

BigTable

BigTable is a fast and extremely large-scale DBMS. However, it departs from the typical convention of a fixed number of columns, instead described by the authors as “a sparse, distributed multi-dimensional sorted map”, sharing characteristics of both row-oriented and column-oriented databases. BigTable is designed to scale into the petabyte range across “hundreds or thousands of machines, and to make it easy to add more machines [to] the system and automatically start taking advantage of those resources without any reconfiguration”.

Opera Unite reinvents the Web: a Web server on the Web browser

[Very interesting possibilities here. Making it easier for people to serve content on the web can only lead to good things.]

tenderlove’s markup_validity

Test for valid markup with test/unit or rspec

Hemlock

Hemlock is an open-source framework that combines the richness of Flash with the scalability of XMPP, facilitating a new class of web applications where multiple users can interact in real time. Games, workspace collaboration, educational tools… The only limit is your imagination.

Rip: A New Package Management System for Ruby

But why a completely new package manager? What’s wrong with RubyGems? We asked one of Rip’s developers, Chris Wanstrath…

Ruby at ThoughtWorks

ThoughtWorks started using Ruby for production projects in 2006, from then till the end of 2008 we had done 41 ruby projects. In preparation for a talk at QCon I surveyed these projects to examine what lessons we can draw from the experience. I describe our thoughts so far on common questions about Ruby’s productivity, speed and maintainability.

[git pull] drm-next

See? All the rules really are pretty simple. There’s that somewhat subtle
interaction between “keep your own history clean” and “never try to clean
up _other_ proples histories”, but if you follow the rules for pulling,
you’ll never have that problem.

GitHub Protip: Follow other users

Inspired by this post, I thought I’d share a tip that helps me get the most out of GitHub.

Don’t just follow the projects that you’re interested in — follow other users. Here’s a list of people that I’m following. They’re constantly turning me on to new and interesting projects, because I get to see everything they’re working on, and everything they’re following.

 

Dig around the users that I follow, check out what they’re been up to, and try it out. If you find that your feed becomes a bit much to manage, try subscribing to your personal RSS feed. There’s a link on the home page when you’re logged in.

Thanks, GitHub. You’re the best.

Automatically Rotate your Log Files in Development

I’m trying to save hard drive space, since I’ve got this super small (and fast?) SSD hard drive on the way. I noticed that I was using a TON of space to store totally worthless logs for my Rails apps. Now, I know I could set up proper log rotation, but I don’t feel like going through the trouble for my local machine.

Here’s a quick tip I picked up here that will set your logs to automatically rotate in the test and development environments. Just add the following line to these files:

  • config/development.rb
  • config/test.rb
config.logger = Logger.new(config.log_path, 2, 20.megabytes)

Make sure you’ve got these in your .gitignore file as well:

/log/*
*.log

That will keep your log files under control, but with plenty of room for digging in if need be.

Speed up your Apache/Passenger Rails app in 2min

Here’s a quick tip for speeding up your Apache/Passenger powered Rails app. It’ll take you about 2 minutes, and I guarantee you’ll notice the speed-up.

  • SSH onto your VPS
  • Run the following commands: “a2enmod expires” and “a2enmod deflate”

Now, open up your Apache vhost config for your Rails app. Add the following:

http://gist.github.com/128392

Then, restart Apache by running: “/etc/init.d/apache2 restart”

This will gzip your html, css, and javascript. It’ll also add far future expires headers for the appropriate cacheable filetypes. There’s no downside, and it only takes a second. Bang for buck.

Edit: Check the comments for some possible downsides… ;)

Weekly Digest, 6-11-09

In this edition, Timothy moves to Washington DC and Trevor trims down his “watch list” on GitHub and shares many interesting projects with you via his delicious feed.

Trevor’s Links

Email. Twice daily. No more, no less.

So, using some motivation from The Four Hour Workweek1, I opted to come back to the studio and change my behavior. That morning, I emailed my entire team and my clients to let them know that I would only be checking my email at 10am and 4pm each day.

How to Build a Popularity Algorithm You can be Proud of

Many web sites allow users to casts vote on items. These visitors’ votes are then often used to detect the items’ “popularity” and hence rank the rated items accordingly. And when “rank” comes into play things gets tricky…

Online communities, etc.

Anyway, I’m bored on a long bus drive and there’s no real moral to the story here, just writing. I will be tuning out of the social networking sites because at the end of the day it’s now doing more harm than good in the bigger picture and the experiment seems to have yielded a result. Idiots rule.

Really Simple Rails Log Rotatation

I always used logrotate Linux tool to setup log rotation for my Rails apps which has worked fine although it required finding some external config file and understanding its config options and syntax. [Great tip for development/test environments. Might not be a good idea in production?]

Instapaper bookmarklet, modified to close the current tab

I modified the bookmarklet slightly so that the tab closes immediately, without disturbing the pop-up. This way, saving something for later is one simple action, instead of two.

DeliciousSafari

Use and create Delicious bookmarks from the Safari web browser.

So, about this Shopify Platform

The Shopify platform allows any programmer to create applications that integrate natively with the administration interface or storefront. These applications can be written in any language and communicate with Shopify using our handcrafted REST API. We even provide some amazing rails generators to get started quickly.

Introducing Trample: A Better Load Simulator

Most load sim tools make requests to a static list of urls. They spawn n threads and make requests to the urls on the list in succession, in each thread. Unfortunately, though, if your applicaition makes use of any kind of caching (including your database’s internal caching facilities), this kind of load simulation is unrealistic.

TOSBack | The Terms-Of-Service Tracker

TOSBack keeps an eye on 44 website policies. Every time one of them changes, you’ll see an update here.

Twitter Blog: Not Playing Ball

We do recognize an opportunity to improve Twitter user experience and clear up confusion beyond simply removing impersonation accounts once alerted. We’ll be experimenting with a beta preview of what we’re calling Verified Accounts this summer.

cdto

Fast mini application that opens a Terminal.app window cd’d to the front most finder window. This app is designed (including it’s icon) to placed in the finder window’s toolbar.

Trevor’s GitHub Links

quirkey’s sammy

Sammy is a tiny javascript framework built on top of jQuery inspired by Ruby’s Sinatra.

kabuki’s heresy

Heresy is a schema free wrapper around your database, heavily inspired by both CouchDB and FriendFeed.

paulmars’s seven_minute_abs

ab testing for rails

binarylogic’s searchlogic at v2

Searchlogic has been completely rewritten for v2. It is much simpler and has taken an entirely new approach. To give you an idea, v1 had ~2300 lines of code, v2 has ~350 lines of code.

semanticart’s is_paranoid

ActiveRecord 2.3 compatible gem “allowing you to hide and restore records without actually deleting them.” Yes, like acts_as_paranoid, only implemented differently…

brynary’s webrat

Webrat – Ruby Acceptance Testing for Web applications.

mbleigh’s twitter-auth

Standard authentication stack for Rails using Twitter to log in.

courtenay’s splam

Simple, pluggable, easily customizable score-based spam filter plugin for Ruby-based applications.

jeremy’s ruby-prof

a fast code profiler for Ruby

nakajima’s roleful

Generic roles for you and your objects.

37signals’s wysihat

A WYSIWYG JavaScript framework

binarylogic’s authlogic

A clean, simple, and unobtrusive ruby authentication solution.

joshuaclayton’s blueprint-css

A CSS framework that aims to cut down on your CSS development time.

stephencelis’s dots

Free progress dots for your scripts. Test::Unit-style.

wycats’s merb-extlib

Ruby core extensions library extracted from Merb core.

jodosha’s plugin_migrations

Rake tasks for running plugin migrations.

tcocca’s acts_as_follower

A Plugin to add “Follow” functionality for models

mojodna’s active_queue

A toolkit for queueing tasks and creating worker processes

Follow

Get every new post delivered to your Inbox.