Tag: Programming

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

Email Click-Through Tracking

Posted by – June 4, 2008

In my work as a Network Administrator for a school district, I run into problems with email click-through marketing techniques rather frequently. The specific problem is with click-through tracking of email advertising campaigns. Since we are a school district that provides internet access to minors, we tend to filter our internet traffic rather heavily. This filtering wreaks havoc with most click-through advertising emails.

For instance, an email is received inside of our network with a link to:

<a href="http://www.rs6.net/?kna76dv978y34qtib33t897jk1bt4hq3fr897&site=www.theactuallink.com">www.theactuallink.com</a>

The user thinks that when they click on theactuallink.com that they will be taken to theactuallink.com, they are instead taken to rs6.net and then bounced through to theactuallink.com. This causes a great deal of frustration with our users. We constantly receive phone calls that our internet filter is blocking theactuallink.com, when it is in fact blocking rs6.net, and rightfully so.

I imagine that this problem will only increase as more and more companies increase the amount of internet filtering they do to comply with various laws and regulations. So, what is the solution?

I would highly recommend never, ever rely on a 3rd party to bounce your links through. If you need to track the effectiveness of an email advertising campaign, then invest the time and resources to roll your own tracking. That or use a tool like Google Analytics that will not break the link even if the tracking itself gets blocked. I know that a large number of the emails are generated by non-profit organizations or businesses with limited budgets that are running their email advertising campaigns through a 3rd party, but I think the time has come to abandon the 3rd party and either hire the talent or develop it from within to avoid losing your audience entirely. There are a large number of free, open source applications that will allow you to run email advertising campaigns so the cost for software would be negligible. Hardware costs and requirements are ever decreasing as well, so the excuses not to are few.

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.

The best just keep on getting better – Google Maps

Posted by – November 28, 2007

Google Maps has added a new feature called “Terrain”. It overlays a street map on top of a terrain map. While this feature isn’t particularly useful for your everyday mapping needs, it could prove useful in a number of scenarios. What’s more, it is just another example of Google continually improving it’s products.

Google Maps with Terrain

xkcd = funny

Posted by – October 10, 2007

I have seen a few of the comics from xkcd and have found them to be rather funny (although I don’t know what that says about me…). Anyways, check it out!

RoR 2.0

Posted by – October 1, 2007

Via: Ruby on Rails Weblog

Ruby on Rails turns 2.0 (but doesn’t want to celebrate yet). The wonderfully powerful and yet simple to use web framework has reached the 2.0 “preview-release” milestone. According to the venerable DHH, the actual release date for a finalized 2.0 will be some time in the future, after a number of (potential) release candidates. While I don’t understand most of what they have changed, I am happy to see Ruby on Rails moving forward while continuing to gather followers.