A brief update

Firstly, my apolgies to those who have had their RSS read re-filled with old posts, I’ve moved the site to Wordpress. Enki was fantastic, however Wordpress is quite well featured, and their iPhone application tipped me over the edge. I also had many ideas to implement on the site, but ended up with no time - so at least someone else has already done it for me here.

As for hghub, the project stalled due to other commitments, and the fact that git has grown on me, and I’ve switched to it and GitHub. For those looking for the same kinda thing for mercurial, please check out bitbucket.org (Thanks Dennis!). I’ve had a quick look at it, and it looks impressive.

Lastly, the project I’ve been working on lately is now coming to fruition - please go check out stripe.com and tell me what you think!

Shell Meme

I ran

1
history|awk '{a[$2]++} END{for(i in a){printf "%5d\t%s\n ",a[i],i}}'|sort -rn|head

and got this:

1
2
3
4
5
6
7
8
9
10
100	cd
62	ls
60	git
28	ssh
26	hg
19	mate
17	psql
15	sudo
15	mv
14	rake

Looks like I’ve spent too much time looking for things, and not enough time working on them.

Information management, pt. 1

This is a quick post, as you may notice there is a new “Notebook”:http://preview.evernote.com/pub/lstoll/public/ option in the sidebar. I’ve decided to open up some of my notes from now on in a public format, because a lot of the good stuff is there - useful information, that I never get time to write up. So check it out, and beware - it can be pretty raw. Big props to “evernote”:http://evernote.com for this - their new beta is a pretty good notetaking app in its own right, but combined with the online service and syncing - it becomes awesome, and makes something like this possible. I also plan on integrating search with it somehow.

Which leads me on to one of my favorite topics - information management. I seem to go through so much information and generate so many notes it’s not funny, and trying to look after it is difficult. I’ve settled on Evernote and EagleFiler for now. Evernote is great for note taking and jotting things down wherever I am, and EagleFiler works well for storing larger documents, manuals etc. I also use a bunch of other tools around this - I plan on writing up some more of my processes here real soon, so keep an eye out. Also, if you have any tools or methods you find indispensable please let me know - I’d love to hear.

EC2 Persistent Storage

I got an email from Amazon yesterday, talking about persistent storage for EC2 - Based on the email (full text below). From what I can see this works almost like a SAN, which is awesomely cool - you can store you database on here, and if your DB server dies, just start a new instance, and mount the same filesystem on it. It also supports snapshot backups to S3 - both MySQL and PostgreSQL can work with this. It’s adding a SAN service to go with the storage and hosting services that amazon already provide. Can’t wait to see the pricing..

I think this takes EC2 away from being a cool idea, and turns it into a serious hosting platform. Bring it on!

The email from Amazon:

Read more »

Quick guide to making an iPhone work in Australia (1.1.4).

I’ve been working with the iPhone since it came out, and I’m amazed at how far everything has come, back from coding up the first TurboSIM hardware hack and all the messing around for jaikbreak and activation, to now where it’s just point a click. Really, only two steps are needed: The first is to unlock and activate the phone which I won’t cover here, as there are good references elsewhere, the second is to tweak it for Australian Carriers (Telstra,. Optus, Vodafone and Virgin have been tested by myself)

First, unlock according to this guide: “Mac”:http://www.iclarified.com/entry/index.php?enid=893 “Windows”:http://www.iclarified.com/entry/index.php?enid=849
Then, tap on installer on the home screen. Tap on sources at the bottom right. Tap edit, then add. Enter http://wpool.com/iphone , then tap OK. Wait for it to refresh the sources, then tap on Install on the bottom of the screen. Scroll down to the localisation (1.1.4) menu, then for each item in there tap on it, then tap install. Once they are all down hold down the power button to turn the phone off, then turn it back on - and enjoy!

Sorry if this is a little short - kinda busy right now!

Passenger (a.k.a. mod_rails)

Passenger is now available for download - http://www.modrails.com . If you haven’t heard of it, is basically an apache module for running rails apps - nice and easily. I’ve just moved it over to this site, and it was incredibly easy. The install on my ubuntu server went like this:

1
2
3
sudo apt-get install apache2-prefork-dev libapr1-dev
sudo gem install passenger
passenger-install-apache2-module

I then added the apache config lines to the end of the apache config, and set my site up like:

1
2
3
4
5
6
7
<VirtualHost *:80>
ServerName lstoll.net
DocumentRoot /home/xxx/sites/lstoll.net/current/public
ServerAdmin xxx@xxx.net
ErrorLog /home/xxx/logs/lstoll.net_error.log
CustomLog /home/xxx/logs/lstoll.net_access.log combined
</VirtualHost>

Then, when apache started up it automatically started the rails app, and it just worked. It’s simple to use with capistrano, here’s my deploy tasks from deploy.rb:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace :deploy do
  desc "Custom restart task for passenger"
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{deploy_to}/current/tmp/restart.txt"
  end
 
  desc "Custom start task for passenger"
  task :start, :roles => :app do
    # Don't need to do anything, it's automatic
  end
 
  desc "Custom stop task for passenger"
  task :stop, :roles => :app do
    # currently no way I know of to 'stop' the app
  end
 
end

Once that is done, capistrano can flag to passenger to restart the app.

A bit of casual benchmarking shows it’s fast too. I’m very happy this is out there, it makes running rails apps as easy as PHP - saving all the messing around with mongrel/thin/monit. It also works with rails caching, so so more messing around with rewrite rules to get cached files to be read right off disk. This should hopefully make rails better on shared hosts, and lower the barrier of entry. Only downside is that this is currently rails only - so for merb/camping/anything else the old way is still needed. I’m hoping that soon passenger will support rack, or mod_rack/mod_rubinius will come out, so this ease is brought to all ruby frameworks.

Stand-alone ActiveRecord migrations

Currently working on a merb project using datamapper - nice framework, but the auto-migrate feature is fairly limited - So I decided to hook up ActiveRecord’s migrations into the app. This code could be equally as easily adapted in to anything else.

First, I created a folder for the migrations to live in:

1
mkdir -p db/ar_migrations

I then appended a few tasks ripped out of Rails and slightly tweaked to the Rakefile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
APP_BASE = File.dirname(File.expand_path(__FILE__))
 
namespace :db do
  task :ar_init do
    # Load the database config
    require 'active_record'
    database_yml = YAML::load(File.open(APP_BASE + "/config/database.yml"))
    init_env == "rake" ? current_env = "development".to_sym : current_env = init_env.to_sym # Default to dev env, symbolize
    ActiveRecord::Base.establish_connection(database_yml[current_env])
    # set a logger for STDOUT
    ActiveRecord::Base.logger = Logger.new(STDOUT)
  end
 
  desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
  task :migrate => :ar_init  do
    ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
    ActiveRecord::Migrator.migrate(APP_BASE + "/db/ar_migrations/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
    Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
  end
 
  namespace :schema do
    desc "Create a db/ar_schema.rb file that can be portably used against any DB supported by AR"
    task :dump => :ar_init do
      require 'active_record/schema_dumper'
      File.open(ENV['SCHEMA'] || APP_BASE + "/db/ar_schema.rb", "w") do |file|
        ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
      end
    end
 
    desc "Load a ar_schema.rb file into the database"
    task :load => :ar_init do
      file = ENV['SCHEMA'] || APP_BASE + "/db/ar_schema.rb"
      load(file)
    end
  end
end

These will read from database.yml in config/ , so make sure you’ve got datamapper set up.

Lastly, Let’s create an example migration to create the datamapper sessions table in db/ar_migrations/001_create_dm_session_table.rb:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class CreateDmSessionTable < ActiveRecord::Migration
  def self.up
    create_table(:sessions, :id => false) do |t|
      t.string :session_id, :null => false
      t.text :data
      t.timestamp :updated_at
    end
    # Need this because ar in unhappy with a varchar primary key
    sql = "ALTER TABLE sessions ADD CONSTRAINT sessions_pkey PRIMARY KEY  ( session_id )"
    execute(sql)
 
    add_index :sessions, :session_id
    add_index :sessions, :updated_at
  end
 
  def self.down
    drop_table :sessions
  end
end

Once this is done, you can run rake db:migrate , and the DB will get the sessions table added. The db:schema:load task is also there, so you should use this when you first deploy your app to a new server. The naming is also consistent with rails, so capistrano should interact with it out of the box, with the exception that the environment to load/migrate needs to be called MERB_ENV instead of RAILS_ENV

When creating additional migrations you will need to follow the ‘proper’ naming scheme: the filename should start with an incrementing three digit number, and the rest should be a ‘flattened’ version of the class name. (i.e migration class AddPostTable becomes add_post_table).

Postgres Plus 8.3 + Ruby

EnterpriseDB have done some reshuffling, and have release a package called Postgres Plus - contains their tweaked version of postgresql bundled with some other pieces for a bunch of platforms including mac - well recommended.

I did have a few problems getting the postgres gem working with it - here’s what I had to do

*Mac OS X:*

1
2
PATH=$PATH:/Library/PostgresPlus/8.3/bin/
sudo gem install postgres -- --with-pg-include=/Library/PostgresPlus/8.3/include --with-pg-lib=/Library/PostgresPlus/8.3/lib/ ARCHFLAGS='-arch i386'

*Linux:*

1
2
3
4
PATH=$PATH:/Library/PostgresPlus/8.3/bin/
sudo ln -s /usr/lib/libssl.so.0.9.8 /usr/lib/libssl.so.4
sudo ln -s /usr/lib/libcrypto.so.0.9.8 /usr/lib/libcrypto.so.4
sudo gem install postgres -- --with-pg-include=/Library/PostgresPlus/8.3/include --with-pg-lib=/Library/PostgresPlus/8.3/lib

You’ll probably want to make the PATH change permanent for access to psql.

And that should get you going. Those of you who use postgres should definately check it out at “http://www.enterprisedb.com/”:http://www.enterprisedb.com/ - and for those using any other DB it’s worth checking out too.

SSL/HTTPS Support error with MacPorts Mercurial 1.0

I recently upgraded to mercurial 1.0 using macports, and when I tried to communicate with a HTTPS repository I got the following error:

1
abort: Python support for SSL and HTTPS is not installed

The solution was simple:

1
sudo port install py25-socket-ssl

After that, HTTPS operations worked fine.

Installing Mercurial on Ubuntu 7.04

I’ve finally decided to bite the bullet and move to a distributed VCS - after looking around it seems that mercurial is the way to go. There is a TextMate bundle for it, and NetBeans plugin, Trac plugin, and seems to be well supported. I also looked around and particularly at git - however even though its name comes up often, it doesn’t seem to have anywhere near the support.

So this is a little document I put together on how I got it up and running on my Ubuntu 7.04 server, with trac support and web access. This document extends my previous setup doc which as of yet unpublished - to it is assumed you already have trac and subversion installed, with a htpasswd file for authentication against them located at /etc/apache2/projects.htpasswd - please adjust the references to this below to suit your environment. You will also need to make changes to the apache config file to suit your naming etc.

Read more »

Next Page »