October 26, 2005

Shredder

My 2nd shredder just died. It noisily labored on paper that was no longer externally visible and then smoke bellowed out of it. It was at one time a sharp little unit that resembled a R2D2 droid.

I have decided that I need a "Big Daddy" shredder that will last longer than a year. I need one that will shred paper (with staples), CDs, DVDs, etc. in cross-cut fashion. Any recommendations?

Posted by bourea at 03:24 PM | Comments (1)

October 24, 2005

Common Sense Prevails

We need to more tightly regulate spoons and forks. Spoons and forks are making America fat. America's legal system needs to hold spoon and fork manufacturers and retailers responsible for America's rotundness! Down with the spoons! Down with the forks! It doesn't matter that the spoons and forks (built and distributed) were non-defective, our legal system must prosecute spoon and fork manufacturers and retailers for turning America into a grossly overweight nation. Then, we will bankrupt the spoon and fork industry. A lean, mean, healthy American utopia will be created. Woo hoo!

Subsitute spoons and forks for guns. If only Josh would wrap this theme up nicely in one of his activist songs! *hint hint*

Fortunately, the gun ban extremists have been prevented from bankrupting one of America's oldest industries and succeeding in revoking the 2nd Amendment rights as promised in the Bill of Rights by default...

The "Protection of Lawful Commerce in Arms Act" (S. 397) passed in both the House and Senate.

The "Protection of Lawful Commerce in Arms Act" seeks to end predatory and baseless lawsuits initiated nationwide by the gun control lobby. These lawsuits sought to bankrupt a lawful, highly regulated industry by holding the manufacturers and retailers responsible for the unforeseeable acts of criminals. S. 397 passed the Senate in late July with a bipartisan vote of 65-31.

Joining LaPierre in commenting on this victory, NRA Chief Lobbyist Chris W. Cox added, "Our judicial system has been exploited for politics and Congress put a stop to that. Passage of the 'Protection of Lawful Commerce in Arms Act' would not have been possible without the support of the 257 House co-sponsors from both sides of the aisle. We appreciate the tireless efforts of Rep. Cliff Stearns and Rep. Rick Boucher and the Republican members of House leadership who worked to move the bill in this chamber.

"We are a safer country today because Congress passed this critical legislation and acted to save American icons like Remington, Ruger, Winchester and Smith & Wesson from politically motivated lawsuits. Our men and women in uniform abroad and at home now will not have to rely on France, China or Germany to supply their firearms," Cox added.

During Senate debate earlier this year, the Pentagon stated its concern over the consequences if the American firearms industry was litigated into extinction. The Department of Defense stated that it "strongly supports" S. 397 citing, "that passage of S. 397 would help safeguard our national security by limiting unnecessary lawsuits against an industry that plays a critical role in meeting the procurement needs of our men and women in uniform."

"I would like to thank our members who played a pivotal role in making this bill a reality. Together, we have saved the American firearms industry and protected the sanctity of the Second Amendment," concluded LaPierre.

National Rifle Association of America
Institute for Legislative Action

Posted by bourea at 04:24 PM | Comments (0)

October 21, 2005

Date Validation

What is the best way to do date validation in Ruby (when using Rails)?

The code block below is one proposed solution. However, all the user's form values are lost (when the form is saved with an invalid date) and the message of 'Item could not be saved.' isn't informative. This error message can't be made more informative (i.e. 'Please enter a valid date.') since a more specific message might not be true. (The save could have failed for some other reason other than trying to save an invalid date.)

def create
begin
@item = Item.new(@params['item'])
if @item.save
flash['notice'] = 'Item was successfully created.'
redirect_to :action => 'list_by_priority'
else
@categories = Category.find_all
render_action 'new'
end
rescue
flash['notice'] = 'Item could not be saved.'
redirect_to :action => 'new'
end
end

Any ideas?

Posted by bourea at 01:58 PM | Comments (0)

October 12, 2005

Ruby on Rails

Another comment on the Four Days on Rails documentation.

The code provided to sort the items by category has an unintended side effect. If an item contains a reference to a deleted category then the code outputs 'Unfiled'. However, when a list of items with 'Unfiled' item(s) is sorted by category the 'Unfiled' item(s) disappear since the equi-join (i.e. inner join) is too restrictive to handle this properly.

Original code:
def list_by_category
@item_pages = Paginator.new self, Item.count, 10, @params['page']
@items = Item.find_by_sql 'SELECT i.*, c.category FROM categories c, items i ' +
'WHERE ( c.id = i.category_id ) '+
'ORDER BY c.category ' +
'LIMIT 10 ' +
"OFFSET #{@item_pages.current.to_sql[1]}"
render_action 'list'
end

I came up with some new SQL:
SELECT i.*, c.category FROM items i
LEFT JOIN categories c on i.category_id = c.id
ORDER BY c.category
LIMIT 10

However the 'Unfiled' item(s) always appear at the top of the ordering since <NULL> is sorted first. I found a way to force MySQL NULL values to the end of the sorted list. Therefore the SQL becomes:
SELECT i.*, c.category, category IS NULL AS isnull FROM items i
LEFT JOIN categories c on i.category_id = c.id
ORDER BY isnull ASC, category
LIMIT 10

Resulting code to sort the items by category:
def list_by_category
@item_pages = Paginator.new self, Item.count, 10, @params['page']
@items = Item.find_by_sql 'SELECT i.*, c.category, category IS NULL AS isnull FROM items i ' +
'LEFT JOIN categories c on i.category_id = c.id ' +
'ORDER BY isnull ASC, category, due_date ' +
'LIMIT 10 '
"OFFSET #{@item_pages.current.to_sql[1]}"
render_action 'list'
end

This approach outputs all the item rows but <NULL> category entries mess up the sort order.
def list_by_category
@item_pages = Paginator.new self, Item.count, 10, @params['page']
@items = Item.find(:all, :include=> :category, :order=>'category')
render_action 'list'
end
Any ideas to fix this approach and not resort to using SQL?

Posted by bourea at 09:44 PM | Comments (0)

Ruby on Rails

I decided to give the Four Days on Rails documentation another try. I pre-loaded the database using the todos.sql script provided. However, after I followed all the steps up to and including those on page 17 the list categories page (http://localhost:3000/categories/list) errored out:
undefined method `strftime' for nil:NilClass

I decided that the strftime function might not like the value '0000-00-00 00:00:00' stored in both the create_on and update_on fields. Consequently, I emptied the categories table. Then, the list categories page worked for the no results case. Then, I added a category and the list categories page executed as expected.

Posted by bourea at 07:53 PM | Comments (0)

October 11, 2005

Ruby on Rails

I have been playing with Ruby on Rails and I am very impressed so far. I need to thank Bryce for pointed out what a great tool this is and recommending that I check it out. I found the Rolling with Ruby on Rails, Part 1 and Rolling with Ruby on Rails, Part 2 tutorials very helpful. However, I have found that the Four Days on Rails documentation wasn't as helpful.

The source code provided for the todo tracking application doesn't appear to work under the WEBrick webserver.

F:\Ruby\rails\todo>ruby script/server
f:/ruby/install/lib/ruby/site_ruby/1.8/rubygems.rb:144:in `activate': can't acti
vate activesupport (= 1.1.1), already activated activesupport-1.0.4] (Gem::Excep
tion)
from f:/ruby/install/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:2
3:in `require'
from f:/ruby/install/lib/ruby/gems/1.8/gems/activesupport-1.0.4/lib/acti
ve_support/dependencies.rb:197:in `require'
from ./script/../config/..//config/environments/development.rb:6
from f:/ruby/install/lib/ruby/gems/1.8/gems/activesupport-1.0.4/lib/acti
ve_support/dependencies.rb:189:in `load'
from f:/ruby/install/lib/ruby/gems/1.8/gems/activesupport-1.0.4/lib/acti
ve_support/dependencies.rb:189:in `load'
from f:/ruby/install/lib/ruby/gems/1.8/gems/activesupport-1.0.4/lib/acti
ve_support/dependencies.rb:38:in `require_or_load'
from f:/ruby/install/lib/ruby/gems/1.8/gems/activesupport-1.0.4/lib/acti
ve_support/dependencies.rb:21:in `depend_on'
from f:/ruby/install/lib/ruby/gems/1.8/gems/activesupport-1.0.4/lib/acti
ve_support/dependencies.rb:167:in `require_dependency'
from f:/ruby/install/lib/ruby/gems/1.8/gems/activesupport-1.0.4/lib/acti
ve_support/dependencies.rb:167:in `require_dependency'
from ./script/../config/environment.rb:45
from f:/ruby/install/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:1
8:in `require__'
from f:/ruby/install/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:1
8:in `require'
from script/server:42

F:\Ruby\rails\todo>

I know that Ruby supports multiple versions and I installed rails version 0.12.1 via "gem install rails --version 0.12.1" that the provided source code is supposed to be compatible with. I verified that the installation was successful by comfirming the installed versions:

F:\Ruby\rails\todo>gem list --local

F:\Ruby\rails\todo>"f:\ruby\install\bin\ruby.exe" "f:\ruby\install\bin\gem" list
--local

*** LOCAL GEMS ***

actionmailer (1.0.1, 0.9.1)
Service layer for easy email delivery and testing.

actionpack (1.9.1, 1.8.1)
Web-flow and rendering framework putting the VC in MVC.

actionwebservice (0.8.1, 0.7.1)
Web service support for Action Pack.

activerecord (1.11.1, 1.10.1)
Implements the ActiveRecord pattern for ORM.

activesupport (1.1.1, 1.0.4)
Support and utility classes used by the Rails framework.

fxri (0.3.2)
Graphical interface to the RI documentation, with search engine.

fxruby (1.4.2, 1.2.6)
FXRuby is the Ruby binding to the FOX GUI toolkit.

rails (0.13.1, 0.12.1)
Web-application framework with template engine, control-flow layer,
and ORM.

rake (0.6.2)
Ruby based make-like utility.

sources (0.0.1)
This package provides download sources for remote gem installation

Any ideas? Does it matter that version 0.12.1 was installed after the newer version 0.13.1?

Posted by bourea at 08:16 PM | Comments (0)

When an F350 is *not* enough... due to operator error

We decided to pull our 10,000 lb water-ski jump out last night. Jason brought an F350 dually (6x4) powered by a mammoth diesel engine. We took the trailer hitch receiver off of Terry's truck and discovered that it was a bit lacking in size, so much so, that the corresponding pin wouldn't work. We determined that we would have to make due with a carriage bolt hooking the ill-sized hitch receiver in place. The Y-shaped towing tongue was installed on the front of the jump and it was time to get everything hooked up.

Even with the slight lowering of the ball via the trailer hitch receiver it sat really high. We pushed the jump out into the river a bit to clear a path for the F350, which would have to go deep into the water in order to slide the hitch over the ball. When we successfully hitched it up I asked if we should install a pin in place to lock it together. Mike noted that this wasn't needed in the past so we continued on. (The F350's back wheels were half under water and the front wheels were just clear of the end of the ramp and the nasty super slick green moss.)

I was ready to see the big F350 rock and roll. A bunch of us jumped in the bed of the F350 to weight down the rear tires. We told Jason to hit it and we moved ahead but were quickly stopped when the jump tires collided with the ledge that forms the edge of the launching ramp. The back tires spun, rubber burned, and we went nowhere. A running start was needed. We backed up and kicked off round two. The running start helped but the F350 was still stopped dead in its tracks. Jason got out of the truck to investigate, but quickly returned to the truck since it started rolling ominously toward the river. We decided to try one more running start with plenty of Ford power.

The truck lunged forward resembling a fit of rage and the jump tires hit the end of the ramp hard, the ramp bounced, and the large 16" thick foam floatation pieces broke off the ramp frame. However, the effort was futile since the jump once again stopped us dead. We pulled all the large foam pieces that had broken off out of the way (which weighed quite a bit given their waterlogged state). It became clear that we were fully committed to removing the jump now; otherwise it would now sink faster than the Titanic.

We had another problem. All along we suspected that the front wheels were doing nothing and that is why the big Ford struggled so much. On the last attempt, it was confirmed that the 4x6 mode was *not* powering the front tires. (Four wheel drive is critical given the loose stones and wet concrete present on a boat launching ramp.) We determined that the F350 needed some Chevy help. Terry's Chevy was connected to the front of the F350 (making a train) and two more attempts were made. This didn't really help since Terry had to pull both the huge F350 and the jump.

It was time for another approach and it should be noted that daylight was quickly expiring. We kept the F350 in the middle and had Terry's pickup tied to one corner of the jump and Mike's minivan to the other corner of the jump. Frank and I weighed down the F350's back tires. Hit it! All three vehicles battled forward and the ski jump bounced over the ledge and started up the launching ramp. The trailer hitch tongue broke loose of the F350 and slammed down onto the ground. Terry's rope broke and only Mike's rope (no stronger than a ski line) kept the jump from roaring down the ramp into the river. Terry quickly crawled behind the jump and blocked the jump tires earning a medal of bravery.

After a discussion of the options a determination was made to not jack up the tongue for reattachment to the F350. The F350 was tied to the tongue and Terry's pickup was also reconnected. This approach was successful and the ski jump was now free of the incline of the launching ramp. The remaining movement, placement, and parking of the jump was uneventful. The saturated foam pieces were moved with the F350 via two trips and stacked on the deck of the ski jump. Jason left and took the F350 to the car wash for a much needed cleaning.

It was very dark when we were done with the ski jump and consequently, we didn't get to ski. Considering all the things that could have gone wrong (slipping on nasty green moss; carriage bolt failure; last rope breaking, jump rolling into river and sinking; F350 rolling into river...) we got off pretty easy.

*** Update ***
There was no problem with the F350's 6x4 operation. Our operator forgot to lock the front hubs, which differ from the F150s which lock electronically.

Posted by bourea at 02:53 PM | Comments (5)

October 10, 2005

My Invincible USB Flash Drive

I fired up my clothes dryer and went off to do something else. From the other room I heard a banging sound as the dryer rotated. I assumed this was coinage I missed when I emptied my pocket prior to starting the washing and drying process. Being lazy and given that my dryer is an early 1970's vintage Maytag I ignored the extra noise. A couple days later I emptied my dryer since I had some clothes from the washer to input into the dryer. When I was pulling the last bit of clothing out I noticed my USB Flash Drive at the bottom of the dryer. Ut-oh! I concluded that it was probably ruined. However, when I plugged it in it worked flawlessly. I am not sure how this will effect long term vitality but irregardless, I was still impressed.

Posted by bourea at 03:35 PM | Comments (0)