.:: Run Fat Boy .net ::.

Fitness for the buffet enthusiast.

Choose a Topic:

Clueless about getting into shape? Try RunFatBoy.

Top Posts:

Wed
28
May '08

Uncle Bob

My Uncle Bob bought my family growing up their first ever telescope, a telescope so big that at the time it stood taller than me. I can remember watching the stars with the neighbors on a few summers nights.

He took us on a tour of StorageTek in 1988 showing off proudly the systems that they had built and the parts that he had individually machined.

He garnered a respect in myself for the sciences and engineering disciplines that still lives with me today. And along with his adeptness for engineering precision and measurement, he was a really nice guy.

Our lives are given meaning through others. We live through others, we live for others.

Our individual lives are a manifestation of all that who have come before us. And it’s only through giving back to future generations do we give thanks to those that helped us along the way.

Thank-you Uncle Bob. Rest in Peace.

Uncle Bob
Bob Sedlak April 2nd, 1950 - May 20th, 2008

Fri
16
May '08

Managing Multiple Images for Multimodel Forms

So, I have this web app that I am creating for a friend that helps with managing inventory for eBay auctions.

When a user created a product, my intention was to allow them to upload as many images as they would like to be associated with that product. When they would go to edit the inventory item I would like for them to be able to delete any previously uploaded images and upload new images if they like.

Here’s what my interface looks like.

Interface screenshot.

So I have a good idea that I will probably use attachment_fu to manage the uploading of images. But wait, things are slightly more complicated because I will have one model that manages the product attributes (Products) and then another model that manages the uploaded images (ProductImages).

As usual, Ryan Bates to the rescue with his Railscast “Complex Forms Part 3″. Much of the following code will be familiar if you’ve watched this Railscast; I am just going to demonstrate the usage of attachment_fu with a multi-model setup.

So, within the product new/edit form I have a div defined where my images will be displayed.

  ........
  <p>
    Wholesale Price<br />
    < %= f.text_field :wholesale_price %>
  </p>
	
  <div id="images">
    Images
      < % @product.product_images.in_groups_of(3) do |group| %>
          < %= render :partial => 'product_image', :collection => group %>
          <p style="clear: both"/>
      < % end %>
  </div>
	
  <p style="clear: both"/>
	
  < %= link_to_function image_tag('add.png', :border => 0, :alt => "Add image.") + "&nbsp;Add Image" do |page|
    page.insert_html :bottom, :images, :partial => "product_image", :o bject => ProductImage.new
  end %>
  <p>
	
</p>

My product_image partial looks like this :

    < % if product_image != nil %>
        < % fields_for "product[image_attributes][]", product_image do |f| %>
          < % if product_image.new_record? %>
            <div class="newimage">
               <p>
                 < %= f.file_field :uploaded_data, :class => "formField", :index => nil %>
                 < %= link_to_function "Remove", "$(this).up('.newimage').remove()" %>
               </p>
            </div>
        < % else  %>
          <div class="image">
            < %= image_tag(product_image.public_filename(:stamp), :border => 0) %>
	    < %= f.file_field :uploaded_data , :index => nil, :style => 'display:none' %>
	    < %= link_to_function image_tag('cancel.png', :border => 0, :alt => "Delete image."), "mark_for_destroy(this)" %>
	
            < %= f.hidden_field :id, :index => nil %>
            < %= f.hidden_field :should_destroy, :index => nil, :class => 'should_destroy' %>
          </div>
      < % end %>
    < % end %>
  < % end %>

Areas of interest : I’m using the fields_for form helper because our images are part of another model. There’s a set of empty brackets after the definition

product[image_attributes][]

to tell Rails that we’re passing an array (in this case multiple images).

The call to the mark_for_destroy method. This allows me to directly hide the display of the image and mark a form flag that tells the system to destroy it once the form has been submitted. This technique is outlined in Ryan’s railscast.

In application.js


function mark_for_destroy(element) {
	$(element).next('.should_destroy').value = 1;
	$(element).up('.image').hide();
}

I have a product_image model that manages the attachments using attachment_fu. It has an attribute should_destroy which allows an image to be marked for deletion from the form.

class ProductImage < ActiveRecord::Base
  has_attachment :content_type => :image,
                 :storage => :file_system,
                 :max_size => 2000.kilobytes,
                 :resize_to => '320x200>',
                 :thumbnails => { :thumb => '150x150>', :stamp => '75x75>' },
                 :processor => :ImageScience   
	
  validates_as_attachment
	
  attr_accessor :should_destroy
	
  def should_destroy?
    should_destroy.to_i == 1
  end
	
end

For the products model, we want to setup a virtual attribute called image_attributes (remember the array of images that we defined in our form above?) that will handle the saving/deletion of product images.

class Product < ActiveRecord::Base
  belongs_to :vendor
  belongs_to :product_status
  belongs_to :ebay_category
  has_many   :product_images, :dependent => :destroy
	
  after_update :save_images
	
  def image_attributes=(image_attributes)
    image_attributes.each do |attributes|
      if attributes[:id].blank?
        product_images.build(attributes)
      else
        product_image = product_images.detect { |t| t.id == attributes[:id].to_i}
        product_image.attributes = attributes
      end
    end
  end
	
  def save_images
    product_images.each do |image|
      if image.should_destroy?
        image.destroy
      else
        image.save(false)
      end
    end
  end
	
end
Tue
13
May '08

Recording Type Definitions From Unit Tests For Autocompletion

I just got done reading Steve Yegge’s “Dyanmic Languages Strike Back”. He notes that one of the perceived problems with dynamic languages is the lack of tools, (he notes specifically the autocomplete feature).

While the thought of type declarations or any sort of annotations makes me cringe, is there any useful type data that could be recorded while running the unit tests that could later be used for the autocompletion of methods from within your Favorite Editor (I Textmate)?

While this may be cheating by deriving types at runtime, it certainly seems simpler than the probabilistic methods Steve outlines for determing types in dynamic languages. And it would certainly encourage the act of writing tests if you could get the added productivity boost of autocomplete.

Sat
3
May '08

Lower Blood Pressure and Seasonal Changes

Ever since Jr. High I looked forward to the winter time. I loved the way the cool breezes hit against my face. I loved the fact that I could wear a long sleeve shirt and not worry about breaking into a sweat or develop pit stains. Winter was the fat man’s paradise where the lower temperatures gave me a sense of freedom that no other season provided. I was in a seasonal wonderland where my above average body heat didn’t control me and I could finally wear and act how I wanted without the embarrassment of my overly-sweating body showing itself.

But winter was no friend and he was only acting as a mask to further deep rooted problems. Most people who chronically sweat are probably over weight and I was no exception. Furthermore, I had high blood pressure as a result. And the high body temps were probably a result of this. Who wouldn’t be hot when your heart is working twice as hard as the average individual?

In May of 2006 I was hospitalized for my high blood pressure and as a result, I have been taking three different blood pressure medications. Atentolol, a beta blocker, Avalid, a diuretic, and Norvasc, a vasodilator.

My entire perception has changed. With a normal blood pressure, I now enjoy the sun and the heat and have even worn a long sleeve shirt when it’s 80 degrees out. I actually have days where I want to feel the warmth of the sun against my neck and feel the summer’s breeze blow against my shirt.

It’s such a strange perception shift. This has to be the feeling that one would feel when observing an indigenous tribe for the first time or experiencing weightlessness in space. While before others would tell me that they “feel cold”, I didn’t understand. But now I feel their cold and I feel their discomfort, and for once my perception of temperature seems right in line with those around me. And I am finally figuring out that I was living in a whole different world these past few years.

Sat
1
Mar '08

Rails Migrations - Command Line Power in 2.0

I absolutely loves Rails 2.0 and the command line conveniences it provides for the RESTful scaffolding and models. Here’s a couple of tricks to generate a migration to quickly to add/remove columns from an existing table.

Assume you already have a table called ‘Users’. You would like to add a column called ‘title’ and another column called ‘email’. You can quickly create a migration from the command line using the following :

script/generate migration AddTitleEmailToUsers title:string email:string

The migration generated looks like this:

class AddTitleEmailToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :title, :string
    add_column :users, :email, :string
  end
	
  def self.down
    remove_column :users, :email
    remove_column :users, :title
  end
end
</pre>
	
And if you need to remove those same columns, you can generate a migration with the following :
script/generate migration RemoveTitleEmailFromUsers title:string email:string

The title of the migration is significant. The beginning Add/Remove specifies the action to take, the To/From specifies the tablename to apply the action against.

How sweet is that?!?

Fri
28
Dec '07

Diagnose Me!

I am posting an image and three movies.

The image represents a chest x-ray that was performed on May 2, 2006.  The collection of movies are of a CT scan that was performed in early December.

I am hoping that a few qualified (and curious) individuals will take the time to review the scans and will be gracious enough to give their two cents regarding a diagnosis. Optimally, by making these records public I will attract a few quality outside diagnoses and hopefully those diagnoses will be in line with what my doctor has already stated.  If there are differing opinions on the scans, at least I can bring these points up with my next doctor’s appointment to have them addressed.

Before I get yelled at by the rest of the world stating "why the hell are you relying on stranger for your diagnosis!" let me reiterate that I have already been to one specialist and am getting a second opinion on Jan 2nd just to be safe.

I am intentionally keeping the details behind my diagnosis vague. I want all assessments done solely by the data presented.

I have a pretty good BS detector, so please don’t tell me that I have Leprosy. :-)

So if you’re a doctor or pre-med student, or if you’re a fan of “House”, post your best diagnosis.  Once you have your diagnosis, go ahead and read the comments. There I will give further information on my circumstances.

– Jim

Chest xray: 



Click to englarge

 

CT (AC) : Chest 5’s CHK 2ND

Hi-res images of this scan be found here along with a hi-res QuickTime version of this movie.

 

CT (AC) : Soft Tissue

Hi-res images of this scan be found here along with a hi-res QuickTime version of this movie.

 

CT : Chest 5′S CHK 2ND

Hi-res images of this scan be found here along with a hi-res QuickTime version of this movie.

Wed
18
Apr '07

Hyperfocus and the Loss of Sensitivity

My mother called me yesterday and told me that my sister had a mole removed from her leg and the doctors found it be cancerous.  My sister has been known to lay out the in the sun a little too long, but at only age 30, the percentages were definitely on her side for this very thing not to occur.

Today I was creating my "to-do" list for work and I list 1) finish up taxes (yes I know, they’re late), 2) some items regarding my daily job, and 3) call mom about Shannon.

It struck me as odd (and made me a little depressed) that I would have to created an item #3.  

Sometimes within my work I reach a level of focus for which all outside influences disappear and time is nonexistent. But with this hyperfocus, there’s a definite emotional disconnect.   And for the first time I am wondering what loved ones that have become second class to this overly stimulated way of working.

In the end, I feel incredibly guilty for making my sister’s condition just another checklist item.  I’m not sure what to make of this. 

Fri
5
Jan '07

Velocity Diet Recap

The last couple of days were uneventful — by then the shakes had become somewhat automatic, and I was mainly focused on how I was going to transition to a more normal eating pattern.  My skill with calipers is still a work in progress, but I would say that I went from about 18% bodyfat to about 13% bodyfat.  I lost 12 pounds in the 28 days, and I really don’t think any of it was muscle (it’s been about a week and a half since I finished up, and I’ve gained back 1-2 pounds while maintaining the same level of leanness, which I think represents any water weight that I might have lost).  There might even have been some muscle gain, which would make the numbers even more positive, but that’s a tougher thing to guage.  My stomach circumference measurement went down dramatically (I don’t have the numbers right in front of me, but it was at least 2.25 inches).  The interesting thing is that my stomach/waist measurements have both continued to decrease even since I came off the diet (even while I’ve been gaining weight). Aesthetically, I think that I look as good as I ever have (if I was ever this lean before, it must have been when I was in high school — back when I weighed 107 pounds).  The additional 45 pounds definitely makes a
difference.  :-)

I’ve continued to do weighted walks on my offdays, although I don’t mind taking the occasional day of rest if I feel like I need it.  The walks seem to have a lot of benefits outside of their contribution to calories burned — I’m not sure if it’s the weight I’ve lost, or if it’s been the walks, but my legs just feel "springier" — kind of a general positive feeling of good health/athleticism.  I’m up to using an xvest with 20 additional pounds, typically for about 3 miles, and I typically walk at a 1 mile/16 minute clip (just enough to feel it, not so much that I feel like it’s interfering with my workouts).

I’ve ramped by calories up from where I was on the v-diet (1300 on nontraining days, 1600 on training days) to about 2000-2100 every day (slightly higher number of calories on training days, and typically more carbs on training days).  I’m doing a routine from Chad Waterbury’s book (which I highly recommend — you can find it on t-nation) and am going to stick pretty closely to his suggestions for at least the next year.  I plan on slowly upping calories by looking at my weight and body composition (based on calipers, waist readings, the mirror, etc.) every couple of weeks and increasing calories as my weight gain slows (assuming it’s good weight gain).  A little bit of fat is certainly okay (if there’s anything this diet has proven, it’s that I can take the fat off if I need/want to), but I don’t want to go overboard bulking.  I think that getting to 160 lbs while maintaining my current level of leanness by the end of the year is a very reasonable goal, and I think that it may even be possible to come in a bit higher and a bit leaner.

Thu
21
Dec '06

Velocity Diet - Day 24

I’ve been keeping the volume of my workouts down this week and doing anything that strikes me as fun.  Today I thought I’d max out on bench press, just to see how much, if any, strength I’ve lost during this diet.  I worked up to a pretty easy 195 single, but failed miserably at 201 (200 is my previous best, and I was 12 pounds heavier at the time).  All in all, not bad — 5 lbs is a small enough difference that it could be chalked up to random fluctuations.  

After the workout, I had a big burrito meal which left me stuffed (mmm, solid food). As I had hoped when I originally started this diet, I think my newfound leanness is making it easier for me to eat carbs; this morning, even after that big meal, I only gained a pound, and according to the calipers, I actually lost bodyfat (I’m at 154 lbs at 12.3% bodyfat with a 31.5" maximum stomach circumference measurement). 

Tue
19
Dec '06

Velocity Diet - Day 22

Quick update after last night’s long posting –

This morning I’m down to 153.5 (11 lbs in exactly 3 weeks).  The exciting thing is for the first time, the calipers say I’m below 13% bodyfat (12.7% to be exact).  Now, I’m still learning how to use the calipers, so any of my reading might be a millimeter off here or there, so take that exact number with a grain of salt — but still, it’s pretty cool, and the trend continues to be positive.