Nathan Colgate RSS

This is the personal blog of Nathan Colgate Clark. I work at Brand New Box. I developed a content management system for churches.

Archive

May
6th
Fri
permalink

Mac Bash / Shell Script To Launch Development Environment

As my rails apps get more complex, I find myself spending more time getting them booted up.  While this may not be a big deal for you, my early morning brain doesn’t do well with it.

After a bit of searching I found some code for launching rails server in a new terminal tab, opening text mate, launching delayed job in a new terminal tab, and opening the browser.

I put this in a file called rock_and_roll.sh in my Rails.root folder:


#!/bin/sh
osascript -e 'tell application "Terminal"' \
-e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
-e "do script with command \"cd ~/path/to/my/app/;rails server;\" in selected tab of the front window" \
-e 'end tell' &> /dev/null

osascript -e 'tell application "Terminal"' \
-e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
-e "do script with command \"cd ~/path/to/my/app/;rake jobs:work;\" in selected tab of the front window" \
-e 'end tell' &> /dev/null

mate .

open http://localhost:3000

Then all I gotta do:


$ cd /path/to/my/app/
$ . rock_and_roll.sh
Jan
31st
Mon
permalink
Jan
26th
Wed
permalink

Drag and Drop Paths in Raphael JS

The key here is to convert the x and y deltas into translate values, which the path object understands.

jQuery(function () {

  var startPath = function () {
    // path coordinates are best kept as relative distances
    // so that you can use the built in translate method
    this.ox = 0;
    this.oy = 0;
  },
  movePath = function (dx, dy) {
    // move is called with dx and dy, which we convert
    // into translate values, which are reset at the end
    // of the function
    var trans_x = dx-this.ox;
    var trans_y = dy-this.oy;
    this.translate(trans_x,trans_y);
    this.ox = dx;
    this.oy = dy;
  },
  upPath = function () {
		// nothing special
  };

	var fly_paper = Raphael('application',500,500);
	var fly_path = "M28.589,10.903l-5.828,1.612c-0.534-1.419-1.338-2.649-2.311-3.628l3.082-5.44c0.271-0.48,0.104-1.092-0.38-1.365c-0.479-0.271-1.09-0.102-1.36,0.377l-2.924,5.162c-0.604-0.383-1.24-0.689-1.9-0.896c-0.416-1.437-1.652-2.411-3.058-2.562c-0.001-0.004-0.002-0.008-0.003-0.012c-0.061-0.242-0.093-0.46-0.098-0.65c-0.005-0.189,0.012-0.351,0.046-0.479c0.037-0.13,0.079-0.235,0.125-0.317c0.146-0.26,0.34-0.43,0.577-0.509c0.023,0.281,0.142,0.482,0.352,0.601c0.155,0.088,0.336,0.115,0.546,0.086c0.211-0.031,0.376-0.152,0.496-0.363c0.105-0.186,0.127-0.389,0.064-0.607c-0.064-0.219-0.203-0.388-0.414-0.507c-0.154-0.087-0.314-0.131-0.482-0.129c-0.167,0.001-0.327,0.034-0.481,0.097c-0.153,0.063-0.296,0.16-0.429,0.289c-0.132,0.129-0.241,0.271-0.33,0.426c-0.132,0.234-0.216,0.496-0.25,0.783c-0.033,0.286-0.037,0.565-0.009,0.84c0.017,0.16,0.061,0.301,0.094,0.449c-0.375-0.021-0.758,0.002-1.14,0.108c-0.482,0.133-0.913,0.36-1.28,0.653c-0.052-0.172-0.098-0.344-0.18-0.518c-0.116-0.249-0.263-0.486-0.438-0.716c-0.178-0.229-0.384-0.41-0.618-0.543C9.904,3.059,9.737,2.994,9.557,2.951c-0.18-0.043-0.352-0.052-0.516-0.027s-0.318,0.08-0.463,0.164C8.432,3.172,8.318,3.293,8.23,3.445C8.111,3.656,8.08,3.873,8.136,4.092c0.058,0.221,0.181,0.384,0.367,0.49c0.21,0.119,0.415,0.138,0.611,0.056C9.31,4.556,9.451,4.439,9.539,4.283c0.119-0.21,0.118-0.443-0.007-0.695c0.244-0.055,0.497-0.008,0.757,0.141c0.081,0.045,0.171,0.115,0.27,0.208c0.097,0.092,0.193,0.222,0.286,0.388c0.094,0.166,0.179,0.368,0.251,0.608c0.013,0.044,0.023,0.098,0.035,0.146c-0.911,0.828-1.357,2.088-1.098,3.357c-0.582,0.584-1.072,1.27-1.457,2.035l-5.16-2.926c-0.48-0.271-1.092-0.102-1.364,0.377C1.781,8.404,1.95,9.016,2.43,9.289l5.441,3.082c-0.331,1.34-0.387,2.807-0.117,4.297l-5.828,1.613c-0.534,0.147-0.846,0.699-0.698,1.231c0.147,0.53,0.697,0.843,1.231,0.694l5.879-1.627c0.503,1.057,1.363,2.28,2.371,3.443l-3.194,5.639c-0.272,0.481-0.104,1.092,0.378,1.363c0.239,0.137,0.512,0.162,0.758,0.094c0.248-0.068,0.469-0.229,0.604-0.471l2.895-5.109c2.7,2.594,5.684,4.123,5.778,1.053c1.598,2.56,3.451-0.338,4.502-3.976l5.203,2.947c0.24,0.138,0.514,0.162,0.762,0.094c0.246-0.067,0.467-0.229,0.603-0.471c0.272-0.479,0.104-1.091-0.377-1.362l-5.701-3.229c0.291-1.505,0.422-2.983,0.319-4.138l5.886-1.627c0.53-0.147,0.847-0.697,0.696-1.229C29.673,11.068,29.121,10.756,28.589,10.903z";
	var fly;
	fly = fly_paper.path(fly_path);
	fly.translate(250,250);
	fly.scale(4, 4);
	fly.attr({
		'stroke-width': 0,
		'fill': '#cccccc',
		'fill-opacity': 1.0
	});
	fly.drag(movePath, startPath, upPath);
	
});
Jan
3rd
Mon
permalink
Oct
20th
Wed
permalink

Simulating PROPFIND Request Using Curl on Rails App

curl —data “<xml></xml>” —header “Content-Type: text/xml” —request PROPFIND localhost:3000/one/two/three

Sep
24th
Fri
permalink
permalink

Lessons Learned PostgreSQL on Mac OS X

Like many Rails shops out there, we are moving all our servers into the cloud.  A few legacy projects, and certainly all new ones.  Our cloud of choice: Heroku.  I’ve been a Heroku fan since the first time I tried deploying an app on their system… and it just worked.  They’ve been a fantastic solution, with almost no hiccups, until this past week when I ran into problems with the inconsistencies between MySQL (on my machine) and PostgreSQL (on Heroku).

Here are some of the lessons learned while trying to install PostgreSQL 8.3.x on my Mac OS X 10.5.8 machine:

Out of the Box

I went for the low hanging fruit and tried using http://www.postgresqlformac.com/.  Everything seemed to run smoothly, no errors, no warnings.  But there was also no confirmation, no clear next step, no information to test the installation and get started with postgresql. For all I know, I had PostgreSQL up and running on my machine, but because there was no documentation on how to ‘get started’, I had no clue what to do next.

To the wonderful people at postgresqlformac.com: your product may be wonderful, but self installers are geared towards postgres noobs (like myself) so treat me like a noob and walk me through starting/stopping the server, creating a db, etc…

Back in the Box

I had to follow (roughly) this shell script (http://www.postgresqlformac.com/news/archived_news/uninstall_835.html) to try to uninstall the system.  The only thing that wasn’t working was getting rid of the ‘postgres’ user the system had generated.  This wasn’t an apparent problem until I tried the next method of installing (below), which called for me to add the ‘postgres’ user through System Preferences.  Despite not having a ‘postgres’ user in the account list, the system was prompting me with “name is used by another user”.  So apparently there was some kind of hidden user that OS X was not picking up on.

Quick fast forward to the solution: http://www.oreillynet.com/mac/blog/2006/04/deleting_mac_os_x_users_remote.html

I had to use the ‘dscl’ command line tool to remove the postgres user and group.

By the Book

For attempt number 2, I decided to follow the official Apple Developer documentation: http://developer.apple.com/internet/opensource/postgres.html.

Everything went smoothly and now i can start up a postgresql server with relative ease from terminal:

$ su postgres
$ cd ~
$ export PATH=$PATH:/usr/local/pgsql/bin
$ pg_ctl -D /usr/local/pgsql/data -l postgres_logfile start

Or without a log

$ pg_ctl -D /usr/local/pgsql/data start

Look at all those happy processes:

$ ps waux | grep postgres

And stop it:

$ pg_ctl -D /usr/local/pgsql/data stop

Creating a database

$ createdb railsapp_development

Gem Please

I must have lucked out big time because all i had to do was run:

$ sudo gem install pg

And I got “Successfully installed pg-0.9.0”. I don’t think that has ever happened on any complex gem issue for me before.

Rails Now Too

Gemfile:

gem ‘pg’

A little bit of this:

$ bundle install

database.yml (using the same ‘postgres’ user and password i created in System Preferences)

development:
  adapter: postgresql
  database: application_development
  username: postgres
  password: secret

And whadya know:

$ rake db:migrate

It works! Now all I’ve got to do is repopulate the database.

permalink
Sep
13th
Mon
permalink
Aug
27th
Fri
permalink