Monthly Archives: January 2009

Generating N colors (Ruby)

Kevin messaged me a few days ago to give me a problem his boss had given him. Generate a list of colors that can be used when drawing n lines on a graph.  My first solution was to just pick 20 or 30 colors, put them an in a list and pick one of them for each graph, but I had a few other ideas.  One of them seemed stupidly-simple, so I threw it together in ruby and had it generate an html page to display the results.

maxColors = 250'colors.html', 'w') do |myfile|  #create file
    myfile.print "nnn"
    1.upto(maxColors) { |tblcnt|
        myfile.print "n"
        1.upto(tblcnt) { |rowcnt|
            newColor = (rowcnt * (0xFFFFFF/tblcnt)).to_s(16)
            myfile.print "n"
        myfile.print "
n" } myfile.print " nn" end

Here are the results from my code:

Click for html (warning 1MB file)

Click for html (warning >1MB file)

The code basically takes 0xFFFFFF, divides it by n and displays each color.  It’s a simple hack, but the patterns it generated were just incredible.  Most of the color lines aren’t distinct enough to use in graphing, so it doesn’t really match what Kevin asked me to do.  Oh well, it was a fun little script to write.

Work on my new house

Stripped-away garage ceiling

Stripped-away garage ceiling

I got the keys to my house last Wednesday and have been working on it almost non-stop since.  I decided to start on the garage, tear out the paneling and have a new door installed before I move in.  My dad and I removed the paneling and saw that there was some framing tomfoolery, so we decided to redo all the garage framing while we’re working on it.   The garage was also crappily-carpeted,  so we tore that out and spent nearly a day scraping the carpet glue off the floor.


In between scraping crap off of the garage floor I finally took the time to tear up the carpets in the bedrooms.  Three of the four bedrooms have pristine hardwood floors.  Awesome!  The Master bedroom floor is trashed, but this means I can just carpet the master and leave the other floors as-is.

KHAN! (Ruby)

This evening I read a story on reddit in which someone graphed the number results google gives vs. the number of A’s in “KHAN.”  KHAN! is from the second Star Trek Movie, “The Wrath of Khan.”  The original results from that article are here.  I thought it was pretty funny, so I decided to write a ruby script to automatically do the same thing (I’ve been using ruby a lot lately).

require 'gruff'
require 'open-uri'

dataToGraph =
khanNumOfAs = 1
maxKhanAs = 100

g =
g.title = "KHAN!"

    sleep 0.5
    open('' + "A"*i + "N") do |f|
        f.each do |line|
            dataToGraph[i] = $~[1].gsub(/,/, "").to_i if /of about ([0-9,]+)/.match(line)
    print "KH#{"A"*i}N!!!!!    results: #{dataToGraph[i]}n"
}"KHAN!", dataToGraph)

Kevin helped me with the regular expressions to get the number of results out of google.

Final results, no log scale :-(

Final results, no log scale 🙁