Sunday, October 30, 2005

my kid brother has an new TV series

Andrew has a new film in the works, based on his comic Damn Nation, recently released by Dark Horse Comics.

He's a busy guy. He only just wrapped up the pilot for a new TV series called Eureka! that has been picked up by the SciFi channel. They start filming the first season in January. And it looks like one of my favorite actors Joe Morton (Brother From Another Planet) is in the cast!

Can you tell I'm proud? Hell, yes! He's rolling with some really cool stuff, and I can't wait to see it.

But there's some strange synchronicity going on here that makes me wonder if there is a higher power somewhere out there trying to tell me something.

Only last month General Electric announced that their healthcare division was merging with the company I work for, IDX Systems, in a $1.3 billion deal. Well, GE also owns NBC, who in turn owns the Sci-Fi channel. So indirectly, Andy and I may end up working for the same company. Only he gets to do the really fun, imaginative stuff.

Yes, there is a smidge of jealousy here, a green-eyed gargoyle lurking in my mid-brain, as you see, growing up, I was the biggest sci-fi geek in the family. There are still boxes of old paperbacks in my mom's attic that can attest to a large chunk of my misspent youth and failing eyesight. Andy was more into the D&D stuff with which I had a short-lived romance due to the Tolkien influence, but then high school, sports, and girls came into the picture for me, and well... my hormones and ADD kicked into high gear and I found other romances with which to 'mis-spend' my youth.

Of course, we kids were all into comics in a big way. Like it was only yesterday, I can recall those countless trips to Dr. No's where we spent hours digging through the comic racks and stacks of sci-fi and fantasy books. (Andy, can you believe they're still in business!?) I was hip on Silver Surfer, Fantastic Four, X-men, Green Lantern, Thor, Iron Man, to name just a few. Who'd ever thought it would ever be useful to one of us?

From junior high through college, I found time to write stories, mostly scifi and fantasy, but after graduation making a living wage got in the way of pursuing it further. I spent a few years working at a bookstore in Atlanta - probably mostly from a desire to be close to my heroes - then I left for Seattle, where I studied film and video production at the University of Washington. But I had trouble finding work in film, got sidetracked into programming - something I had a knack for back in college - and the money was just too tempting. Not so much for what it could buy me, as I've never been a big consumer of anything except maybe books, but the lure was more for not having to worry about how I was going to pay the rent that month. Then the next thing you know, I have a wife, mortgage, kids, and life insurance.

I often find myself looking back, wondering what I might be doing now if I'd stuck it out a bit longer or moved back to L.A. to find work.

So I'm doing a lot of self-questioning these days, having strange dreams and seeing messages in things, books, and movies that seem directed toward me personally. Is this a mid-life crisis, or the early onset of schizophrenia? Or is the 'Verse trying to tell me it's time to dust off the old dreams and try something new (and old)?

Saturday, October 29, 2005

do you really want to know?


Want to know why a good portion of the world hates the U.S.?
Want to know the real reasons behind 9/11?
Want to know why we are fighting a war in Iraq?
Want to know what's wrong with corporate America and the current state of "free market" capitalism?

If you really want to know, then read Confessions of an Economic Hit Man by John Perkins.

no truer shiny words were spoken

I'm at a place in my life where these words hit me in a deep place.

Capt. Malcolm Reynolds: It ain't all buttons and charts little Albatross. You know what the first rule of flyin' is? Well I suppose you do, since you already know what I'm about to say.

River Tam: I do, but I like to hear you say it.

Capt. Malcolm Reynolds: Love. You can know all the math in the 'Verse, but take a boat in the air you don't love, she ain't keepin' up just as sure as the turning of worlds. Love keeps her up when she ought to fall down, tells ya she's hurtin' 'fore she keens, makes her home.

River Tam: Storm's getting worse.

Capt. Malcolm Reynolds: We'll pass through it soon enough.

-- From the movie Serenity, written and directed by Joss Whedon.

Am I flying the wrong ship? Will I make it through this storm?

Wednesday, October 26, 2005

Textile Templates with Rails in 10 lines or less

The template code goes in myapp/lib/textile_template.rb:



You register the file suffix with the template handler in either the myapp/app/controllers/application.rb or myapp/config/environment.rb:



Put your textile formatted file in your view:



And you're done!

Saturday, October 15, 2005

dave astel's behavior driven design with ruby

I read Dave Astel's A Pratical Guide to Extreme Programming some time back, and I just started reading Test-Driven Development. So, I'm excited to hear that he may start work on a new book about what he is calling Behavior Driven Design, an approach that extends the concept of unit testing to a higher level where you are thinking less about verification of code at the unit level and more about the specification of design at the behavior and context level.

Dave and company have begun an xUnit type framework around this idea. Low and behold, Steven Baker, Aslak Hellesoy, Gabriel Baumann, and Dave wrote rSpec in Ruby, available as a gem.

In his intro paper on BDD, Dave says:
"Thinking about unit testing leads us to divide tests in a way that reflects the structural arrangement of the code. For example, having text classes and production classes in a 1-1 relationship. That's not what we want... we want behavioural divisions.. we want to work at a level of granularity much smaller than that of the typical unit test. As I've said before when talking about TDD, we should be working with very small, focused pieces of behaviour... one small aspect of a single method."

He goes on to show an example of some specs for a Movie and MovieList class:

require 'spec' 
require 'movie'
require 'movie_list'

class EmptyMovieList < Spec::Context
def setup
@list = MovieList.new
end
def should_have_size_of_0
@list.size.should_equal 0
end
def should_not_include_star_wars
@list.should_not_include "Star Wars"
end
end

class OneMovieList < Spec::Context
def setup
@list = MovieList.new
star_wars = Movie.new "Star Wars"
@list.add star_wars
end
def should_have_size_of_1
@list.size.should_equal 1
end
def should_include_star_wars
@list.should_include "Star Wars"
end
# vc: I added this bit
def should_not_include_serenity
@list.should_not_include "Serenity"
end
end


So now with a specification for the behavior of the classes, you implement the system to pass the spec.

Here's what I came up with to implement the classes to test out rSpec:

class Movie
attr_accessor :title
def initialize(title)
@title = title
end
def to_s
@title
end
end

class MovieList
def initialize
@list = []
end
def size
@list.size
end
def add(movie)
@list << movie
end
def include?(title)
(@list.find {|movie| movie.title == title }) != nil
end
end


Now you run 'spec' from the command line. (I don't think they have a runner yet).
>> spec spec_movie_list.rb

.....

Finished in 0.01058 seconds

5 specifications, 5 expectations, 0 failures

Voila, the classes pass the specification!

You can find out more on Dave Astel's blog, the original post that started it all, and this podcast.

[UPDATE: Steven Baker is giving a workshop on Agile Rails Development at Canada on Rails this April. Looks like he will be talking about TDD vs. BDD and likely his RSpec testing framework. I'm having trouble deciding which conference I should attend this year. Vancouver is closer (and cheaper) than Chicago, but they haven't announced who the speakers are or what the sessions will be yet, so hard to say.]

Friday, October 07, 2005

quick and dirty xmlserializer in ruby

I've been thinking about how one might transfer objects in Ruby to XML and JSON for use in an AJAX application. There may be libraries that do it already, but I thought it might be an interesting exercise anyway.

Here's my first stab at adding XML serialization to any object. The idea is that all public attributes would be available as XML elements.

class Object
def xml
root_name = self.class.name.downcase
s = start_element(root_name)
self.instance_variables.each do |getter|
getter.gsub!(/@/, '')
# Set an id property as a class attribute
if getter == 'id'
s.gsub!(/<#{root_name}/,
"<#{root_name} id=\"#{self.send(:id).to_s}\"")
else
s << build_element(getter, self.send(getter).to_s)
end
end
s << end_element(root_name)
end
private
def build_element(name, value)
start_element(name) +
value.gsub(/ .gsub(/>/, '&gt;').gsub(/'/, '&apos;') +
end_element(name)
end
def start_element(name)
"<"+name+">"
end
def end_element(name)
""
end
end

require 'date'

class Person
attr_accessor :name, :dob, :phone, :id, :email
end

p = Person.new
p.id = 12345
p.name = "Shawn O'Malley"
p.dob = Date.new(1975, 1, 28)
p.phone = "555-555-5555"
p.email = "somalley@foobar.com"

puts p.xml

# => <person id="12345">
# <dob>1975-01-28</dob>
# <email>somalley@foobar.com</email>
# <name>Shawn O'Malley>/name><phone>555-555-5555</phone>
# </person>

Monday, October 03, 2005

TextMate and Rails


I've been twidling with TextMate's commands in an attempt to automate some of the common Rails commands.

Unfortunately, as far as I can tell TextMate doesn't have a way to invoke a pop-up for input (like Eclipse), so I've had to settle for sending in single arguments via selected text. So after creating a new app, I just create a setup.txt file in the project root where I can enter things like the port to start WEBrick and the names of the controllers, scaffolds, and models I want to generate.

Another issue: I've had to start WEBrick as a daemon with the -d switch; otherwise TextMate locks up. And another downside is I have to shut it down via command line after checking for it's process id. There's got to be a better way to start and stop the server from inside TextMate, but I haven't worked it out.

Here's the bundle of commands. You can unzip it to your /Users/[username]/Library/Application Support/TextMate/Bundles/ folder.

If anyone has any better versions of these commands, please let me know.

[UPDATE: Thanks to suggestions from the author of TextMate I now have some better ways to enter input and control WEBrick using HTML and JavaScript. I'll post the changes as soon as I've got them working the way I want. Check the comments for Allan's recommendations or see his blog.]