.:: Run Fat Boy .net ::.

Fitness for the buffet enthusiast.

Choose a Topic:

Clueless about getting into shape? Try RunFatBoy.

Top Posts:

Mon
27
Oct '08

Karaoke, kJams, and Auto CrossFading with iTunes

Anybody who knows me knows that I am a huge fan of karaoke. Back in the college days we took it upon ourselves to build a karaoke stage in the living room complete with mounted multi-monitors on the wall. Those were the good ole’ days

Karaoke stage

In an attempt to recreate these great memories, I have put together a portable karaoke setup that I like to call Karaoke In a Bag ™. KIAB contains a laptop, portable computer speakers, a mixer board, and a library of karaoke music. It works well. I bring it to parties. We sing on the beach. We sing in old folks homes. It’s a blast.

I’ve been using the kJams for playback of my karaoke music. kJams is on the bleeding edge of the karaoke software. Nothing on the PC even comes close to touching it.

Usually when we throw parties we setup the system and just allow people to come up, search for the song they want, double-click it, and away they go. But it’s no fun when the party is just starting. At the beginning of the night no one is drunk and when people are searching for karaoke songs, you can hear crickets chirp.

I have been holding out on registering the software for I want one feature; the ability to automatically cross-fade back and forth between karaoke playback and iTunes playback. In other words, I want music from iTunes to play when the user is searching for the karaoke song, then when the user begins to sing, I want the iTunes music to fade out (karaoke music fade in) and then once the karaoke song is done, the iTunes music should fade back in and continue to play.

So I set out to write a script to do such a thing. Luckily the user “oss” from the kJams support board gave me a running start with his iTunes crossfade script that he wrote.

Below is my modified version of his script. You will want to start kJams, iTunes (with the playlist you want it to play through) and then leave the following script running in the background (run it using OS X Script Editor) :

-- Modified 10-27-08 by Jim Jones
-- Script now looks to see if the Video window is full screen.  If the video window is full screen
-- it assumes that a karaoke song is playing and fades out iTunes.  If the video screen is less
-- than full resolution it assumes that karaoke is not being played and starts playing a track from iTunes.
	
-- 11-27-07
-- http://karaoke.kjams.com/forum/viewtopic.php?t=265
-- Please have iTunes and kJams running before launching this script and
-- have a playlist selected in iTunes
-- The simple logic of the script assumes that if iTunes is playing and this script is run,
--  you want to cross fade over to kJams.. Alternately, if iTunes is not playing a track,
--  it assumes you want to cross fade over to iTunes.
-- when you are ready to cross fade to kJams, make sure your next song is
-- highlighted/selected.  It will NOT automatically go to the next track in
-- your kJams playlist.
-- Although I have tested this code, I make no guarantees with this code,
-- any disasters that occur are not my fault.  Use at your own risk!! 
	
tell application "kJams Pro" to set kSpeakers to 0
	
--sets how much in percentage the volume is decreased per step
set fadeStep to 5
	
--sets how long in seconds between each step in the fade
set fadeDelay to 0.1
set kScriptCommand_PLAY_PAUSE to 1
set kScriptCommand_STOP to 2
	
--this is the max volume settings.. iTunes and kJams must share this for proper mixing.. Change to whatever you like.
set MaxVolume to 100
	
--this is the minimum volume setting
set MinVolume to 0
	
set appName to "kJams Pro"
set itunesAppName to "iTunes"
	
-- Playstate will be either 1 for iTunes or 0 for kJams
set playState to 0
set prevPlayState to 0
	
-- Find the bounds for the current system
set _desktopw to 0
set _desktoph to 0
	
-- Get max resolution of system
tell application "Finder"
	set _b to bounds of window of desktop
	set _desktopw to item 3 of _b
	set _desktoph to item 4 of _b
end tell
	
-- Poll the resolution of the Video window and compare it against the max resolution of the system
--  If they are equal, then you can assume the user is playing a karaoke song and you should cross
--  fade out iTunes and crossfade in kJams
	
repeat
	
	set w to 0
	set h to 0
	
	-- Repeatedly get the resolution of kJams Video window and
	--  don't progress until the width and height are greater than zero
	--  If there's an error, probably means the user just closed the Video window
	repeat until w > 0 and h > 0
		try
	
			tell application "System Events"
				tell process "kJams Pro"
	
					tell window "Video"
	
						set _s to get size
						set w to item 1 of _s
						set h to item 2 of _s
	
					end tell
	
				end tell
			end tell
	
		on error errStr number errorNumber
			-- error occurred, Video window was probably closed
		end try
	
		delay 0.1
	
	end repeat
	
	tell application "iTunes"
	
		-- Resolution of Video window equal to max resolution
		--  So we're probably playing a karaoke song.  Fade out music
		--  fade in karaoke music
		if (w ≥ _desktopw and h > _desktoph) then
			set playState to 0
	
			-- If prevPlayState is not the same as the current state
			if (prevPlayState = 1) then
	
				set kJamsVolume to MinVolume
				set iTunesVolume to MaxVolume
				set the sound volume to MaxVolume
	
				tell application "kJams Pro" to set volume kSpeakers level MinVolume
	
				repeat until iTunesVolume ≤ 0
					set iTunesVolume to (iTunesVolume - fadeStep)
					set kJamsVolume to (kJamsVolume + fadeStep)
					tell application "iTunes" to set the sound volume to iTunesVolume
					tell application "kJams Pro" to set volume kSpeakers level kJamsVolume
					delay fadeDelay
				end repeat
				--tell application "kJams Pro" to docommand kScriptCommand_PLAY_PAUSE
	
				tell application "iTunes" to next track
				tell application "iTunes" to pause
	
			end if
	
		else -- Video window not at max, so fade out kJams and fade in iTunes
			set playState to 1
	
			if (prevPlayState = 0) then
				set iTunesVolume to MinVolume
				set kJamsVolume to MaxVolume
				tell application "kJams Pro" to set volume kSpeakers level MaxVolume
				tell application "iTunes" to set the sound volume to MinVolume
				tell application "iTunes" to play
				repeat until kJamsVolume ≤ 0
					set iTunesVolume to (iTunesVolume + fadeStep)
					set kJamsVolume to (kJamsVolume - fadeStep)
					tell application "iTunes" to set the sound volume to iTunesVolume
					tell application "kJams Pro" to set volume kSpeakers level kJamsVolume
					delay fadeDelay
				end repeat
				tell application "kJams Pro" to docommand kScriptCommand_STOP
			end if
		end if
	
		set prevPlayState to playState
	
		delay 0.5
	
	end tell
	
end repeat

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).