Saturday, 7 March 2009

Deploying Sinatra on Joyent’s Shared Accelerators with Thin

On Thursday afternoon, I had an idea for just about the smallest web app I could think of (since then, I’ve even cut out a couple features). It didn’t make sense to use all of Ruby on Rails for this considering how tiny it was.

Seemed like a great opportunity to try out Sinatra1

  1. Write the app
  2. Vendor Sinatra and Rack (that’s just good practice)
  3. Submit a ticket requesting a port
  4. Add a config.ru file to your app’s directory (for Rack) containing the following

    # PATH TO VENDOR-ED RACK AND SINATRA
    require 'vendor/rack-[VERSION]/lib/rack'
    require 'vendor/sinatra-[VERSION]/lib/sinatra'
    Sinatra::Application.set(
    :run => false,
    :environment => :production
    )
    require 'app'
    run Sinatra::Application
  5. Add a config.yml file to your app’s directory for Thin containing the following

    ---
    environment: production
    chdir: /path/to/app
    address: 127.0.0.1
    user: [USERNAME]
    port: [PORT]
    pid: /path/to/domain/tmp/thin.pid
    rackup: /path/to/app/config.ru
    log: /path/to/domain/logs/thin.log
    max_conns: 1024
    timeout: 30
    max_persistent_conns: 512
    daemonize: true
  6. Follow the Setting up and Configuring Lighttpd instructions on the Joyent Wiki (See update below)
  7. Add another Bootup Action for Thin
    Startup thin -s 1 -C /path/to/config.yml -R /path/to/config.ru start
    Shutdown thin -s 1 -C /path/to/config.yml -R /path/to/config.ru stop
  8. Follow the Proxying to a Port instructions on the Joyent Wiki
  9. 1. If the time I spent building this app was a cocktail, it’d be 1 part programming, 2 parts design, 3 parts deployment. That’s a huge part of why I wrote this post.

UPDATE: March 8, 2009
My gut says Lighttpd + Thin is redundant, so I’ve turned Lighttpd off.

Saturday, 3 January 2009

QSPress.rb – Quicksilver to WordPress in Ruby

Remember the Quicksilver to WordPress Applescript I wrote a while back?

Well, I’ve ported it to Ruby.

The QSPress.rb works the same as the Applescript version, with a couple of tweaks – you can now set categories, flag if a post should be a draft, and upload files – all from Quicksilver.

The full instructions are in the script itself. Enjoy.

Download QSPress.rb

Thursday, 1 January 2009

iPhoto to WordPress Ruby Script

I maintain a WordPress blog that’s primarily an extension of iPhoto, and the various iPhoto plugins (Photon by Daikini, Photon by Orby, WordPress Export) I’ve tried over the years seem to have stopped being maintained, stopped working, or both.

Which is fine, they never worked exactly the way I wanted them too anyway.

So, I wrote one.

In Ruby, with some help from rb-appscript

Unlike like the other iPhoto export options, this one lives in your Scripts menu and automatically creates (and opens!) a draft post containing all the selected images.

Download send_selected_photos_to_wordpress.rb

“It’s surprisingly short and effective.” – Peter Cooper