PSA: Don’t Generate Offensive Promo Codes

OK folks, I’m now on my 3rd client having problems with certain four letter words coming up in their automatically generated promo codes. It’s easy to get around this problem in a very simple way: Don’t use vowels in your promo codes if you’re using letters. No need for special filtering software or huge lists of banned words. You can always add complexity later, but that simple rule will help you more than the rest.

If you want to get more careful, you could alternate letters and numbers, or use some other strategy. To be kind to your users, be aware that some numbers and letters look the same to people and they will enter your codes wrong (or worse, enter in someone else’s code by mistake).

To help you, here’s a list of the numbers and letters I suggest people use because they won’t get them confused with each other and hopefully your system won’t create any bad words (if they do, let me know). If you’re worried about the number of combinations you can make, just add more characters to the length of your code or allow yourself the option to generate your own special codes.

letters = [‘B’, ‘C’, ‘D’, ‘F’, ‘H’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’]
numbers = [2, 3, 4, 7, 9]

You could then take this and make a simple ruby method that does something like this:

letters = ['B', 'C', 'D', 'F', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z']
numbers = [2, 3, 4, 7, 9]
promo_set = letters | numbers # combine arrays
promo_code = promo_set.sort_by{rand}[0..14].to_s # randomize array and take the first 15 elements and make them a string
=> "CS4FZLHVMPK3QJN"

Install Old Versions of Ports Using MacPorts

MacPorts is my preferred way of installing, managing, and upgrading much of the software I have on my Mac.

I’m setting up a new work machine today and I need to install ruby 1.8.5 on my machine for Rails to be happy.

Unfortunately, you can’t do something simple like specifying the version of the port you want to install unless it’s in a local repository.

Fortunately, my friend Stephen Chu had this problem about a year ago and has a nice procedure on how to do it. I’m going to update it for MacPorts and ruby 1.8.5 here.

1) Find out the svn revision number of the Portfile that has 1.8.5 by looking at:
http://trac.macosforge.org/projects/macports/log/trunk/dports/lang/ruby/Portfile
In my case it is 21127.

2) Set up a local port repository. In the file /opt/local/etc/macports/sources.conf, add this line before the rsync line:
file:///Users/Shared/dports and create that directory.

3) Install the port into your local repository.

cd /Users/Shared/dports && svn co --revision 21127 http://svn.macports.org/repository/macports/trunk/dports/lang/ruby/ lang/ruby/

4) Run portindex so that ports now finds your new (old) version of ruby.

portindex /Users/Shared/dports

5) Now you should be able to see ruby @1.8.5-p12 in addition to @1.8.6 by running:

port list

6) Install Ruby

sudo port install ruby @1.8.5-p12

You should be up and running now, so to check, run:

ruby -v

You will see something like this:

ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-darwin8.10.1]

Now, if you want versions of ruby that MacPorts doesn’t have (later patchlevels for instance), you can modify the portfiles by hand, but I’ll leave that for another post.

Update: There is an “official” MacPorts HOWTO on installing older versions of ports here. It may be updated in the future, so I’m linking to it here: http://trac.macports.org/wiki/howto/InstallingOlderPort

Install Old Versions of Ruby Gems

I am setting up a new machine that has some old software requirements for my project this week. A quick tip if you need gems to be installed at an older version (if they are still available).

Use the -v version flag to specify which version you want.

sudo gem install capistrano -v 1.4.1

If you’ve got the newer versions of the capistrano gem, no need to fret. You can specify the version you want to use on the command line like this:

cap  _1.4.1_  deploy

You can alias that to something else in your bash profile by adding something like this:

alias cap1='cap  _1.4.1_'

RubyConf.new(2006)

I attended the annual Ruby Conference this year in Denver, CO courtesy of ThoughtWorks. Lots of fun was had by all. I met up with a few people from caboose that I hadn’t seen since last year and had some friends like Evan Phoenix do some talks.

The conference was a good chance to meet up with some other ThoughtWorkers and have fun in a city I haven’t been to before.

I also snuck out at night to go to SkyVenture and do a little indoor night-skydiving. That was definitely an experience I’ll have to have again.

Until next year…

Getting Weird Rails Errors?

Having trouble with rails on OS X? Are you getting something like this message?

`require': No such file to load -- rubygems (LoadError)

Then the ruby binary may have been replaced on your machine by Apple in an update recently. The fix is just to remove Apple’s version in /usr/bin or to change your bash profile to load your version of ruby first.