skip main content

Archive for July, 2006

Grand Theft Auto: Lego City

posted by Duncan at 11:24 pm on July 27th, 2006

Someone’s re-made the intro to Grand Theft Auto…. in Lego. Brilliant.

Here’s a direct link to the LEGO movie.

Ruby one liners via the command line

posted by Duncan at 11:18 am on July 23rd, 2006

David P Thomas has been collecting Ruby one-liners and sticking them in a single text file for us all to enjoy. The list looks like it hasn’t been touched in a while but has has proven to be very useful for me.

Shame it’s in a .txt file as finding the ones that would be helpful requires memorising them all, or searching through and hoping to find the one you’re after. Great stuff all the same though.

New Omnigraffle stencil for Rails

posted by Duncan at 2:43 pm on July 22nd, 2006

Ruby on Rails Omnigraffle stencil by metaskills.netMetaskills have created a new Omnigraffle stencil for Ruby on Rails. Omnigraffle is a great OSX tool for creating visulisations of any kind. If you use OSX then its a must for this type of thing.

It says it’s semi-complete but it seems to have the basics you’ll need to create a rails project model schema.

Arrested Development 3rd Series

posted by Duncan at 8:31 am on July 18th, 2006

I’ve just had the pleasure of watching the final series of Arrested Development (I don’t have SKY). I’ve mentioned the previous series of this fantastic sitcom before and the third series doesn’t disappoint. It picks up where the last one left with Michael Bluth (Jason Bateman) searching for his runaway father, George Sr. (Jeffrey Tambor) and GOB (George Oscar Bluth II; pronounced “Jobe”) played by Will Arnett gets an invitation to a father/son reunion outing, and believes it to be George Sr. trying to contact him.

Arrested Development

There are new characters, Julia Louis-Dreyfus, Charlize Theron, and Amy Poehler play recurring characters, but my favourite purely for his character name is Scott Baio as attorney Bob Loblaw (pronounced, “Ba blah blah”), a replacement for Barry Zuckerkorn (Henry Winkler), in part, because he “skews younger” (an allusion to Baio’s “Happy Days” character “Chachi,” who was brought in to inject youth into the aging Winkler’s “Fonzie”). There is also a strange James Bondy type flavour in the early episodes.

For the best experience you really should watch these shows in batches as one show rolls straight into the next. Boo Hoo that this is the last series.

My first run using the NIKE+iPod pedometer

posted by Duncan at 12:49 pm on July 15th, 2006

UPDATE: Do you also need those special Nike Trainers? NO, see below.

I got the latest product from Apple and Nike yesterday on the way home from work. I do a bit of running and use a Heart rate monitor but the having a pedometer is much easier for pace setting. I did a quick 2.5 mile run this morning and I love this thing already. Just plug it into your ipod and press go, and you’re off!

My first run using the Nike+Ipod pedometer

You can choose your distance or run free and once you start your run you get feedback straight away from either a male or female voice. Once I had finished my run I just plugged in the ipod and itunes asked if I wanted to sync with the Nike site. The photo you see above is the result. As you can see I overcooked my run a bit and petered off at the end. As time goes on it will be intersting to see if my running improves.

Nike ipod puck in non-Nike shoe

UPDATE One thing I forgot to say was that I don’t own and did not want a pair of those special Nike trainers that have the hole in the sole for you to stick your pedometer in. I just used my normal running shoes and manged to fit the pedemeter to them with a bit of persuading

Snowboarding in the sun

posted by Duncan at 6:03 pm on July 12th, 2006

I’ve just come back from another great 4 days riding the glacier in Tignes. This trip is becoming a yearly event between me and a few friends and this years ruled as much as the last.

Tignes 2006

We had the best weather, and the snow although not awesome, was as good as expected considering it was 22deg at the top. About 10.00am you get for me the absolute best conditions as the snow is hard enough to play and soft enough not to hurt yourself (oops, tempting fate). We even hired Downhill Bikes this year and gave them a blast from the top ( we had helmets but the armour hadn’t arrived ) which made it a exciting. These bikes ( Big Hits ) have 8 inches of front/rear travel and just sucked up the bumps.

I’ve stuck all the photos up on Flickr as has Martyn. Go view them and make yoursekf feel very jealous.

Another tag cloud script for Ruby on Rails

posted by Duncan at 9:09 am on July 6th, 2006

Or any other Ruby program really. I know there are attempts already out there but none that really suited my purposes. I needed a simple way of creating that tag-cloud-look for many situations. I needed a tag cloud by size or by colour and I didn’t want it to do everything, just provide me with the style attributes I needed to get the job done. Below is an example of what gets returned by default:

font-size:16px;color:rgb(70,70,70);

Here’s the code; it comes with no warranty.

With all these tags cloud scripts you really only need 3 parameters:

  1. The total counts of items – For example you have 10 tags each that has been used numerous times. The total counts would be all of the uses added together
  2. The minimum count of items in a batch – Using the example above this would be a count of the uses for the tag that has been used least
  3. The maximum count of items in a batch – Using the example above this would be a count of the uses for the tag that has been used most

Below is the actual script and then below that I have stuck a quick example of how you could use it.

def font_size_for_tag_cloud( total, lowest, highest, options={} )
  return nil if total.nil? or highest.nil? or lowest.nil?
  #
  # options
  maxf = options.delete( :max_font_size ) || 14
  minf = options.delete( :min_font_size ) || 11
  maxc = options.delete( :max_color ) || [ 0, 0, 0 ]
  minc = options.delete( :min_color ) || [ 156, 156, 156 ]
  hide_sizes = options.delete( :hide_sizes )
  hide_colours = options.delete( :hide_colours )
  #
  # function to work out rgb values
  def rgb_color( a, b, i, x)
    return nil if i <= 1 or x <= 1
    if a & b
      a-(Math.log(i)*(a-b)/Math.log(x)).floor
    else
      (Math.log(i)*(b-a)/Math.log(x)+a).floor
    end
  end
  #
  # work out colours
  c = []
  (0..2).each { |i| c && rgb_color( minc[i], maxc[i], total, highest ) || nil }
  colors = c.compact.empty? ? minc.join(',') : c.join(',')
  #
  # work out the font size
  spread = highest.to_f - lowest.to_f
  spread = 1.to_f if spread <= 0
  fontspread = maxf.to_f - minf.to_f
  fontstep = spread / fontspread
  size = ( minf + ( total.to_f / fontstep ) ).to_i
  size = maxf if size > maxf
  #
  # display the results
  size_txt = "font-size:#{ size.to_s }px;" unless hide_sizes
  color_txt = "color:rgb(#{ colors });" unless hide_colours
  return [ size_txt, color_txt ].join
end

and now a quick example of it’s use in a rails view. This code assumes the db find call looks something like this:

@foo = Foo.find( :all,
  :select => '*, COUNT(DISTINCT(i.id)) AS item_cnt',
  :joins => 'AS f INNER JOIN bars AS b ON f.id=b.foo_id',
  :group => 'b.id',
  :order => 'item_cnt DESC',
  :limit => 50
)

Below just loop through your db results and calls font_size_for_tag_cloud for each item, passing in the required parameters. There are a few options available but if you leave them out you should still see something useful.

<ul>
<% for f in @foo -%>
<%= content_tag( 'li', f.some_label, :style => font_size_for_tag_cloud( f.bars.size, 
  f.first.count_items, 
  f.last.count_items,  
) ) %>
<% end -%>
</ul>

That’s it! I guess I should turn it into a plugin but hey, there’s to much reading to be done on ActiveResource at the moment heyhey!


back to the top