BibleGateway.com Verse Of The Day

Tuesday, July 03, 2007

Office Art, Part 1

I drew this on the back of one of my project folders and snapped the picture with my ViewSonic v36 Pocket PC. This is what happens when I get bored in meetings.

Tuesday, June 26, 2007

And 20 Became 19.

fresh chicken and ribs on the barbieUnce upon a time, five Buff Orpington roosters lived among others in a backyard flock, somewhere in upstate New York. A lone Speckled Sussex was even more the outsider, for the flock was mostly made up of Rhode Island Reds.

One sunny day in the summer of 2007, the largest rooster of the flock, a Rhode Island Red who goes by no name, was set aside to become dinner. By "set aside", what I really mean is he was placed into the fenced in backyard, separated from the other chickens and their food, until the time came. But this fenced in yard also happens to be inhabited part-time by a Soft Coated Wheaten Terrier named Lexi.

And so it was, Lexi was let outside and chased the RIR rooster before I could grab either one of them. The rooster ran into some high weeds, the remnants of what used to be a nice flower garden. Lexi ran in after, and came out seconds later, but the rooster did not appear. The chicken must have found escape from the fenced yard, for nobody could find the rooster after much searching.

So the next in line was desperately chosen, as dinner time was drawing nearer with no poultry ready to grill. It was a tough choice, but finally one Buff Orpington rooster stood out as the second largest, and soon succumbed to the meat cleaver. One chop and that's all she wrote.

That evening, dinner plates were stacked high of barbequed pork ribs and a fresh chicken, right from the back yard. Wegman's Memphis Style Barbeque sauce and Frank's Red Hot sauce complimented the smoked meats well.

Soon thereafter, the orginal RIR rooster showed himself. A master of camoflage he proved himself to be, as nobody could find him a few hours earlier, but there he was, right where he had last been spied. He managed to avoid his fate on that June day. But alas, he shall become dinner on another eve, when the 20 will become 18.

Thursday, June 21, 2007

NYS Child Car Seat Inspection

If you're a New Yorker, this is a good deal. It's one of those rare instances where you feel like you're actually getting something back for all the insane taxes you pay. You can go to these free child car seat inspections where officers will inspect your car seats to see if they meet current regulations, are installed properly, and to see that your child fits properly.

If you child has outgrown the seat, or if the seat fails to meet current regulations for any reason, they hand you a new replacement seat. Yes, a FREE replacement seat. They also let you know about the various height and weight guidelines for the different types of seats so you know better what you should be doing. We went to one last month and ended up getting 2 new seats because Raina had just outgrown the seat she was in, and Taryn was very close to outgrowing hers.

Another bonus was free popcorn, hotdogs, and pop. Can't go wrong there even if your seats are up to code.

Check out http://www.nysgtsc.state.ny.us/seat-cal.htm to see when the inspections will be held near you.

Robb's Salsa Recipe

I made a batch of salsa last night, and figured I would share my "recipe", as if there's anything to making salsa -- put crap in food processor and chop the hell out of it.

This is how I did it last night, but it usually varies a bit depending on what's available at Wegmans.

Ingredients
  • 2-3 lbs. "Tomatoes on the Vine"
  • 1-2 Vidalia onions, depending on size
  • 2 -3 Jalapeno peppers
  • 1 big Poblano pepper
  • 1 tbsp. Fresh of chopped Garlic
  • 1 bunch of fresh Cilantro
  • 2 nectarines or peaches
Directions
  • Heat cast iron skillet on high, get it really hot. Add a little dab of oil.
  • Cut poblano pepper and onion into quarters and place in skillet to sear outside. You don't want to completely cook the onions and peppers, just sear them on the outside to bring out a nice roasted smoky flavor and soften them up just a tad.
  • Place everything into a food processor and chop the crap out of it. May need to do multiple batches in the chopper depending on its size. Chop to a consistency you like, some like it chunky, some smooth, and everything in between.
  • Pour into a sealable bowl and store in refrigerator. Let the flavors meld together for awhile before enjoying for best results.
  • If you choose to share, DON'T DOUBLE DIP! That's nasty.
Variations
  • The peaches sound odd or even downright gross if you've never tried it, but they add a certain sweetness without being overbearing. BTW, peaches and nectarines are pretty much the same thing, except peaches have fuzz and nectarines don't. I prefer the non-fuzzy nectarine.
  • Roasting the vegetables on the grill would probably be even tastier than the cast iron skillet method.
  • Add corn and black beans, and maybe even a bit of cumin for a bit of southwestern flair
  • To turn up the heat, add more Jalapenos, Habaneros, or some of your favorite hot sauce. I have young children now, so I try to not get carried away with heat.
  • Of course, green peppers are popular in salsa. I find them a bit overbearing though when raw.

Tuesday, June 19, 2007

Monkey Butt

Sometimes I like to enter random word combos into Google to see what comes up. Tonight I entered "monkey butt" and found an interesting product. The funniest part is, it's a real product.

Thursday, June 14, 2007

Getting Thread Dump Of Running Java Process

Of course you can kill -3 a process to get the thread dump, but for Java apps you can also get thread dumps of running processes using the JDK 5 tools jps and jstack. For example, on a server where I am running Tomcat 5.5, typing jps gets a list of all Java processes running:
-bash-3.00$ jps
25515 Bootstrap
26912 Jps
Then using that process id, run jstack:

jstack 25515

Tuesday, June 12, 2007

My First Vaguely Useful Ruby Script

Alright, anyone with directories full of digital photos, mp3's, or other docs might appreciate an easy way to rename all the files in a directory, either by appending a common prefix, postfix (or extension), or giving each file the same basename with a sequence appending to the filename. There have been times I would have found that useful, and it turns out it's very easy to do with some simple Ruby scripting....


file_renamer.rb


#!/usr/bin/env ruby

require 'fileutils'
require 'find'

class FileRenamer

attr_accessor :directory

# constructor
def initialize(directory=".")
@directory = directory
FileUtils.cd(@directory, :verbose => true)
end

#add prefix to each file in dir, ignoring directories
def add_prefix(prefix)
Dir.foreach(@directory) {|x| rename_file(x,"#{prefix}#{x}") }
end

#add postfix to end of each file in dir, ignoring directories
def add_postfix(postfix)
Dir.foreach(@directory) {|x| rename_file(x,"#{x}#{postfix}") }
end

#rename a file unless it is a directory
def rename_file(from, to)
print "#{from}"
if FileTest.directory?(from)
puts "/ remains unchanged"
else
FileUtils.mv(from, to, :verbose => false)
puts " changed to #{to}"
end #if
end

# rename all files in directory to base_name + a sequence
def rename_with_base(base_name)
idx = 0
Dir.foreach(@directory) do |x|
if !FileTest.directory?(x)
rename_file(x,"#{base_name}#{idx}")
idx += 1
end
end
end

def list_dir
Dir.foreach(@directory) do |x|
print "#{x}"
if FileTest.directory?(x)
puts "/"
elsif FileTest.executable?(x)
puts "*"
elsif FileTest.symlink?(x)
puts "->"
end #if
end #do
end
end

# test it...
fn = FileRenamer.new("C:/test")
fn.list_dir
fn.add_prefix("test")
fn.rename_with_base("start")
fn.add_postfix(".txt")

Monday, June 04, 2007

Set The Captives Free!

My original plan was to let my chickens free-range during the days so they could eat weeds and bugs off my property. I've read that free-ranging chickens will find enough food that you really don't even need to feed them in the summer months. I'm not ready to test that one yet, but I did try a little free ranging this weekend.

On Saturday, I opened up the gate while I went in to get them fresh water, and by the time I got back with the water, they were all out in the yard scratching and pecking and making happy little chicken noises. I let that go on for a few hours while I played outside with the girls.

On Sunday I left them out for a few hours again. Actually I left them out twice Sunday, for a few hours the first time and just about 20 minutes the second time. The second time was a fluke. They used to never try to leave even with the gate open. But now they know what it's like out there, and they leave whenever they can.

I liked seeing the chickens roam about on their own. They mostly stayed right near the coop, foraging in the high weeds for bugs and making the occasional foray into the garden. I still only do it when I am outside with them, though, because some of our neighbors don't feel the need to control their dogs, and just let them roam about in other people's yards.

Lexi got out of the yard at one point Sunday and had a good chase with the chickens. She was within about 4 inches of a Buff Orpington dinner at one point right before I caught her. If a small puppy can be that fast and aggressive toward the chickens, I hate to think what would happen if full grown dogs came into our yard with the chickens out. So I still leave them "ccoped" up when I'm not right there watching and still keep them full of 20% grower/starter and cracked corn.

Wednesday, May 30, 2007

Ruby On Rails On Oracle Hurdles, Part 2

I've hit my first bumps in the road to hooking up RoR to an existing Oracle database schema. Like I posted yesterday, designing an RoR app from the ground up would be easier because you can build your database schema to RoR's expectations and limitations. And now I explain in more detail why...

Other than getting connected to an Oracle database (officially "Hurdle #1"), which I discussed yesterday, I've hit a few more snags.

Hurdle #2: Table naming. I'm trying to hook up to an in-house authentication/authorization database that is used by several of our application platforms. For RoR's "coding by convention" to work properly, you would ideally have plural table names, e.g. reps, rep_roles. Then when you generate your scaffolding, you would use singular names for the controller and view, e.g. rep, rep_role.

The existing database had singular table names. Generating scaffolding would come up with an error about the reps table not existing. Of course not, it's rep. My initial thought is, "how can I fool RoR?" And the answer was obvious, create views and see what happens.


create view reps as select * from rep;
create view rep_roles as select * from rep_role;


With newly created views sitting in from of the tables, I go back to the trusty command line and try to generate my scaffolding again. PRESTO!! It worked. It's a hack, it's trashy, it's shameful. But it works, and it was quicker than ripping apart the framework and touching code in inappropriate fashion.

So, Hurdle #2 has been overcome.

Hurdle #3: This one is what I alluded to yesterday about simple keys. These tables don't have simple "id" type keys. In MySQL when I was starting an app from scratch, of course I would use an auto-increment id. Works great. But according to the RoR on Oracle article (http://www.oracle.com/technology/pub/articles/saternos-rails.html), there are expectations for the primary key column being "id" and having a sequence with a naming convention of "singular-table-name"_seq, e.g. rep_seq for table reps.

Well, that's not going to happen here, not for this database. And despite the tagline of the article ("Learn techniques for creating a Ruby on Rails Web application that utilizes a legacy schema."), the article really doesn't address natural primary keys, whether they are simple one-column keys or complex multiple-column keys.

I can generate the scaffolding and launch the server. I get pages displaying all the rows in the table. But clicking on the show, edit, etc. links fail. The error, obviously is that it couldn't find an "id" column to look up the record by. I also noticed the PK fields aren't showing up on the list view or in the "create new" record view.

I've been working on other projects most of the day, so haven't had a chance to work on it beyond identifying what doesn't work.

So, Hurdle #3 remains a hurdle for now.

And I just had a few minutes to Google, and found this article (http://www.oracle.com/technology/pub/articles/tate-activeerecord.html) which basically says the same thing I am realizing. To quote:
But Active Record is not for every application. It does not handle legacy schemas nearly as well. For those, you need a mapping framework, not one that merely wraps tables with simple classes.

But then there is this blog (http://paulmwatson.com/journal/category/ruby-on-rails/) that has some encouraging words about setting the table name and PK column with the set_primary_key and set_table_name methods of the ActiveRecord model. (The specific post is at http://paulmwatson.com/journal/2006/11/02/wrangling-rails/)

Now that is worth a try, but still not so sure it will work for a VARCHAR primary key field, and still not going to cut it for multiple-column primary keys.

Tuesday, May 29, 2007

Hooking Up Ruby To Oracle

Well, I have to admit this one stumped me for a few days. Actually it stumped me one day, and I got pulled to work on actuall work stuff, and just got back to it a few days later.

I started by following the examples at http://www.oracle.com/technology/pub/articles/haefel-oracle-ruby.html
to get the Ruby Oracle libraries installed. That part was easy, download the OCI8 Ruby package at http://rubyforge.org/projects/ruby-oci8 and run it.

Then I whipped up a script to test the connection from an example I found online (forget the URL to reference -- sorry if I stole your crap, dude!) That script basically looks like this (with usernames and passwords changed to protect the innocent.

test-conn.rb


require 'oci8'

OCI8.new("user", "password", "oracle_sid").exec("select * from rep") do
|r| puts r.join(", ");
end



I was pumped! That seems easy, and then I can get out of the MySQL realm and start hooking up Rails to existing enterprise DB's and really show this stuff to be useful in our environment. Sorry MySQL fanatics, we are (mostly) an Oracle shop -- I have nothing against MySQL for my personal projects.

Anyways, she didn't work out so well. I figured it would work since I have Oracle installed on my PC, but got the following popup when I ran that script.

There was also a Ruby stack trace on the command line. Basically I did some Google'ing and found this posting (http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/238003) which at least gave me the clue I needed to look for OCI.dll on my system. My thought was it was getting confused between the Oracle 8 and Oracle 9 versions loaded on my machine.

Searching and searching, I don't have OCI.dll on my machine. Back to Google (a developer's best friend IMO, it always confuses me when other developers don't try this first when they get stumped) That's when I came across this page (http://www.dll-files.com/dllindex/dll-files.shtml?oci) that let me download OCI.dll. Dropped that in C:\WINNT\system32 (I'm on Windows 2000 at work, might be WINDOWS instead of WINNT for you), and re-ran the above test-conn.rb script.

IT WORKS!
Ruby on Rails on Oracle, here I come (again)

I'm guessing my next big hurdle (or potentially a roadblock instead of a hurdle) will be the lack of support for complex primary keys. Starting an application from scratch, you can design your database with that limitation in mind, but building applications for existing databases becomes another issue. I'm sure someone smarter than me has already addressed these concerns, so it might just be a matter of more Google searches.

Monday, May 28, 2007

Thursday, May 24, 2007

Ruby Syntax Sampler Script

Alright, I got a few different Ruby On Rails applications off the ground with the help of some tutorials, examples, and just plain screwing around. But I came to the scary conclusion that these apps were cool, but I still don't know much about Ruby the language. Rails makes it almost too easy! I only injected a few lines of code here and there based on the samples and tutorials to do things like define the foreign keys to get a selection list instead of text entry box for referenced tables.

So here's my lame attempt at playing with "Ruby proper" -- the language, devoid of frameworks. This is my trashy syntax_sampler.rb script that demonstrates some of the basics of Ruby.


require 'net/http'

#define a class
class SyntaxSampler
# define a constant
Dude = "Constants are capitalized. They cannot be declared in methods"
# the constructor method in Ruby is always "initialize"
def initialize( name )
@name = name # instance var starts with at sign
end

def print_name
puts @name
end

# big ugly method
def dostuff
print "x = "
x = 5
puts x
print "x + x = "
puts x + x
print "x * x = "
puts x * x
print "x**x = "
puts x**x
print "x/2 is "
puts x/2
print "but x/2.0 is "
puts x/2.0
names = ['robb', 'paula', 'raina', 'taryn'] #assign array to 'names'
print "crappers reversed is "
puts "crappers".reverse
print "\nPrint the Array: #{names}" # embed values right in print instead of 2 lines
puts "\nReverse the Array: #{names.reverse}"
puts "for methods with no args, parenthesis optional..."
puts names.reverse()
print "\nCapitalize Each Array Item: "
names.each {|name| print "#{name.capitalize} " }
print "\nUpper case Each Array Item: "
names.each {|name| print "\n\t - #{name.upcase} " }
puts "\n\n'5' as an integer = #{"5".to_i}"
puts "\n19.0 as a string = #{19.0.to_s}"
puts "\n'a19' as an integer = #{"a19".to_i}"
puts "\n'19a3' as an integer = #{"19a3".to_i}"
puts Dude
# define a global var
$wicked = "Global vars start with a dollar sign"
puts $wicked
end

def anothermethod
puts $wicked # make sure that var is really global scope
end

def mirror( something )
puts "#{something} #{something.reverse}"
end

def mirrordefval( something = "dude")
puts "#{something} #{something.reverse}"
end
end

class DiffClass
def initialize
end

def rundiff
puts $wicked # really is global, even across classes
10.times {print " x "} # everything is an object
puts
# use the above "required" module to do something...
Net::HTTP.start( 'www.ruby-lang.org', 80 ) do |http|
print( http.get( '/en/LICENSE.txt' ).body )
end

# shortcut for string arrays, no more pesky commas and quotes
food = %w{elk deer caribou squirrel pig chicken cow}
puts food

# basic if/else control structure
count = 5
if count > 10
puts "Try again"
elsif count == 5
puts "You lose"
else
puts "Enter a number"
end

# a while loop
xx = 0
while xx < 10
print "#{xx}..."
xx += 1
end
print "done"
end
end

# classes and methods are defined, now run them....
ss = SyntaxSampler.new("Robb")
ss.print_name
ss.dostuff
ss.anothermethod
ss.mirror("hello, I'm passing params baby") # with parens
ss.mirrordefval "yo yo yo" # no parens
ss.mirrordefval # no params sent in, use default value
puts $wicked # still don't believe me? it IS GLOBAL DAMMIT!
dc = DiffClass.new
dc.rundiff()
#now a little introspection for your sorry ass
puts "\n\nMethods of SyntaxSampler class...."
SyntaxSampler.instance_methods.each {|mm| print "#{mm} "}
puts "\n\nNow eliminate inherited methods...."
# this looks like a simpler way to print out a list, eh?
puts SyntaxSampler.instance_methods(false).join(" ")
exit # not really needed here

Friday, May 18, 2007

Getting Started With Ruby On Rails

The steps I took to install and get Ruby on Rails up and running. This is working on Windows (2000 at work, XP at home). I basically followed the steps on http://www.rubyonrails.org/down.

  1. Download and install Ruby. For Windows, there is a .exe installer. Make sure you pick the installer that comes with the "gems" package updater. I installed at c:\ruby to keep things simple. Installers are at http://www.ruby-lang.org/en/downloads/
  2. Once installed, you made need to add your Ruby bin directory to your PATH environment variable. On 2000, I had to do that, on XP, it just worked from the command line without doing that.
  3. In a command line window, cd into c:\ruby and run: gem install rails --include-dependencies
  4. To create the application, I created a webapp directory under c:\ruby.
  5. Change directory into c:\ruby and type: rails webapp
  6. Change directory into c:\ruby\webapp and type ruby script/server
  7. Once that comes up, open up a browser and check out http://localhost:3000
  8. There you have it, Rails is up and running on Webrick server.
  9. I already had MySQL installed, so next step was quick for me. If you don't already have it, go download and install MySQL.
  10. While you're in a downloading kind of mood, you might as well grab the Eclipse plugin for Ruby if you are an Eclipse guy. You could use any editor, like Notepad++, FreeRIDE (is that still supported? not in latest Ruby release, but it was in last release I downloaded), etc.
  11. With MySQL up and running, create a database and some tables.
  12. Edit your c:\ruby\webapp\config\database.yml file to point at your database.
  13. Run ruby script/generate to create controllers, models, etc.
  14. Edit your c:\ruby\webapp\routes.rb file to add your "routes" for your app.
I'm still on step 14, so can't tell you much more about that. Sitting on a conference call doing "real work"....

To create a controller, I did this....

C:\ruby\webapp>ruby script/generate controller recipe list
exists app/controllers/
exists app/helpers/
create app/views/recipe
exists test/functional/
create app/controllers/recipe_controller.rb
create test/functional/recipe_controller_test.rb
create app/helpers/recipe_helper.rb
create app/views/recipe/list.rhtml


And then enter http://localhost:3000/recipe/list into your browser. So far I got the screen below running without writing a single line of code. Not bad for about 30-45 minutes' worth of work.


It's amazing what you learn when you actually look at a tutorial. Instead of generating models blindly and getting the above, I should have been creating scaffolding to get something useful. I created a table call "robbs" in my database and added a single row (from MyEclipse DB Explorer). Notice my table is "robbs" plural, and the scaffolding controller and view is simply "robb" singular. Then by running the following command, I get this....



C:\ruby\webapp>ruby script/generate scaffold robb robb
exists app/controllers/
exists app/helpers/
exists app/views/robb
exists app/views/layouts/
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/robb.rb
identical test/unit/robb_test.rb
identical test/fixtures/robbs.yml
create app/views/robb/_form.rhtml
create app/views/robb/list.rhtml
create app/views/robb/show.rhtml
create app/views/robb/new.rhtml
create app/views/robb/edit.rhtml
create app/controllers/robb_controller.rb
create test/functional/robb_controller_test.rb
create app/helpers/robb_helper.rb
create app/views/layouts/robb.rhtml
create public/stylesheets/scaffold.css


Thursday, May 17, 2007

My Ruby Dilemna

To Ruby or not to Ruby?

I looked at Ruby a while back, maybe 2004/5-ish, when it was just starting to make a buzz. It seemed interesting because it was an object oriented scripting language. Loosely typed, to-the-point syntax, etc. I liked the concept, but ultimately I couldn't find a use for it to get me off the ground. When I really needed a shell script, it was quicker to just use ksh or bash and the standard array of unix utilities--awk, sed, cut, grep, etc.

Spare time is precious, and there are a lot of things besides programming to fill it with. And how often do you really get time at work to sit down and learn a new technology, pure R&D and personal development type stuff?

And if I do sit down to learn something new, should I really be spending time on a "toy" like Ruby when I could be brushing up on new Java stuff? Afterall, Java/J2EE are paying the bills, so shouldn't I be the best Java guy I can be, instead of dabbling in flavor-of-the-month technologies?

Then I saw a demo for Ruby on Rails. Wow, that blows the mind of a STRUTS/JSP/Servlet kinds of guy like me. It looks so cool, so fast, so easy, can it really be like the demo? It sparked my interest, but again, the buzz was that this was more of a "toy" than a real enterprise alternative, and lots of negative press was spent decrying lack of security and scalability, blah blah blah. Short attention span, drifting off, blah blah blah.

So now a friend of mine is diving head first into Ruby on Rails along with a few of his friends at work. His genuine enthusiasm has piqued my interest for a 3rd time. He is enthusiastic without being one of those zealots that are screaming loudly about how Ruby is going to kill Java or kill .Net or kill Python or whatever. No languages have to die here, people, it's just one more tool in the toolbox -- do you throw away your drill when you buy a new hammer?

And after all this time, Ruby is still out there and gaining support, so I can't really label it "flavor-of-the-month" or "toy" anymore. To be honest, I thought the same thing about Java back in '96/'97-ish when it was just being used to write applets embedded in HTML pages. I dabbled with some Java, but as a C/SQL/Motif programmer, Java seemed completely useless for real apps. I wasn't convinced until I saw the proof-of-concept office suite Corel wrote in Java -- whoa, real applications like drawing and word processing and spreadsheets running in a graphics "desktop" with icons and stuff! Now I write Java every day. So given that my judgement on this sort of thing sucks goat, I think Ruby, esp. Ruby on Rails, deserves another, more serious, look.

Using the instructions on this link, I was able to use Ruby GEMS to download and install Rails. Then a few commands and I got my sample skeleton project up and running. About 20 minutes worth of "work" while I sit here trying to figure out a production support issue for work. And here it is, my local server running my skeleton project....

And now, some links.....

Ruby Programming Language

Ruby On Rails

Ruby in 20 Minutes tutorial

Learning Ruby by comparing to languages you already know

More Ruby documentation

RDT Ruby IDE plugin for Eclipse

Why's Poignant Guide To Ruby

Using Oracle with Ruby

Wednesday, May 16, 2007

Mini KISS

Couple of friends saw these guys playing at the JavaOne After Dark bash. It's at once disturbing and intriguing at the same time. Mini KISS is a KISS tribute band made up of midgets, er, little people, or whatever they like to be called nowadays.

http://www.minikissonline.com/

Tuesday, May 15, 2007

Freaky Word Tricks For Your Shriveled Little Mind

An interesting email I got recently. Must be some amount of truth to it because I could read it without much difficulty...


Only great minds can read this


This is weird, but interesting!

fi yuo cna raed tihs, yuo hvae a sgtrane mnid too
Cna yuo raed tihs? Olny 55 plepoe out of 100 can.
i cdnuolt blveiee taht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it dseno't mtaetr in waht oerdr the ltteres in a wrod are, the olny iproamtnt tihng is taht the frsit and lsat ltteer be in the rghit pclae. The rset can be a taotl mses and you can sitll raed it whotuit a pboerlm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Azanmig huh? yaeh and I awlyas tghuhot slpeling was ipmorantt! if you can raed tihs forwrad it

FORWARD ONLY IF YOU CAN READ IT.

Monday, May 14, 2007

More Chicken Pictures

The chickens have more than tripled in size since we got them a few weeks ago.

The buff orpington's seem to be the beefiest of them all right now, and a few of the reds are still kind of scrawny looking. They are all almost fully feathered out now, though -- with just their undersides and necks looking downy now.

I picked one up the other day and could not believe how thick the legs are already. These things went from fluffy little balls to something that resembles actual chickens now. Every day I go back there I notice a difference. I think if I just sat back there in the coop, I would actually see them grow. Well, maybe not.

Friday, May 11, 2007

I've Got Some Time

I've been increasingly paranoid about not having time to build my nest boxes for the chickens. So I asked myself, "self, how early do chickens start laying eggs?"

And when I had no answers, I asked Google instead. According to the Murray McMurray hatchery site, this is the answer:

"Most hens will start laying between 5-7 months of age. They will lay best at 1 to 2 years of age. All pullets (female chicken under 1 year of age) lay small eggs at first and after a while will lay larger eggs. Younger hens will lay 1 egg every 3-4 days. A hen 30 weeks old can lay 2 eggs every 3 days. Some have been known to lay an egg a day. All breeds have different laying abilities."
So I have a little time before I really need to panic. They are getting pretty big though, and when I fed them this morning, one of them was actually up on the perch. They are almost fully feathered out now as well. By the end of May we should be grillin' up our first chickens.

MMMmmmm, chickens!

Thursday, May 10, 2007

9 Week Old Lexi

This is what Lexi, our Wheaten Terrier, looks like at about 9 weeks old. Chewing on a toy. Play! Play! Play! Crash and sleep! Repeat.....

Wednesday, May 09, 2007

Bear Kills Moose in Alaska Driveway as Residents Watch

Bear Kills Moose in Alaska Driveway as Residents Watch
FOX News

I've seen stray cats hunting for mice in my driveway, but never anything as exciting as a brown bear killing a moose. If I had been in this situation, I probably would have grabbed the camera AFTER grabbing my rifle and skinning knife.

Click on the URL below for the rest of this story:
http://www.foxnews.com/story/0,2933,270936,00.html

Monday, May 07, 2007

Winchester 1300 - Possible Issue Shooting Slugs?

My father just bought the rifled slug barrel for his Winchester 1300 12 gauge, and brought it up this weekend to try it out. I gave him a couple of my Lightfield Hybrid EXP sabot slugs to shoot through it, and the when he fired, the action came all the way open and ejected the shell without any intervention.

He thought maybe he was inadvertently pulling the slide open because he wasn't expecting that much recoil, so I tried it. I rested the gun over the "V" of my pointer finger and thumb, not holding the forestock at all. The action came all the way open and ejected the spent casing for me as well.

Now we aren't sure if the barrel is keeping the bolt from fully locking properly, or if this is a side effect of the Winchester "Speed Pump" feature (I never really knew what that feature was supposed to do anyways), or if it is a matter of too much shell for the gun to handle?

Each shot was dead accurate at about 70 yards, and it didn't seem to be an "unsafe" condition as it was firing accurately and ejecting the spent casing, but it could definitely catch you off guard in a hunting situation if you are used to doing all the work of pumping a new round in.

I've fired everything from light target loads to heavy 3" magnum turkey and goose loads to rifled slugs through my Mossberg 500 and never had this happen, so I can't image a 2-3/4 slug being too much for a 1300 to handle.

My initial research on the web found another guy in a forum that this happened to, but haven't been able to find too much more info on it. I'll have to keep looking, and in the meantime he was going to have a gunsmith look at it to see if there is an issue with the bolt locking mechanism.

Thursday, May 03, 2007

Lexi Is OURS!!! HAHAHA

We picked her up Tuesday evening because the breeder was going to be out of town delivering a few puppies on Wednesday (a few hours early, yeah!). We'll have to post more pictures when we get a chance. She does a lot of hyper play-play-playing, followed immediately by crashing into a sleep. That's what puppies do.

Monday, April 30, 2007

2 More Days And Lexi Is Ours!

Here she is, at almost 8 weeks old. She turns 8 weeks Wednesday, May 2, so we can pick her up then.

Sunday, April 29, 2007

The Chickens Are Home

Today I put the finishing touches on the chicken run. Paula cleaned out the building that will serve as the coop while I finished putting the gate on. We put the perch in there, carried the chickens outside in laundry baskets, and hung up the brooder heat lamp. I got bigger feeder and waterer and set those up, and Paula went and got more corncob bedding to put down on the floor. So the chickens our our of our home and into their home.

And it was about time. They got to the point where they could fly out of the wading pool even with the 12" cardboard walls surrounding it. This morning one of them was running around the living room chirping because it was lost and couldn't get back in the pool. Later in the morning I saw a couple of them fly out when they got excited about something. They also started to do a little picking on one of the Buff Orpingtons, which meant it was time for them to get more space per bird.

Of course, now that they have so much more room, I went out to take pictures and they are all huddled together in the corner. When we got home from dinner, I peeked in the side window and they were all laying down right under the brooder lamp. But they have the space if they need it, so I feel better. And they aren't running around in my living room, so my wife feels better.

By the end of May they should be right about eatin' size, and it will be time to fire up the grill and have some friends over. Nice and fresh.

I still need to build or buy nest boxes, but I should have a few weeks before they get to that point, so it isn't an emergency yet.

Tuesday, April 24, 2007

More Puppy Pix 4/24

More pictures of the Wheaten puppies.
We get to pick ours up May 2!!

Thursday, April 19, 2007

The Other Chick - A Mystery!

This is the extra chick we got with our order from Murray. Still not sure what kind of chicken it is. Once the wing feathers start coming in more it should be a lot easier to tell, or I could just wait until it's fully grown.

Wednesday, April 18, 2007

Go Ahead And Make Yourself At Home

These 3 deer were among the 7 that visited our feeder the other day. It's not all that uncommon for them to be in our yard with the apple trees and the fact that we back up to an abandoned apple orchard. It's not even uncommon for them to poke their noses in the squirrel feeder and eat out of there. But this particular deer decided to make herself right at home and just layed down right smack dab in the middle of our yard.

Obviously she doesn't know who lives here. Hard to not think of a full freezer with scenes like this.

Who Says Programmers Can't Get Chicks?


Here's a close up of a Rhode Island Red chick, about 5 days old, sitting on my kitchen table.

Tuesday, April 17, 2007

The Chicks Have Arrived

The chicks have arrived! I finally got to bed around 6am after working on that file upload all night, and drifted off to sleep around 6:20 -- just in time for my cell phone to ring at 6:30. I jumped up and answered assuming it was work calling about the failed upload, but it was the post office letting me know the chickens have arrived. I rolled over andwent back to sleep for a few hours, then picked them up around lunch time. One had died in transit, but there were still 26 birds in there, so they must have put in 2 extra instead of just the one extra. We got 5 Buff Orpington roosters, 20 Rhode Island Red straight-run (as they hatch, no sexing), plus the one "exotic" chick Murray McMurray throws in for free. It is black with a stripe, so not sure what kind it is yet. Looking through the catalog it could be any number of breeds -- we'll see once it gets bigger.

We have our old kiddie pool set up in the back living room for them right now. We got the starter kit from Murray McMurray that has the cardboard draft shield, brooder lamp and red heat bulb, thermometer, 2 waterers, and 2 feeders. It seemed like a good deal versus buying all the individual pieces separately.

Right now our house if full of the CHEEP CHEEP CHEEP of 26 baby chickens. The girls think they are so cute and wanted to know what we would name them. Our answer of course NO NAMES, these are LIVESTOCK not PETS!

The dog on the other hand is a pet, she will have a name (Lexi -- we picked her out last night, and get to bring her home in a few more weeks) -- we won't eat the dog! Try to explain that to a 2 and 3 year old and it suddenly becomes clear how arbitrary the whole thing is -- how certain animals can share our homes as pets (dogs, cats, guinea pigs), other animals get killed for sharing our homes without asking (mice, rats, moles), and other animals get raised solely to eat (chickens, cows, pigs).


Thursday, April 12, 2007

Working With Velocity Templates

I used Velocity as the templating engine for my persistence code generator project. It is really simple and clean to set up and use, which is refreshing compared to a lot of the Apache projects which are obtuse and over-abstracted for the sake of inflating programmer's egos.

Why use Velocity? I use it for code generation -- connect to a database, get the meta data, and generate the DAO, VO, and DaoFactory Java classes to work with that database. But you could use it to generate any sort of text, whether it is HTML, JSP, ASP, emails, documentation, source code, etc.


Below is a very simple stub to show how easy it is to work with Velocity. This is the bare minimum Java code you need to merge your data into a template and generate an output file. Of course, you would have more than one bind variable in the context would probably have to deal with more complex data structures, but this gives you the basics...


import java.io.File;
import java.io.FileWriter;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;

public class VelocityExample
{

public void execute() throws Exception
{
//Set up Velocity engine and context
Properties p = new Properties();
VelocityEngine ve = new VelocityEngine();
VelocityContext vctx = new VelocityContext();

p.setProperty("file.resource.loader.path", "/path/to/your/velocity/templates");
ve.init(p);

// put any number of properties in the context. These are
// used as bind vars in the Velocity template. For example
// In template any instance of ${someProperty} will be replaced
// with someValue.
vctx.put("voClassName", "ExampleVo");

// Get your template
Template templ = ve.getTemplate("YourTemplate.vm");
// and a writer to new file to be generated
FileWriter writer = new FileWriter("/path/and/filename/of/generatedfile");

// merge template with context and write to your output file
templ.merge(vctx, writer);
writer.flush();
writer.close();
}
}


Ok, so that's the code, what does the template look like? Below is the template I use to generate VO's (or DTO's) -- a class with properties and getters/setters methods for each property.

Notice is looks a lot like a Java class already, except for all those pesky $var's and #directives. Anything you put in the velocity context is available from the template. You reference the properties using $property or ${property}, and if it is a complex type you can reference fields using dot notation like ${property.name}, or loop through List's and arrays using #foreach directives.


// ====================================================================
// DO NOT EDIT THIS FILE. IT HAS BEEN AUTO-GENERATED BY DAO-GEN.
// YOUR CHANGES WILL BE LOST NEXT TIME THE CODE IS GENERATED!
// ====================================================================

package ${voPackageName};

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import java.sql.Date;
import java.sql.Timestamp;


/**
* @author DaoGen
* @version cvs: $Id: VoTemplate.vm,v 1.2 2006/12/12 20:13:23 ran488 Exp $
*/
public class ${voClassName}
extends BaseVo
implements Serializable
{

#foreach( $field in $persistableFields )
/** $field.colName */
private $field.javaType $field.jFieldName ;

#end


/** Constructor */
public ${voClassName}()
{
super();
}


// Getters and Setters
#foreach( $field in $persistableFields )


/**
* Setter for DB column $field.colName
* @return void
* @param $field.typeName
*/
public void set${field.jProperFieldName}( $field.javaType $field.jFieldName )
{
this.${field.jFieldName} = $field.jFieldName;
}


/**
* Getter for DB column $field.colName
* @return value
*/
public $field.javaType get${field.jProperFieldName}()
{
return this.${field.jFieldName};
}
#end
}




For a more real-world example of the Java code, here is the method I use to generate the VO from the above example. This method actually generates the DAO implementation and interface and the VO for each table in a database.



/**
* @param db
* @param basePath
* @param ve
* @param vctx
* @throws ResourceNotFoundException
* @throws ParseErrorException
* @throws Exception
* @throws IOException
* @throws MethodInvocationException
*/
private void generateTablePersistentObjects(Database db, String basePath, VelocityEngine ve, VelocityContext vctx) throws ResourceNotFoundException, ParseErrorException, Exception, IOException, MethodInvocationException
{
Template voTempl = null;
Template daoIntfcTempl = null;
Template daoImplTempl = null;
voTempl = ve.getTemplate("VoTemplate.vm");
daoIntfcTempl = ve.getTemplate("DaoTemplate.vm");
daoImplTempl = ve.getTemplate("DaoImplTemplate.vm");

// The MEAT and POTATOES
for (Table table : db.getTables())
{
// put everything from table into Velocity context
vctx.put("voClassName", table.getJProperFieldName() + "Vo");
vctx.put("daoImplClassName", table.getJProperFieldName() + "DaoImpl");
vctx.put("daoInterfaceName", table.getJProperFieldName() + "Dao");
vctx.put("dbTableName", table.getTableName());
vctx.put("javaTableName", table.getTableName());
vctx.put("persistableFields", table.getColumns());
vctx.put("primaryKeyFields", table.getPrimaryKeys());
vctx.put("schema", table.getTableSchema());
vctx.put("tableType", table.getTableType());
vctx.put("numPkFields", table.getPrimaryKeys().size());

FileWriter voWriter = new FileWriter(basePath+"vo"+File.separator+table.getJProperFieldName()+"Vo.java");
voTempl.merge(vctx, voWriter);
voWriter.flush();
voWriter.close();

FileWriter daoIntfcWriter = new FileWriter(basePath+"dao"+File.separator+table.getJProperFieldName()+"Dao.java");
daoIntfcTempl.merge(vctx,daoIntfcWriter);
daoIntfcWriter.flush();
daoIntfcWriter.close();

FileWriter daoImplWriter = new FileWriter(basePath+"dao"+File.separator+table.getJProperFieldName()+"DaoImpl.java");
daoImplTempl.merge(vctx,daoImplWriter);
daoImplWriter.flush();
daoImplWriter.close();
}
}


For more info check out http://velocity.apache.org/

There is also an Eclipse plugin for the templates at http://veloedit.sourceforge.net/.

Monday, April 09, 2007

More Puppy Pix

We went to see the Wheaton Terrier puppies again last Thursday. A few of the pictures are here....http://www.frontiernet.net/~nicholson150/puppies.html They are up and playing now, pushing each other around, wrestling, barking at each other.

Tuesday, April 03, 2007

K&N Performance Air Filter Kits

I was wondering what the difference between the FIPK eries 57) kit and the "Performance" Series 77 kit was, other than the 77 kit being chrome instead of plastic. My assumption was the new 77 was supposed to be higher performance as well, but I was wrong.

According to the K&N website, the series 57 kits gives an extra 10.49 horsepower for the 5.7L HEMI, while the 77 only gives 8.34 HP (dyno chart), and the 57 seems to be more consistent boost across the RPM range.

FIPK Installation Instructions for 5.7L HEMI V8.

Monday, April 02, 2007

More Puppy Pictures

The Wheaten Terrier puppies at about 3-1/2 weeks....



Thursday, March 29, 2007

ETA On Chickens: 4/16

I just ordered my chickens, and they should arrive the week of April 16th. Got them from Murray McMurray hatchery via internet. They will be shipped out as day old chicks, ready to go, so I just need ot pick them up at the post office as soon as they arrive. We got a striaght run of 20 Rhode Island Reds, 5 Buff Orpington roosters, plus whatever the extra free "exotic" chick is they put in there with them.

I also ordered the starter kit (brooding lamp, waterers, feeders, etc) from them earlier today. So now the dream of rasining chickens is reality, no turning back.

Fire up the barbeque!

Wednesday, March 28, 2007

Chicken Perch Finished


Tonight I finally finished building the perch for our chickens. Here is a picture of the finished product. Actually not completely done, as I would like to sand the actual perches a bit better and maybe hit the whole thing with a coat of paint or stain.

Now I just need to build the nest boxes, fix the roofing, fence in the run area, and purchase the chickens along with some supplies like feeders and waterers, food, grit, etc.

Tuesday, March 27, 2007

A Big Day

We had a big day yesterday. I came home from work and Paula had a pan of homemade macaroni and cheese in the oven.

And my new tonneau cover was on the porch, freshly delivered from Amazon.com. I got the Lund Genesis Tri-Fold and it really was about a 5 minute install, no exaggeration. Line it up at front of bed, clamp down the front, unbuckle the mid section and unfold. Clamp down two rear clamps. Done. Took longer to pull into the barn (all the while tearing up my very wet lawn with my very big and heavy truck tires).

Then we packed up the kids and went out to look at some puppies. We ended up putting down a deposit on a Soft Coated Wheaten Terrier female. They are 3 weeks old right now, so we have wait until May. We played with the mom, "Claire", and watched the puppies for about an hour before we finally left. Marion Morse is the breeder, and she is in Webster, NY. website link

Tuesday, March 13, 2007

Lights Mod For Ram

On the Dodge Ram, the grill is attached to the hood, and the whole kit and kaboodle lifts as one piece. Here's an ingenius method for mounting driving lights so they sit behind the grill, mounted on the cross bar in front of the radiator. When I get around to mounting my driving lights, I'll be a lame ass and copy these guys. http://www.dodgetalk.com/forums/showthread.php?t=141886

Friday, February 23, 2007

Apache "Maintenance" Pages Using mod_rewrite

Just found out about the power of mod_rewrite in the Apache web server. To enable a system wide "maintenance" page (system not available type thing) you need enter only 2 lines of code in the httpd.conf file and restart apache. This is so simple, it kind of baffles me why this example wasn't mentioned in the 2 links I used to figure it out.

The pattern matches for everything except maintenance.html and sends the request to maintenance.html. That is important, because at first I tried to redirect all requests by matching on ^/(.*) but that got into an endless loop, since it would redirect request to maint page which redirected to the maint page which redirected to, well you get the idea.

Here is my rule:
RewriteEngine On
#RewriteRule !^/maintenance.html$ /maintenance.html [R,L]


Save file, cd ../bin and sudo ./apachectl restart and presto! All requests go to maintenance.html instead of the intended destination. Comment out those 2 lines, restart, and all normal.

Links of interest:

FOLLOWUP - 3/29
My maintenance redirect wasn't working for requests already coming in over SSL. I had to add the rule to the secure virtual host config section as well for it to work. Special thanks to "shimmyshack" on the alt.apache.configuration newsgroup for pointing me in the right direction.

Thursday, February 22, 2007

2007 DST Issues And Java

This daylight savings time (DST) issue is a pain in my buttI didn't need right now. We still have legacy applications running on JRE 1.2.2, and since it is Silverstream 3.5, changing anything out from under will destroy the world and it will not run right, if at all.

Links to Sun's FAQ is at http://java.sun.com/developer/technicalArticles/Intl/USDST_Faq.html
Of notable interest here is this little tidbit of crap:
  1. Do my operating system's timezone patches fix the Java platform's timezone data?
    • No. The Java SE platform's timezone data is not read from the local or host operating system.
    • The Java SE platform maintains a private repository of timezone data in locally installed files (.../jre/lib/zi) as part of the Java Runtime Environement (JRE) software.
      • Applying whatever operating system timezone patches (for example Solaris OS, Linux, Windows) will have no effect on the accuracy of the Java SE platform's timezone data.

Well isn't that lovely? Java doesn't rely on the underlying OS to get timezone info. I'm sure there's a "good" reason, but it seems like pointless redundancy to me. Why set it up on the OS if the JVM doesn't use it? Sure there is probably some backward OS that has no concept of timezones, so Java abstracts everything to a point of uselessness just like Swing UI's.

If installing or updating new JRE is not an option (say, in production where the app server and all the apps haven't been tested on newer JRE's) The JRE updater tool is found at http://java.sun.com/developer/technicalArticles/Intl/USDST_Faq.html -- not sure how reliable ot stable that thing is, but we'll find out in our dev and test environments soon enough.

There is a brief discussion on the Jboss forums at http://jboss.org/index.html?module=bb&op=viewtopic&t=98682 as well. Or for Websphere http://www-1.ibm.com/support/docview.wss?rs=180&context=SSEQTP&dc=D600&uid=swg21219396#actions.

Venison And Mushrooms In Gravy

This is a simple "recipe" we did tonight that was extremely good -- very tender meat and great flavor. We didn't really have a recipe, so I don't know what to call it (Bambi swimming in gravy?)

1 lb. venison, cut in 1" cubes
2 cups mushrooms, sliced or cubed
Beef gravy, mix or pre-made.
Flour
Salt
Pepper
Garlic Powder

  1. Heat up a cast iron skillet with a little bit of oil.
  2. Mix the salt, pepper, garlic powder into some flour on a plate or in a plastic bag.
  3. Dredge meat cubes in the seasoned flour and brown each side in the pan. Don't worry about cooking all the way through, just searin the juices. Once browned, remove the meat from the skilet and set aside.
  4. Sautee the mushrooms in the same pan, using a little oil or butter as necessary to soften them up. Remove and set aside with the meat.
  5. Pour the gravy (or mix up the gravy mix according to directions, we used 3 packages but 2 would have been fine) into the skillet.
  6. Put the meat and mushrooms back into the skillet, lower heat, cover, and simmer for about 30 minutes or so, until meat is tender and fully cooked.
We dumped this over white rice and it was delicious.

Next time I would probably try adding some sauteed onions in with the mushrooms as well. There's really no reason why you couldn't substitute some other meat for the venison, e.g. elk, caribou, bear, rabbit, squirrel, or even beef.

Wednesday, February 14, 2007

"Peterbilt" Dodge Ram

This thing is sweet. He must have spent a lot of cash and time on this custom project. I only looked at the pictures so far, but I plan on going back to read it later. He started with a Ram 3500 and put a Peterbilt cab on it, truck bed off an old Chevy, 40" Mickey Thompson's, etc. Must be seen to be believed....

http://www.autoblog.com/2006/09/13/when-a-dodge-ram-just-isnt-sufficiently-truck-like

Server Printing Using Java Print Service

The first and most obvious thing you will notice about the Java Print Service (JPS) API's is that it is pretty much geared toward client side printing. For example, to look up print services you use javax.print.PrintServiceLookup, which has methods to lookup the default print service, lookup all the print services that match the given AttributeSets and/or DocFlavor's. That all makes sense if you are building a print dialog with the default printer selected already, and a list of all the other printers defined on the system, to allow the user to choose one.

On the server, however, printing is just one more stop in a process flow. It has to just happen automatically, which means you have a specific printer in mind for the stuff to go to. Notice on the PrintServiceLookup class, there is no method to get a specific named printer service. In my mind, that is a deficiency, but one that is easily rectified.

Here is the code I use to lookup a named printer service. The name is kept in a properties file that gets bound to JNDI, or it could be kept in a database, etc. Basically you pass in null for the DocFlavor and AttributeSet to get all print services on the machine. Then loop through those looking for a match, and return the matching service, or throw an Exception.



import javax.print.*;

...

public PrintService getNamedPrintService(String prnName)
throws Exception
{
PrintService[] prnSvcs;
PrintService prnSvc = null;

// get all print services for this machine
prnSvcs = PrintServiceLookup.lookupPrintServices(null, null);

if (prnSvcs.length > 0)
{
int ii = 0;
while ( ii < prnSvcs.length )
{
log.debug("Named Printer found: "+prnSvcs[ii].getName());
if (prnSvcs[ii].getName().equalsIgnoreCase(prnName))
{
prnSvc = prnSvcs[ii];
log.debug("Named Printer selected: "+prnSvcs[ii].getName()+"*");
break;
}
ii++;
}
}

if (prnSvc == null)
{
throw new Exception("Printer " + prnName + " was not found on this system.");
}

return prnSvc;
}

Parsing Fixed-Length Positional Text Data

I recently had to parse out positional (fixed-length field) data, and I really didn't want to write some ugly hard-coded parser that would break every time a field changed length or a new field was added.

I also didn't want to write some overly complicated abomination with XML configuration files and AbstractFactories and visitor patterns and so on (you know, like the Apache guys would have done.)

Instead I chose to use some of the new features of JDK 5 -- like enums and the enhanced for loop. I create an enum like the one show below.


public enum GetTransactionFields
{
ADDR_ID (10, Justification.LEFT_SPACEFILLED),
ADDRESS (70, Justification.LEFT_SPACEFILLED),
TYPE_CODE (1, Justification.NONE),
ACCOUNT_INFO_IND (1, Justification.NONE),
RECEIVE_OFFERS_IND (1, Justification.NONE),
THIRD_PARTY_IND (1, Justification.NONE),
CUSTOMER_EMAIL_STATUS (1, Justification.NONE),
WIRELESS_CARRIER (4, Justification.NONE),
INVALID_IND (1, Justification.NONE),
SOURCE_CODE (1, Justification.NONE),
SYSTEM_CODE (1, Justification.NONE),
LAST_UPDATE (8, Justification.NONE),
;

private int fieldSize;
private Justification justification;

/** Private constructor */
private GetTransactionFields(int fieldSize, Justification justification)
{
this.fieldSize = fieldSize;
this.justification = justification;
}

/**
* @return Returns the justification.
*/
public Justification getJustification()
{
return justification;
}

/**
* @return Returns the fieldSize.
*/
public int getFieldSize()
{
return fieldSize;
}
}


Now, to add a new field, I simply insert it in the right position, with it's fixed length and the justification (if you only get 10 characters in a 20 character field, are they left or right justified? In this case Justification is an enum as well, but I ended up not needing to use it)

If a field size changes, you only need to change the size here. Your parser code does not need to know or care. That parsing code is extremely simple. An example is shown below. This example just prints the field name (from the enum) and the value that was parsed out.

In my real application, I created an XML document using the enum names as the XML nodes, and the values were the parsed values. This way, the data was more flexible to work with, as I could use XSLT to show the data nicely formatted on a JSP log viewer, and use another XSLT to transform it into the format needed by the backend web services.


private void parseGetRecord(String record)
{
int posn = 0;
int endIdx = 0;
for (GetTransactionFields f: GetTransactionFields.values())
{
endIdx = posn + f.getFieldSize();
System.out.println("Parsing field " + f.toString() +", value = " + record.substring(posn, endIdx)));
posn = endIdx;
}
}


And that's all there is to it. An enum and a for loop. Simple, elegant, and best of all, maintainable even by drooling neanderthal programmers.

Reading a Text File Line By Line

Sometimes I need to read a text file line by line from Java code. Whether it's reading transactions to blast onto an MQ queue, or parsing out CSV files, the actual reading of the file remains the same. But it's something that I always have to look up an example for, because I don't work with all the streams, readers, and writers classes often enough to memorize.

Here's the simplest running example, basically a crappy implementation of the the Unix "cat" command (read a file and spit it out to the console, line by line). To get it to do something useful, replace the System.out.println with something more useful, like putting to a queue, or running the line through a CSV parser, or running a SQL query, etc.



import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class UnixCat
{
public void cat(String filename) throws IOException
{
BufferedReader is = new BufferedReader(new FileReader(filename));

String line = "";
while (line != null)
{
line = is.readLine();
System.out.println(line);
}
is.close();
}

public static void main(String[] args)
{
UnixCat uc = new UnixCat();

// Assume args is a list of filenames
for (int ii = 0; ii < args.length; ii++)
{
try
{
uc.cat(args[ii]);
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}
}


Tuesday, February 13, 2007

Ram HEMI: First Shock

I ended up buying that Ram last week (http://redneckprogrammer.blogspot.com/2007/02/is-this-truck.html
), and I have to say it's awesome. It's a 2003 Ram 1500 SLT Quad Cab 4x4 with short bed and the 5.7 liter 345 HEMI V8. It hauls lots of serious ass. It's kind of hard to open her up with all the snow and ice we've had, but you can feel it growling under that big bulging RAM hood. The kids love and and always aks to ride in Daddy's truck.

I filled it up late last week to the tune of $50, then filled it up again last night. I did a little basic math and found that I got a little (very little) over 13 miles per gallon mileage. It was a little bit of a shock to fill that 26 gallon tank, and a bit of a shock to get 13 mpg, but it really can't be too much worse than the Jeep with 4.11 gears, 33" tires, and the aerodynamic qualities of a brick. I don't know for sure because I never actually calculated what the Jeep got. I figured I just didn't care enough to run the numbers. Anyone who drives a lifted and modified Jeep is not in it for the economic benefits. Same goes for driving a full size truck with a big V8.

The truck has all the goodies, towing package with the hidden hitch, trailer wiring, trailer brake controller, leather seats, overhead console, bed liner, "Infinity premium sound" system with the CD and cassette, fold out flat cargo deck in back seats, with storage under that, heated side mirrors, power locks/windows/driver's seat, auto transmission, etc.

Monday, February 12, 2007

Tonneau Covers

I'm looking to get a tonneau cover for the new Dodge Ram this spring. My father has one for his Dakota that attached very similar to the soft top on a Jeep. The problem is when it gets cold the material gets stiff and shrinks a bit. If you get it off, you'll never get it back on, as we found out when we were packing for our bear hunting trip last November. Lund and a couple other companies make a cover with the bows and frame built right in, so you just clamp it down to the bed rails. It folds up in 3 sections, and installs in minutes no matter what the weather.

The Lund is the Lund Genesis Tri Fold, and it's amazing how much of a range exists in pricing. At the cheapest, I have found Amazon.com has it for $282.74 with free shipping, and as high was 423.95 at Auto Parts Warehouse, with free shipping (gee, thanks, charge me and extra $140 but give me free shipping).

I was kind of amazed Amazon.com had it at all, let alone them being the cheapest by far. Remember when they sold books? And maybe CD's and movies? Now they are like the Super Walmart of the internet world.

Price list for Lund Genesis Tri Fold model 95064 for Dodge Ram 1500 Quad Cab short bed (6'3")
  • Summit Racing - $329.95
  • JEGS - didn't have it
  • Truck Addons.com - $330.99, free shipping
  • Truck Stuff USA - 369.99
  • JC Whitney - $359.99
  • Auto Parts Warehouse - $423.95, free shipping
  • Amazon.com - $282.74, free shipping

Saturday, February 03, 2007

Apple Picking Fall 2006

This past fall we went apple picking at Morgan Farms out here in 315 land. Here are a few pictures.

Daddy And Taryn
daddy and taryn
Mommy and Raina
mommy and raina

Pix From The Cabin (Last Fall)

Just going through some pictures on my hard drive. Here are a few from the cabin last fall.

Grammy and the girls coming back from a walk


Taryn, Teddie, and Charlie sleeping together. I think Charlie liked being able to sleep with Taryn, where she normally would have been sleeping in a brib at home.

Thursday, February 01, 2007

Winter Warmth

One of my favorite winter time recipes...

1. Fill a rocks glass with ice
2. Fill with bourbon
3. Enjoy responsibly.