Category: Programming

Installing tools for Rails development

Posted by – March 1, 2010

I have long been a fan of the various tutorials written by Dan Benjamin at Hivelogic for installing the various components of a Ruby on Rails development environment. Some of these articles are:

Recently, however, I have found a new way to install Ruby, RubyGems and Rails. This new method allows for a simple installation and switching between different versions of Ruby. Enter, Ruby Version Manager (aka RVM). Once installed and configured, installing Ruby is as simple as:

rvm install 1.9.1

I was introduced to this magical tool via a screencast from Ryan Bates on Railscasts entitled: Rails 3 Beta and RVM

Ruby on Rails, Passenger & MySQL PATH issues in Snow Leopard

Posted by – September 8, 2009

I recently did a clean installation of Snow Leopard, which is great by the way, and I ran into some issues after installing MySQL and Ruby on Rails based on the instructions from Dan Benjamin at Hivelogic.

Specifically, when I would try to access a site in development mode I would get an error from Passenger that “Rails 2.3.4 could not be found”. I also noticed that on reboot my PATH wasn’t being loaded properly either so the system could not find MySql, Ruby, or RubyGems.

I tried placing the path information that, according to the instructions goes in ~/.profile into my ~/.bash_profile.

Now when I restart the system, MySQL and Ruby on Rail can be found! Passenger is working now as well. I am not sure if there was a change in the way Snow Leopard loads bash profiles or if there is just a problem with my installation that was preventing it from working when the PATH was specified in ~/.profile, but it’s all working now so hopefully this will help someone else.

Make OSX Terminal pretty

Posted by – August 31, 2009

I have always been annoyed with how a new tab opens in the OSX Terminal. I have my Terminal set to run “source ~/.bashrc” when the application starts. The problem with this is that it won’t run for new tabs, and I use lots of tabs (Rails development, web server, database, ruby console, etc…). And while I have been annoyed, it never really bothered me enough to look for a solution, until today.

As is usually the case, a quick search in Google led me to “Customizing the terminal prompt on Mac“. Apparently, OSX handles the terminal profiles a little differently than what I am used to. OSX uses profiles, where Ubuntu uses .bashrc. So, just add one line in your terminal profile to tell the terminal run the necessary command to load your .bashrc like so:

  1. First open up your ~/.bash_profile in your text editor of choice
  2. Add the line “source ~/.bashrc”
  3. Save and close ~/.bash_profile

Easy as can be! Now set your .bashrc to make your terminal as color-coded and informative as you want it to be. There are a lot of tutorials and information available for editing your .bashrc file.

Updating Ruby on OSX Leopard

Posted by – May 13, 2009

Quick and easy method for updating, or rather installing an updated version of Ruby on OSX Leopard (10.5) from Hivelogic. Ruby ships with OSX Leopard which is great, but the version included is outdated in regards to the recommendations of the Ruby on Rails folk.

This method seems to be the best way because it doesn’t overwrite what Apple has shipped with OSX, rather it just tells the computer to keep the older version, but use the newer version in it’s stead. Of course, this does require some command line shenanigans, but once you get started it really isn’t all that difficult. Besides, if you are concerned about using Ruby and/or Rails you should be comfortable using the command line!

Some Git goodness

Posted by – May 11, 2009

A project I am working on has a configuration file that contains a few variables for using Microsoft’s Active Directory to authenticate to a Ruby on Rails application. This is working great, but I was banging my head against a wall trying to get Git to not track changes to the configuration file. I didn’t want my username and passwords tracked in GitHub for obvious reasons, but I did want a generic copy of the configuration file in the repository.

While searching for a solution today, I ran across this little gem of an article titled “GIT: ignoring changes in tracked files” from Pagebakers.nl, the salient code is below:


git update-index --assume-unchanged <file>

Add weekdays in Ruby on Rails

Posted by – March 9, 2009

I am working on an application where I need to be able to add 3 week days to today’s date. Unfortunately there doesn’t seem to be any built-in functionality for this in Ruby, so I needed to roll my own. At first I searched Google hoping someone had already solved the problem for me, which is most often the case. Not so with this problem. I did however come across this post on Platte daddy, which provided a good starting point, but was designed to simply add 1 weekday, not any number of days that I want.

I ran through a number of iterations until I came up with this helper method:


def add_cwdays(date, n)
#Add number of weekdays plus necessary weekend days
date += n.days + (2*(n/5.floor)).days
#If the above lands on a weekend, keep adding days until it is a weekday
date += 1.days until (1..5).member?(date.wday)
date
end

This was added to my ApplicationHelper.rb file and is called for adding 3 week days to today via:


add_cwdays(Time.now, 3)

I created a helper to DRY the method and I wrote it so that the starting date and the number of workdays is variable. The helper has only 2 lines of code (after some re-factoring), which reduces the readability a bit, but it still makes sense I think.

The first line simply adds the desired number of weekdays, plus any weekend days that would be within the range of week days. If we wanted to add 8 weekdays, we would need to add 10 total calendar days (1 weekend). If we wanted to add 23 weekdays, we would need to add 31 total calendar days (4 weekends). If we wanted to add 4 weekdays, we would need to add 4 total calendar days (no weekends). The weekend addition is made with the (2*(n/5.floor)).days bit of code. Basically take the number of days “n”, divide by five, strip off the decimal and multiply by 2 (for Saturday and Sunday).

The second line of code deals with the eventuality of the first line landing on a weekend. If this happens, we simply add 1 day repeatedly “until” we reach a weekday.

This seems to be working well, if anyone looks this over and sees anything wrong or if there are any opportunities to re-factor and simplify, please post comments.

Linux server instructions

Posted by – January 20, 2009

Slicehost has some really nice tutorials and instructions for setting up a Linux server to get a website up and running. I just followed the tutorial for setting up a Ruby on Rails site being server by Apache using Passenger. If this sounds like a foreign language, well the names for software in the FOSS world can be a bit confusing but once involved in the process they become more familiar.

There are four basic steps that I followed:

1. Install and configure the server’s operating system (parts 1 & 2, Ubuntu 8.10 (aka Intrepid Ibex)
2. Install Ruby, Ruby Gems and Rails
3. Install Apache and Passenger and configure them to serve up a Rails site.
4. Make a website

Not too difficult, well, except for step #4! Ha! All told, the entire process takes about an hour (most of that spent downloading, installing and updating the software).

I think I Git it

Posted by – October 28, 2008

I just used Git for the first time and I think I finally understand what all the hullabaloo is about. Git is a distributed source control tool being used by the Linux and Ruby on Rails community.

The difference between Git and other source control systems like Subversion is that there is no need for a central repository for your source code. Your code remains completely distributed amongst the various machines and people that are working on it.
I currently use Subversion to maintain my source code, but I am thinking that I may like Git better.

UPDATE: To install Git on Mac OSX (10.5) I used the following, graciously taken from this forum post at Slicehost.

First, get the source code for the latest stable build here, then:

sudo apt-get build-dep git-core
tar xjf git-1.5.5.1.tar.bz2
cd git-1.5.5.1/
./configure
make
sudo make install

Posting from iPhone

Posted by – August 4, 2008

I just downloaded the WordPress application for the iPhone and iPod Touch. It was painless to setup and seems to work really well. One thing I would already like to see is automatic completion for tags. Other than that, A+!

IE8 – Full Standards Compliance

Posted by – March 3, 2008

via: Simple Bits

Some exciting news from the developers of Microsoft’s Internet Explorer 8! Basically they have reversed course on their previous decision to hamstring standards based web design by forcing IE8 to render all web pages in an identical fashion as IE7, unless explicitly told to do otherwise. Microsoft was planning on forcing web developers tell IE8 to render a web page according to web standards or else IE8 would render the page identically to IE7 (which has some shortcomings when it comes to standards).

This is definitely good news and I for one am glad to see Microsoft making a decision that makes sense for the web community at large.