life.i.think -

In the Name of All That is Holy, Highlight the OK Button!
Scribbled on April 27th. 0 comments.

If you are doing any Greasemonkey development, you’ve most likely noticed 2 quirks:

1. On the install script window, OK has no accessability key.

2. That annoying Success dialog that pops up after you install a script. (This might need to stay in for users, at least until we have it as an option in some options pane)

Both of these are just annoying enough to deserve attention when you’re developing greasemonkey scripts (clicking OK manually hurts my soul!), so …

gm_accessability.xpi 0.2.6

And the cooresponding patches:

install_xul_accessability.patch
remove_success_dialog.patch

Both of these should be applied in /chrome/greasemonkey/content with something like (if the patch files are in the same location):
patch -p0 < patch_name 

Lookup Tables in Rails
Scribbled on April 25th. 3 comments.

So look up tables are fun. Well, maybe not fun, but they are good for database integrity and all that jive. But how to do them cleanly in Rails?

Firstly, lets talk about database schemas. There are 2 primary ways to do lookup tables. One is to have a lookup table for each field. You end up with something like:

  lookup_genders
  -------------
  int id
  varchar description

  lookup_states
  -----------
  int id
  varchar description

This is a bit messy, as you can end up with a gazillion of these suckers in your database. Now, if you aren’t a normal form nazi, you can break the rules a bit and do something like:

  lookups
  -------
  int id
  varchar description
  varchar field_name

Now, this is populated with data like:

  [1, 'Male', 'gender']
  [2, 'Female', 'gender']
  [3, 'KY', 'states']

I’m using the latter for my rails app. Now when displaying the data in pure text form, I want the value of the id to be translated into its cooresponding description. So in the rails model that contains a lookup, I override the method to return that field with this (I’ll use gender as my example from here on):

  # for reading
  def gender
    # first we get the name of the function we're operating within.
    # this is done with the ruby Kernel#caller() method.
    db_field = caller(0)[0].match(/`(.*)'/)[1]

    @lookup = Lookup.find(:all, :conditions  => [ "field_name = ?", db_field])
    for i in @lookup
      if self[db_field] == i.id
        return i.description
      end
    end
    return 'lookup error!'
  end

Lookup.find just searches through our lookup table (it’s an empty model in rails).

Cool right? Now what about putting the data back in the database? Well the best way to deal with lookup data is with a dropdown. So I have the following.

In /app/helps/application_helper.rb:

  def lookup_dropdown(parent_record, lookup_field)
    name = parent_record + "[" + lookup_field + "]" 
    lookup = Lookup.find(:all, :conditions  => [ "field_name = ?", lookup_field])
    render_partial("shared/lookup_dropdown", {:name => name, :values => lookup})
  end

In /app/views/shared, add the file _lookup_dropdown.rhtml with the following contents:

  <select name=<%= name %>>
    <% for i in values %>
      <option value="<%= i.id %>"><%= i.description %></option>
    <% end %>
  </select>

Now, anywhere where you want a dropdown for this lookup/field you can use:

<%= lookup_dropdown "inmate", "gender" %>

Tada!

Mmmm, delicious!
Scribbled on April 23rd. 0 comments.

After much stalling and general hobobetry (i just made up that word), I have finally set up a del.icio.us site.

http://del.icio.us/lukewarmtapioca

And what better reason than bunny (lack of) sex?

Also, Jesse’s very super cool Amazon greasemonkey script is kicking ass on delicious/popular! I really need to start working on porting gm to Epiphany.

hackerwhatchi?
Scribbled on April 13th. 1 comment.

After Jesse whips out his little gem, how could I do anything but return the favor? (oh and Emily sent me so many good pics to choose from!)

Baby Jesus wants you to validate your HTML
Scribbled on April 12th. 1 comment.

I know this goes without saying in most cases, but please, PLEASE validate your HTML when developing with Rails (or any framework really)!

Nasty typos in HTML can have very adverse effects on embedded Ruby code. Recently, I had a <TABLE> I did not close properly in one document. Then, much later in the page, embedded in 2 layers of partials, some ajax fancy-pants-ness. Specifically, I was doing something like

<%= form_remote_tag :url => {:action => "save_note", 
                             :id => note.id}, 
                             :update => "row" + note.id.to_s %>
  <%= text_field "save_note", "note_text" %>
<%= end_form_tag %>

Well my little HTML snafu was causing some Ajax calls to work perfectly, but in this case, I was getting some very quirky results. They were accessing the proper action in the controller, but were not passing any of the form data into @params!

Now of course if I had simply reached up and clicked Validation->Validate HTML on my handy-dandy Web Developer Toolbar I could have saved myself a lot of grief. Lesson learned!

System.Money.Spending.Too.Much.Of
Scribbled on April 11th. 0 comments.

My new toy came in a few days ago … So today I bought 2 new sets of cans!

http://www.musiciansfriend.com/srs7/search/detail/base_pid/240274/src=01340 http://www.electronicscity.com/product_info.php?products_id=532&osCsid=a780a6c73dd58ee29309ab234ae76d34

Decided on both after reading up a bit on http://www.head-fi.com. Yes that’s right, the second pair were $10 after shipping.

Doing a bit more C# hacking, trying to finish up ‘the project that will not die.’ I needed to SQL-friendly-ize strings in my queries. Of course in Ruby you would do something like my_string.gsub(/’/,”’’”). In most languages this is called sub or replace.

In C# this is System.Text.Regular Expressions?.Regex.Replace. That was going to be my next guess!

Yesterday I went to Louisville for a party for Ben who is taking the big plunge soon. Afterwards I met my parents at a bar, because they were doing the Bambi walk (kinda)! Then I saw Jamie, my old roomate, and of course we stuck our tounges out. (I have no idea why this has been hapenning so much lately)

Jumping From a Very Tall Tree
Scribbled on April 3rd. 0 comments.

Thursday I went to Louisville to hang out with friends for my unbirthday. (I can drive and take pictures at the same time. tada!)

But to their surprise, I brought a present for them!

After that we drank a lot and there was much tounge sticker outing to be had by all.

Here is a pic of Joe looking very smert … amazing!

Then it was a hop, skip, and a jump over to Bardstown …

For skydiving!

Here we have Ben looking very incredulous in front of a small airplane.

And of course we practiced our arc stances.

And I’m pretty sure this look sums up our competency level for the afternoon.

Also, this is a 10 year old packing parachutes!

The 10x optical zoom on my camera finally came in very handy!

This guy looks like he was flying into a tree but he really wasn’t.

Then they make us sign some documents that pretty much assure our deaths.

We get into our jumpsuits and become very scared.

We load up in the plane, and all of a sudden we are at 3000 ft …

And then a guy jumps! Ahhhh!

But we don’t get off that easy. While 3000ft seemed plenty high, we were doing the 10,000ft jump, so we went up a bit higher. And at this point I quit taking pictures because most of my thoughts were occupied by various obscinities and general terror (actually, I was much calmer than I would have imagined).

So we jumped and I screamed a lot, although about halfway through the 5000 feet of freefall, I realized that screaming wasn’t really doing much so I all of a sudden stopped. The freefall was by far the most amazing part of the jump. It really is pretty indescribable. You’re hurling down at 120 miles per hour, and like most truly blissful experiences, I can’t really remember what was going through my mind at the time. Pure extacy? Pure terror? I guess I’ll have to do it again to find out :)

So we landed and I didn’t die. And finally, if you decide to jump out of an airplane, watch out for deadly, loose flying propellers.

More pictures here.