100,000 Miles

I bought my 1998 Ford Mustang back in high school with only 16,000 miles on it. Since then, I have graduated college, got married, become a licensed skydiver, and added over 84,000 miles to my car, running up mile number 100,000 just outside Janesville, WI on my way up to Minnesota for Christmas. My car is still running smoothly and I hope to get many more trips out of it before upgrading to a newer model.

Merry Christmas!

Rails: PostgreSQL and attachment_fu

An issue came up at work recently where my development team was asked to create a web interface for the storage, updating, and retrieval of PDF documents. After taking a look at my options, I decided to go with Attachment Fu. Getting started was pretty simple, just follow the directions in the README and away we go.

After doing a couple of uploads on my development machine with some random PDFs I happen to have laying around, it seemed as if only small PDFs would work properly. Larger PDFs, upon retrieval, came back to the browser as corrupt files. This wasn’t really an issue, more of a nagging concern, since the PDFs we need to store are only a couple hundred kilobytes in size. The corruption I was encountering was happening when files were on the order of a couple megabytes. While we did not have the actual files that were going to be uploaded at the time, sample files were used and everything worked perfectly.

That is until we finally got our hands on the actual PDFs and then everything went to hell. The 200KB file came back from the database corrupt and a quick hotfix had to be devised to give users access to a hard copy of the file in question.

After about 2 days of investigation, throwing logger statements all over the code, and learning quite a bit more about connection adapters in Rails then I had previously known, I was able to trace the problem down a bit. The problem seems to stem from the null character \0, or more specifically \000, in the PDF and the pg gem’sstring_to_binary method when used through ActiveRecord. To get around this issue, I modified my copy of Attachment Fu’s DbFile Backend process’s save_to_storagemethod (in RAILS_ROOT/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb) as follows:

# Saves the data to the DbFile model
def save_to_storage
  if save_attachment?
    # NOTE there seems to be a problem with the PostgreSQL gem. Storing data manually on Create/Update.
    if self.connection.class == ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
      unless db_file
        build_db_file
        db_file.save!
        self.class.update_all ['db_file_id = ?', self.db_file_id = db_file.id], ['id = ?', id]
      end
      # NOTE Use a slightly adjusted SQL call than Rails would use with ::bytea
      self.connection.update_sql "UPDATE \"db_files\" SET \"data\" = '#{ActiveRecord::ConnectionAdapters::PostgreSQLColumn.string_to_binary(temp_data)}'::bytea, \"updated_at\" = '#{Time.now.to_s(:db)}' WHERE \"id\" = #{self.db_file_id};"
    else
      (db_file || build_db_file).data = temp_data
      db_file.save!
      self.class.update_all ['db_file_id = ?', self.db_file_id = db_file.id], ['id = ?', id]
    end
  end
  true
end

Update: Well, ran into another issue when moving from development and QA environment to our staging environment. The standard "data" = E'DATA GOES HERE' syntax was throwing an error, checking the PostgreSQL website, I adjusted the query to be "data" = 'DATA GOES HERE'::bytea and all seems to be running smoothly again. Seems like more of the root problem is coming into view. If I get some time, I’ll see if I can create a test case where this fails, and look further into a solution. In the meantime, my fix above does the job I need and PDFs of all sizes work properly with PostgreSQL.

Update 2: Looks like somebody beat me to the punch. The PostgreSQL adapter is fixed in Rails 2.2, here is the commit message for those of you interested: Fix binary data corruption bug in PostgreSQL adaptor

Saving Up for my Skydiving Rig

I'm hooked. If the 'A' License in a Week course wasn't enough excitement, being able to jump 4-ways with my friends puts the thrill and enjoyment level over the top. Starting last week, I'm saving up for my first skydiving rig! I'm now prioritizing my purchases (I haven't even bought Guitar Hero: World Tour) and started making my own lunches to bring with me to work instead of going out 5 days a week. I was worried that I would get sick of eating hard salami sandwiches, but since we are cooking dinner every night, I get to mix up my lunches with leftovers.

I hope to have saved up enough money to buy my complete skydiving rig (Main Parachute, Reserve Parachute, Container, and Automatic Activation Device) by Spring 2009 so I can start saving money on gear rentals. I plan on jumping a LOT next year ;-)

Here is what I'm thinking about getting at this point:

Also looking into a Relative Work (RW) jumpsuit and upgrading my altimeter to an Altitrak. I think I'm going to go with a Black/Grey/Navy color scheme... there is a Vector 3 Coloring Program available that I have been playing with, a Navy/Grey Lightning Scheme looks pretty cool for my container...

I added five more jumps to my logbook over the weekend, making my first 6-way attempt and really feeling the difference sit-flying can make on my fall rate. This brings my jump count up to 38, so with a few more jumps and water training early next season I will be able to apply for my 'B' License :-)

~ Blue Skies

Skydive Chicago AFP-in-a-Week Video

It took me a little while, but I was able to turn the VHS recording of my AFP Jumps into a digital format, build DVD chapters and menus, burn a few DVDs and upload the videos to YouTube! There are also some photos that the AFP Instructors took on my Flickr page under the Skydiving Photo Set... Enjoy!

Video footage from my AFP (Advanced Freefall Program) in a Week course at Skydive Chicago. Part 1 contains AFP jumps 1-10.

Video footage from my AFP (Advanced Freefall Program) in a Week course at Skydive Chicago. Part 2 contains AFP jumps 11-18 and credits.

Skydiving: 'A' License in a Week

This is what happens when I don't post for a while, my family has no idea what I'm up to. I got a birthday call this morning (I'm 25 today!) from my aunt who was shocked to hear that I'm out at Skydive Chicago this week going through their 'A' License in a Week course. Not much time to write today, I'm busy "jumping out of a perfectly good airplane," but I will have pictures and video up here later.

Blue Skies