Installing Rails on Ubuntu 7.10

February 5, 2008 by donc

It was kind of a pain to get Rails installed on Ubuntu 7.10 (Gutsy Gibbon). Ruby is in the main repositories, but rdoc and ri are in the universe repository. Universe also has a ruby-full package with dependencies to most of the ruby packages, which is nice.

Enable universe by editing /etc/apt/sources.list

It’s even easier to enable universe through synaptic.

$ sudo synaptec

Settings -> Repositories
Check Community-maintained Open Source software (universe)
Save, Close, Close

Update apt-get and install the ruby-full meta package

$ sudo apt-get update
$ sudo apt-get install ruby-full

Install curl

sudo apt-get install curl

Download rubygems-1.0.1 since the one from apt-get is old

$ curl -OL http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
$ tar xzf rubygems-1.0.1.tgz
$ cd rubygems-1.0.1
$ sudo ruby setup.rb

Gem gets installed as gem1.8 which is annoying. (Probably because ruby is a symlinked to ruby1.8). Another symlink fixes this.

$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Something in build-essential is required to build mongrel_cluster

$ sudo apt-get install build-essential
$ sudo gem install mongrel_cluser

I use MySQL

$ sudo apt-get install libmysqlclient15-dev
$ sudo gem install mysql

Install more gems

$ sudo gem install capistrano
$ sudo gem install soap4r
$ sudo gem install radiant
$ sudo gem install your-favorite-gem
...

Java 6

December 12, 2007 by donc

thank_you_landon_fuller.png

Still no word from Apple on Java 6.

Fortunately Landon Fuller released a Java 6 port for OS X.

We been using it for development and it’s working great.

http://landonf.bikemonkey.org/static/soylatte/

Hooking custom authentication into Radiant CMS

November 6, 2007 by donc

radiant.png

I’m working on a site running Radiant CMS. Instead of authenticating users with the Radiant database we want to use Crowd.

I need to do 2 things
1) have User include CrowdAuthenticator
2) override the existing implementation of User.authenticate

The solution took a while, but it turned out to be fairly simple.

Create a new radiant extension

$ script/generate extension crowd_authenticator

Create a CrowdAuthenticator module in the lib directory under the extension. The CrowdAuthenticator module has a method to authenticate users by calling Ruby code that wraps the Crowd SOAP API. It also handles updating the Radiant database with the user information from Crowd.

The extension injects my module into the Radiant User model.

class CrowdAuthenticatorExtension < Radiant::Extension
  def activate
    User.send :include, CrowdAuthenticator
  end
end

Radiant looks for the user in the database. I want to change the definition of User.authentication without editing the Radiant code.

class User < ActiveRecord::Base
  ...
  def self.authenticate(login, password)
    find_by_login_and_password(login, sha1(password))
  end
  ...
end

I was having trouble trying to “override” the “static” authenticate method. Fortunately Simon Harris helped out with Alias a Static Method in Ruby

When my extension loads it replaces User.authenticate with CrowdAuthenticator.crowd_login.

# crowd_authenticator.rb
require 'crowd'

module CrowdAuthenticator
  def self.included(base)
    base.extend ClassMethods

    base.class_eval do
      class << self
        alias_method :old_authenticate, :authenticate
        alias_method :authenticate, :crowd_login
      end
    end
  end

  module ClassMethods

    def crowd_login(login, password)
      crowd_user = get_crowd_user login, password
      return nil if crowd_user.nil?

      find_or_create_user crowd_user
    end

    def get_crowd_user(login, password)
      # call api
      # check groups
      crowd_user
    end

    def find_or_create_user(crowd_user)
      # create radiant user if necessary
      # update radiant user with info from crowd_user
      # save and return user
    end
  end
end

I also added some new routes to disable the existing pages for creating, and editing users, since these are now managed through Crowd.

Starting MySQL after Leopard upgrade

October 31, 2007 by donc

After upgrading to Leopard, the MySQL preferences pane would not start the database.

Starting mysql from a terminal

$ cd /usr/local/mysql/bin
$ sudo -b ./mysqld_safe

Stop mysql

$ sudo mysqladmin shutdown

Thank you sir, may I have another

October 26, 2007 by donc

we_dont_need_no_stinking_java6.png

Leopard doesn’t come with Java 6. @#$%. I should have known better, but I pre-ordered Leopard anyway. I really want Java 6, since I’m tired of developing in virtual machine.

This is frustrating since Apple includes the latest Ruby, Rails, Python etc. Whatever. I had those installed with Tiger. Unfortunately only Apple provides Java for OS X. [bitching and griping deleted --ed]

I sure hope there’s a Java 6 download on ADC soon.

WTF?

September 6, 2007 by donc

WTF
Why is Apple charging an extra $0.99 to play clip of a song when the phone rings? Are they going to start charging more to listen to music in the car, on Tuesday, on vacation …

Debugging JRuby with Netbeans 6

July 27, 2007 by donc

Debugging JRuby with NetbeansĀ 6

I do most of my Ruby development in TextMate and Java development in IntelliJ, but both have quirks with JRuby. I’ve been checking out Netbeans 6 M10 and the Netbeans Ruby IDE. There are some nice features and great JRuby support.

I was having a problem tracking down a bug in my JRuby code. I fired up Netbeans, set a break point and stepped though the code. It worked great, I found the problem immediately.

JRuby, Rake and Windows

July 25, 2007 by donc

I’ve been writing a lot of JRuby lately to script a Java application.

I was getting the code to run on Windows for our developers who are not using OS X and Linux and ran into some trouble with Rake. The rake-0.7.3 gem is installed but the shell script c:\jruby-1.0\bin\rake doesn’t do me any good.

JRUBY-969 suggested jruby -S rake which is cool. I wasn’t aware of jruby’s -S switch.

-S cmd run the specified command in JRuby’s bin dir

This was annoying to type so I created rake.cmd

@echo off
jruby -S rake %*

Note: I find it convenient to symlink rake to jake to avoid conflicting with rake from MRI (Matz’s Ruby Interpreter).

jythonconsole-0.0.4 released

March 27, 2007 by donc

Jython Console is a Jython Interactive Interpreter that adds Code Completion.

jythonconsole-004.png

See the project page for more info.

Backup

March 11, 2007 by donc

I switched to a new backup system: SuperDuper! and an external firewire drive.

So far, this solution seems much better than the previous backup scripts, programs and hacks that I’ve used.

I really like the fact that I can use another Mac and boot with the firewire drive to test the backup.