
By the time he was done, he had cake in his hair, ears, and down his back. He beamed, eyes twinkling, with true happiness as we all sang happy birthday to him. He knew we were adoring him, and the little munchkin ate it up, along with the cake.

It's funny, Laura and I were reflecting on the night that Javier arrived. We were up late watching Battlestar Galatica (great great show) and about half way through, Laura starting having contractions. As with all pregnancies, you don't know how much time you have, and this being our third child we could have easily had the little boy right there on the coffee table during the commercial break. Laura, however, sci-fi chick that she is, sucked it up and said that it'd be fine, that we could finish Battlestar Galactica.
"Are you sure?" I asked.
"Yeah, I guess so."
So little Javier, I just want to say on your 1st birthday, thanks for letting us watch our show. You're the best. And Laura, you win the Sci-fi-chick-of-the year award.
Pardon me while I geek out again. This particular article falls under the, "look Ma, no hands" category, a shameless play for adoration of my cleverness. What I'm about to show is neither new nor terribly beautiful, nor cost effective for most professional flash designers and/or web designers.
It's just cool that it was done procedurally and entirely on Linux. First, another caveat; I absolutely do not get these animation tools with their tweening, paths and visual interactions for creation of animations. For some reason, when I animate my stupid brain sees a stack of cells, straight up and down. I see the frame changes like a flip book. If I try to abstract an object in the animation into some sort of mathematical formula, line, path, or whatever, my little pile of gray matter goes all slushy. Also, my brain likes to see things in text. I know, I know, what's the matter with me? I don't even see the code. All I see is blonde, brunette, red-head. Chuckle.
Here's the finished product: www.og-consulting.com
The door scene modeled in POV-ray scene description language and is typical of Old San Juan, Puerto Rico Spanish Colonial architecture. The real doors are beautiful. If you ever get a chance to take a cruise from/to Puerto Rico, don't miss the chance to walk around Old San Juan (El Viejo San Juan) and check them out. I rendered three frames with the doors rotated from 0 to 75 degrees to simulate... guess what? Opening doors. Clever, huh?
There's a lot of POV code, here's a little bit of what it looks like:
cylinder { <0, 0.5, 0>, <0, -0.5, 0>, 0.5
texture {
pigment { color rgb <0.6, 0, 0> }
normal { granite 0.02 turbulence <0.5, 0.9, 0.2> scale 0.25 }
finish { specular 0.1 reflection .1 }
}
}It's pretty simple. You place objects in an X-Y-Z space (Cartesian coordinates) like a sphere, cylinder, box or any other of the predefined primitives. You can merge them, subtract them, intersect them in creative ways. Finally, you apply some sort of texture which includes a pigment, a surface (normal), and a finish (reflections effects etc). There are easier ways to model, but sometimes POV-ray's scene description language is just the most elegant and easiest way to model something.
The next step was to convert the png files to jpegs for inclusion in
the flash animation. I used a little sprinkle of bash and a dash of
kosher ImageMagick's convert.
for file in *.png; do convert -quality 100 "$file" "${file%.png}.jpg"; done
For
each png file, convert the png file to a 100 percent quality jpeg
file. We use 100% quality because I'm going to let the swftools take
care of the final compression. There's no sense in lossy compressing
then lossy compressing again. That's just crazy talk.
We will now create the flash source file. Open a new file slideshow.sc. This is the textual language for the swftools Linux Flash toolkit. I have never ever ever looked at a flash source file from any Macromedia product, so I have no idea if this animation description method looks/acts/walks/talks in anyway shape or form like Macromedia's products. Don't know, don't care.
.flash bbox=640x480 filename="slideshow.swf" version=6 fps=25 compress background=white
.jpeg s1 "puerta_open03.jpg"
.jpeg s2 "puerta_open02.jpg"
.jpeg s3 "puerta_open01.jpg"
.font font "gilc____.ttf"
.font arial "arialbi.ttf"
.text text1 color=white text="Opening Doors" font=font
.text text2 color=white text="Opening Doors" font=font
.text text3 color=white text="Opening Doors" font=font
.text text4 color=white text="OG" font=arial
.text text5 color=white text="Experts in" font=font
.text text6 color=white text="Open Source" font=font
.put s1 scalex=640 scaley=480 alpha=100%
.put text1 scale=100% x=40 y=220 alpha=0%
.frame 25
.put s2 scalex=640 scaley=480 alpha=0%
.change text1 alpha=100%
.put text2 scale=100% x=40 y=220
.frame 100
.change s2 alpha=0%
.change text1 alpha=100%
.change text2 alpha=100%
.frame 125
.change text1 alpha=0%
.change text2 alpha=100%
.change s2 alpha=100%
.put s3 scalex=640 scaley=480 alpha=0%
.put text3 scale=100% x=40 y=220
And
so on (that's not the whole file, but the rest is just repetition.
There are 71 total lines of code for that little flash animation. Is
that a lot or a little? Seems pretty small to me anyway. Basically,
with swftools you define an object (image, or text); you put it; then
you change it. You can change its fade, size, location, and more. The
swfc program will implement the change from the object's last known
state. Check out swftools for more examples (that's where I got all the reference I needed to make my little flash thingie).
So there you have it. I walk through the frames, changing elements, putting, fading, growing, moving stuff around. It's was all described from start to finish in a procedural language, from the POV-ray scene description language, to bash and ImageMagick for command line image manipulation, and finally to swftools flash scene language for the final animation. Pretty nifty, huh?
The neat thing about this is
that once the procedure has been developed, you can reuse it for other
clients, other looks, colors, messages, etc. In fact, you could
directly render it on the server to update information on the fly via
end user input. There's no limit to what you can do with something
like this.
Of course if you're on Windows, you would probably just buy Macromedia's software... but where's the fun in that?
Last night I was at the juvenile processing facility. I got to meet a kid named Phillip. American name, but didn't speak a word of English. I thought it weird. Whatever.
He was a baby, barely 15, but he wanted to be a boxer. He'd trained with his uncle before winding up in prison on a year and half sentence. I secretly wondered what a 15 year old could do to wind up in prison for 18 months. Geez. Either that or what I've heard about the racket of "lawyers" extorting money in the projects para bregar was actually true.
"You have a friend who gives you a Playstation... what do you do with it?"
Puzzled look - like I was trying to trip him up with a trick question, like if he said, play the damn thing, I'd zing him and say... no you give it to charity and spend more time in church on your knees thanking the good Lord for your life. Remember to wail and gnash your teeth. He loves that.
"You would... " I motioned with my thumbs as if to fiddle with the controller.
"Play it?"
"Yeah!" I exclaimed, "You play the thing. That's why your friend gave it to you. And what is a Playstation for? To be P L A Y E D."
Phillip smiled a 15 year old smile, ear to ear, clean teeth to clean shining teeth.
"So now you've got this Playstation that you didn't ask for. You kind of know what to do with it, but it's really no fun by yourself. Who do you call first?"
"Mis amigos?" He offered.
"Right. Then you get together and share your gift with your buds. You pass time with them sharing the Playstation."
"Yeah." Phillip smiled again.
"Phillip, what's your talent? What do you want to do with your life?"
Phillip hesitated. I don't know why, I had not been trying to trick him. The quickest and most natural thought is usually the right one. I had not led him astray up to that point. He stilled seemed to be searching for some kind of noble Godly vision of what he should be doing with his life instead of what he wanted to do, what he was good at. He gathered the courage and offered:
"I want to be a boxer."
"Cool," And without missing a beat, "Did you know that Jesus was a boxer?"
Again Phillip was thrown for a loop. Jesus a boxer? How could it be? Boxing isn't Godly. Boxing isn't pious. Boxing is at best the red-light district of sports and humanity.
"Have you ever heard the phrase, 'leave it all on the field'? Or in your case 'leave it all in the ring'?""No." He looked at me quizzically.
"Well, after you fight, you should barely be alive. After you finish, you shouldn't be able to stand. After you are through, you will have nothing more to give, no interviews, no congratulations, no celebrations, and if you lose no sorrows, no regrets, nothing. You will have used it all up and left it in the ring."
Phillip looked at me, eyes wide in puzzlement or amazement.
"Phillip, for what purpose do you have this life? Did you ask for it?"
"Eh?"
"Are you going to get out alive? Does anyone live forever?"
"No, I guess not."
"Isn't it a gift like the Playstation? Aren't all gifts just that; not asked for? And just like a gift that you didn't ask for, the best thing you can do with it is use it, before it breaks, before it become obsolete... or the Playstation III comes along." Phillip chuckled. "What would you save it for anyway? You've got to use it.
Jesus
wasn't just a boxer? He was the champion of the world, uncontested,
undefeated, even in death. He knew one thing that only the greatest
champions have ever come close to knowing. He knew that how you do a
thing is more important than anything else. That whatever you do, you
live it fully, completely, with no regrets.
When you box, it's a spiritual exercise. In order to do it well, you've got to study it. You have to train. You have to discipline yourself. You must have respect for it. With all the things you do you pay homage to your life and your life is that which has been given to you as a gift. You honor your gift by being the best boxer you can be.
Remember too, though, that all gifts carry a burden. You have a heavy responsibility. If you want to be like Miguel Cotto
you have a heavy burden to carry. You might see his victories, his
money, or his fame, but his bouts show his discipline, his patience,
his devotion to his craft. He's not hanging with his friends in the
evenings. He's training early in the morning and getting his rest.
When he's not training or resting, he's probably reviewing films,
studying his sport or eating a special diet. Yes, he has time for
friends, but he's a championship boxer and it's not easy. And he's
surely not getting in trouble.
Phillip, is this future what you want? Do you accept this? Will you take up the burden, the responsibility, and the commitment to make your dream a reality?"
"Yes."
Yes, I understand this is going to be a weird post for some of you. Frankly, I haven't been writing enough about what I spend most of my day doing, so here it is.
I have been having a bafflingly hard time trying to figure out the proper way to insert multiple child records from one single webform. It is the standard fare for posting things like invoice headers and details. Say for example, you've got an invoice record which consists of an order number, date and whatnot. That particular piece of tabular data is then considered the parent of its child line items (product_id, description, quantity, price, etc). So you've got this Order which consists of an invoice and line items.
It's pretty basic, but I've had the hardest time figuring out how to do this is Ruby on Rails. I know it's not hard in theory, but with Rails, since there is only One Right Way(TM) to do things, 'cause you're on Rails, it takes a bit of doing to figure out this Right Way(TM). I personally don't have a problem doing it Rails' way, but please dear God, just tell me what it is. I bought the book and everything.
So
here's the dope, folks. Please correct me if there's a better way of
doing this, 'cause I'm a Rails newb. For reference sake, I am using
Ruby on Rails 1.0 with Postgres 8.0.4 and Ruby 1.8.4
First the webform:
<ul id=items>
<% for item in @items %>
<li><%= check_box_tag 'line_item', item.id, checked=false,
{:name => "line_item[item_id][]", :id =>
"line_item_id_#{item.id}" } %><label for="line_item_id_<%=
item.id %>"> <%= item.title %></label></li>
<% end %>
</ul>
Make sure to use check_box_tag instead of check_box. check_box inserts a hidden text input that defaults. From http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html
The checked_value defaults to 1 while the default unchecked_value is set to 0 which is convenient for boolean values. Usually unchecked checkboxes don’t post anything. We work around this problem by adding a hidden value with the same name as the checkbox.
You don't want that. You want the plain vanilla check_box_tag which does none of that nonsense, because you in fact, don't want your line_item table being filled with up with all kinds of line_items referring to product "0" or product "NULL".
So that's our form. The line <% for item in @items %> comes
from the items.rb model and is just a little database query to get all
the items associated with a particular order for posting in our
invoice. Why would we use checkboxes? Well, maybe we're not going to
invoice the whole order. Maybe we're out of some items. We'll let our
warehouse guy check off the checkboxes on his wireless pda. How's that?
If you were watching closely, you'll notice that I modified the check_box_tag behavior with options of my own with the following:
:name => "line_item[item_id][]"
This is what gives us multiple lines (an array of items) to pass to the controller. [] is the important part.
Now, so far this is easy, or at least I thought so. I've done this a hundred times in php, but that's just the problem, I got tired of writing and re-writing this. I wanted Rails to handle all the parent child relationships for me and leave me alone. I'm lazy.
But I
couldn't figure out exactly how to do this. Frankly, I'm still trying
to fit all the method/class/object/instance/variable blah blah blah
into my head and keep all the Invoice invoice invoices straight. I
know, I know, it's probably me, but I'll wager there are a few more
slow-witted programmers out there for whom this is all so confusing. A
phrase that I have been becoming more familiar with while working in
Ruby on Rails is, "Use the force." It's funny, but most of the time
when I relax and make stuff up without trying to "understand," things
usually Just Work(TM). Jedi Programming... who knew?
So we've got our form. Now we need to post the parent and the children in one fell swoop.
Now the models (no, not Victoria's Secret). Invoice will not reference the children (the children will come running when they hear their parent's voice regardless of whether they are called by name). The parent "has_many" children and does not bother remembering their names or ids or anything. The children on the other hand "belong_to " (or reference) the parent and are tattooed with the parent_id stamp of ownership (big ears for example). When they are required, they will all line up under the parent and file out like good little children.
Got it? Parent -> has_many :children, Child -> belongs_to :parent
Now we need to post the stuff. This is a snippet from the invoice_controller.rb:
def create
@invoice = Invoice.new(params[:invoice])
@invoice.order_id = @session["order_id"]
for item_id in params[:invoice_item][:item_id] do
@invoice.invoice_items << InvoiceItem.new(:item_id => item_id)
end
if @invoice.save
flash[:notice] = 'Invoice was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
order_id is stored in session variables and is used to reference the invoice. The invoice in turn has items added to it for each item_id in the params passed from our form. What happens on @invoice.save is the following:
I went out the other day on my bicycle to buy some milk. I suited
up, grabbed some cash and headed out the door. My morning was
uneventful up to that point, routine. It was about to go awry, but not
while I was on my bike, no thanks to the cruel fates who would have
loved for this little memoir to have started off differently.
After I returned, I realized that I had to replace the car's registration sticker. It had expired the 28th and I had to put on this year's new little sticker so that I could be legal and that no one could call me illegal and take my car away. I grabbed a razor blade scraper thingie, some Windex(TM) registered patented trade-secreted intellectually propertized brand glass cleaner, and my new little sticker, clutched in my paw like the last Cheetos brand(TM) original corn puff snack of goodness on the planet.
Or maybe I felt a little like a first
grader in craft class. Whee, what were we going to make? I've got my
pencil, my paste, and my paper.
Scrape scrape scrape, went the razor.
Smudge smudge smudge went the sticky glue bead balls.
Tear tear tear went the old sticker.
Curse curse curse went the Jimmy.
Spray spray spray went the Windex.
Wipe wipe wipe went the paper towel.
Smudge smudge smudge went the window.
Sigh. Finally the surface was prepared, and I applied the sticker. Look, mom, no bubbles. But the stupid thing was on upside down*.
It was going to be one of those days, eh?
*not
really, but it's funnier that way don't you think? I'm sure that's
what James Frey thought. Truthfully, my day was just fine, a bit
hectic, but then again that's life, doncha know.