Sandy now has a motorcycle license. Or rather, as soon as she goes to the DMV she just has to pass their written test and gets the "M" designation. I, however, failed the class. In a very frustrating way. For most of the class I was on a DR 200 for most of the class. I had tremendous difficulties with both the rear brakes (situated under your right foot) and with the gearshift (which is situated at the tip of your left foot). The reason for this is I wore my enormous Vasque boots for protection. I couldn't feel where the controls were with my foot, and I couldn't fit my feet where they were supposed to be, so I rode very poorly, in general. Once I got the bike moving, it was a lot easier to drive. I was situated, my feet were properly placed (or at least clutching the bike in roughly the right place), and I had no problems handling the bike. A lot of the stuff you learn for high speed driving in a car applies to a bike. MSF talks about having a "twelve second" view down the road. Yeah, that's about right, as I think about how I drive the Subaru when we're pushing it hard.
So I dropped the bike. That's the big news, I guess, other than Sandy passing or my failing (I think the latter was much less expected than the former). I'm okay. It was on a tight left turn, and I wasn't leaning far enough out (bringing my center of gravity down to the point where it upset the bike). The bike fell out from under me, landed more or less across my waist, and no big deal. But the handlebars were perpendicular to me as the bike was coming down, and I took a real big hit to rib #3 on my left. Right about at the sternum, maybe an inch or so left. It's broken. I mean, you can feel it. Plus, I'd broken ribs before, and knew what the feeling was.
The instructor asked me if I wanted to go to the hospital and I said no. The reason for this is there is no way to "mend" a broken rib. You get X-rayed to make sure you haven't punctured your lungs or heart, and they give you percocet if you're lucky, tylenol #3 or motrin 800 if you're not, and send you on your way. Congratulations, you've broken a rib. Enjoy your pain.
I don't know what I'm going to do about the license. I might be able to pass the class if we could both adjust where the pedals are (they're all adjustable) and get me shoes that meet the requirement for the class but which are thin enough to fit into the right places.
Broken rib. Shit, this hurts.
16 May, 2007
Documentation and more.
Sandy had surgery today. So I spent a lot of time in the hospital doing nothing
but farting around on the laptop (because worrying wasn't going to make her any better).
I originally wanted to munge through my itunes library with ruby and then see if I could push that into last.fm so it had a "history" going back to 2002 or thereabouts (right now I'm around 2,200 tracks on last.fm, I think). Anyways, so I gets to my hackings and I get stuck right around the top. I want to create a class that will be a container for both the track metadata and the track data itself. But what's the syntax? I start looking around for ruby documentation and find nothing. In fact, I see this bit of evilness:
What the hell was Apple thinking? They have mostly functioning ruby, perl, and python installations, which is A Good Thing on user-focused Unixes. But where perl and python have been given not just documentation but examples, ruby has no documentation (not even the documentation that ships with the distribution), and is in fact so poorly supported that we have (good) monstrosities (good in the way that japan loves Godzilla; with apologies to Rob and his monster) like Locomotive. Locomotive is cool, but it only includes the relevant documentation necessary for Rails. And who can blame them? Rails is good stuff, and really, I should alreadyhave a full set of ruby documentation if I want to be hacking rails, right?
Anyways, the grapevine tells me there's a lot of the snake going around in Cupertino. That kind of worries me because I both fear and loathe its snakely ways. While I don't see anyone "kicking ruby out of the base install," I also don't see there being examples in Leopard's Developer disc for ruby (prove me wrong, Fred! please!). Conversely, I bet there will be lots more python examples. It kind of bugs me that there's so much love for the snake, that perl is (of course) included because it's essentially a legacy language, but ruby is sort of thrown in as an afterthought. (and speaking of afterthoughts, how's this for an idea: publish an API to the iTunes Music Store just like Amazon, Google, and so many other renaissance companies. Let your customers build tools that sell your products! You can keep your DRM – even though I know how you hate it, Steve – but let people search through the store and make purchases!)
So, getting back to the documentation thing, I couldn't remember the exact syntax for setting up the classes I needed to, and I couldn't find the documentation which would have revealed it for me. I spent what was probably enough time to find out from just reading the source searching frantically for some hidden ruby.tgz or man install (there are gadzillions of .rb files after you install things like Locomotive; I could have gone through these and infinite-monkeyed their syntax, but I really wanted to go by the documentation since I don't feel that comfortable with ruby yet), and came up entirely empty.
What else was there to do but reach for the tourniquet, find a vein, and dust off my perl habit? Really, it's all there, and documented and stuff (remember, the original goal was to read the iTunes Music Library XML; I am aware there are projects that do this already, so remember again that I am in the hospital waiting for my wife to come out of surgery without intarwebs access).
So I set up a simple class:
I ordinarily use Class::Contract or Params::Validate in object creations, but Apple is missing them in their perl install. Anyways, looking at the above, the tricky part is the "pid" pieces. Apple has what they call a "Persistent ID." I am willing to trust that it is what they say it is. It looks something like "ACE4901A5ECC96A5", so it's probably unique and can be used as a primary key, or whatever. Worth saving, but not necessary to have, per se.
So I give the user the option to provide the PID as the last argument to the constructor, but there's a problem with the blessing. We're returning them a blessed hashref, which is quite fashionable as objects go (your coworkers willlove get angry with you if you return blessed \$^O, sub { foo } or other perl miscellany). However, because it is a hash, we have to have a key for pid. But what if the user didn't give us a pid to begin with?
I added the last line to the blessed hashref to leave an empty list as the last element (this would prevent the returned hash from having a "pid" key at all). The notion being, the ternary question of whether pid is defined results in either a ( pid => $pid ) key/value or in the empty list. Personally, I thought that was clever, and got me out of the problem of leaving the pid key in there and having users covet my object's internals, seeing "pid," and making use of it.
But beware your operators, my hackers! Their precedence, which might precede or follow! Beware the parenthesied ternary operator and shun the frumious empty list!
Documentation in hand, I consult perlop(1):
Ternary has much higher precedence than the comma operator, so I think what perl is actually seeing the comma operator where the second half of the ternary – the ':' – is supposed to be. It has been said that only perl can parse perl. It is ambiguities like this that cause people to say this (and are a large part of why I am wholeheartedly and stupidly in love with it).
One, two! And through and through! The vorpal operator went snicker-snack and left the last element of this hash either a key-value pair or an empty list.
... And then went galumphing back.
It's amazing what you can do with a little documentation. It's not especially amazing how little can be done without it. It took me two days of floundering through icky ruby documentation to figure out how to talk over a Unix socket, when all the necessary information was available in one perl man page (to be fair, also in socket(2); but this applies to ruby as well)
I've spent most of the last week just hacking around on my own shit. I've picked up enough ruby to be dangerous, and I've even started getting back into munging XML and SQL with perl. It's such a shame that, while I love to program, when I program for a living, I never get to write anything I love writing. It would be nice to be in a polylingual environment, where I could say "you know, today I think I'm going to write this solution in ruby as long as nobody minds." I hear Google's like that. On the other hand, they think that somebody who was stupid enough to spend ten years of their life in college is actually smarter than somebody who spent those same ten years in the career of their choice. I digress.

So the reason I've had time to hack for myself is that I'm waiting for a few investigations to finish up before we can execute project Taipei, where I will be working with Dr. Ikari at NERV. I can't wait for the briefing. O frabjous day! Callooh! Callay! Details to follow.
but farting around on the laptop (because worrying wasn't going to make her any better).
I originally wanted to munge through my itunes library with ruby and then see if I could push that into last.fm so it had a "history" going back to 2002 or thereabouts (right now I'm around 2,200 tracks on last.fm, I think). Anyways, so I gets to my hackings and I get stuck right around the top. I want to create a class that will be a container for both the track metadata and the track data itself. But what's the syntax? I start looking around for ruby documentation and find nothing. In fact, I see this bit of evilness:

What the hell was Apple thinking? They have mostly functioning ruby, perl, and python installations, which is A Good Thing on user-focused Unixes. But where perl and python have been given not just documentation but examples, ruby has no documentation (not even the documentation that ships with the distribution), and is in fact so poorly supported that we have (good) monstrosities (good in the way that japan loves Godzilla; with apologies to Rob and his monster) like Locomotive. Locomotive is cool, but it only includes the relevant documentation necessary for Rails. And who can blame them? Rails is good stuff, and really, I should alreadyhave a full set of ruby documentation if I want to be hacking rails, right?
Anyways, the grapevine tells me there's a lot of the snake going around in Cupertino. That kind of worries me because I both fear and loathe its snakely ways. While I don't see anyone "kicking ruby out of the base install," I also don't see there being examples in Leopard's Developer disc for ruby (prove me wrong, Fred! please!). Conversely, I bet there will be lots more python examples. It kind of bugs me that there's so much love for the snake, that perl is (of course) included because it's essentially a legacy language, but ruby is sort of thrown in as an afterthought. (and speaking of afterthoughts, how's this for an idea: publish an API to the iTunes Music Store just like Amazon, Google, and so many other renaissance companies. Let your customers build tools that sell your products! You can keep your DRM – even though I know how you hate it, Steve – but let people search through the store and make purchases!)
So, getting back to the documentation thing, I couldn't remember the exact syntax for setting up the classes I needed to, and I couldn't find the documentation which would have revealed it for me. I spent what was probably enough time to find out from just reading the source searching frantically for some hidden ruby.tgz or man install (there are gadzillions of .rb files after you install things like Locomotive; I could have gone through these and infinite-monkeyed their syntax, but I really wanted to go by the documentation since I don't feel that comfortable with ruby yet), and came up entirely empty.
What else was there to do but reach for the tourniquet, find a vein, and dust off my perl habit? Really, it's all there, and documented and stuff (remember, the original goal was to read the iTunes Music Library XML; I am aware there are projects that do this already, so remember again that I am in the hospital waiting for my wife to come out of surgery without intarwebs access).
So I set up a simple class:
package Track;
sub new {
my ($track_id, $name, $artist, $album) = (@_);
return undef
if grep undef, ($track_id, $name, $artist, $album);
# pid is optional, and should be in the metadata, but the user
# may find it convenient for it to be here as well.
$pid = pop if 5 == @_;
bless {
track_id => $track_id,
name => $name,
artist => $artist,
album => $album,
# our syntax fails here
( defined $pid ? pid => $pid : () ),
}, shift
}
1;
I ordinarily use Class::Contract or Params::Validate in object creations, but Apple is missing them in their perl install. Anyways, looking at the above, the tricky part is the "pid" pieces. Apple has what they call a "Persistent ID." I am willing to trust that it is what they say it is. It looks something like "ACE4901A5ECC96A5", so it's probably unique and can be used as a primary key, or whatever. Worth saving, but not necessary to have, per se.
So I give the user the option to provide the PID as the last argument to the constructor, but there's a problem with the blessing. We're returning them a blessed hashref, which is quite fashionable as objects go (your coworkers will
I added the last line to the blessed hashref to leave an empty list as the last element (this would prevent the returned hash from having a "pid" key at all). The notion being, the ternary question of whether pid is defined results in either a ( pid => $pid ) key/value or in the empty list. Personally, I thought that was clever, and got me out of the problem of leaving the pid key in there and having users covet my object's internals, seeing "pid," and making use of it.
But beware your operators, my hackers! Their precedence, which might precede or follow! Beware the parenthesied ternary operator and shun the frumious empty list!
Documentation in hand, I consult perlop(1):
Ternary "?:" is the conditional operator, just as in C. It works much like an if-then-else. If the argument before the ? is true, the argument before the : is returned, otherwise the argument after the : is returned.
Ternary has much higher precedence than the comma operator, so I think what perl is actually seeing the comma operator where the second half of the ternary – the ':' – is supposed to be. It has been said that only perl can parse perl. It is ambiguities like this that cause people to say this (and are a large part of why I am wholeheartedly and stupidly in love with it).
# original: ( defined $pid ? pid => $pid : () ),
# correct : defined $pid ? (pid => $pid) : (),
One, two! And through and through! The vorpal operator went snicker-snack and left the last element of this hash either a key-value pair or an empty list.
... And then went galumphing back.
It's amazing what you can do with a little documentation. It's not especially amazing how little can be done without it. It took me two days of floundering through icky ruby documentation to figure out how to talk over a Unix socket, when all the necessary information was available in one perl man page (to be fair, also in socket(2); but this applies to ruby as well)
I've spent most of the last week just hacking around on my own shit. I've picked up enough ruby to be dangerous, and I've even started getting back into munging XML and SQL with perl. It's such a shame that, while I love to program, when I program for a living, I never get to write anything I love writing. It would be nice to be in a polylingual environment, where I could say "you know, today I think I'm going to write this solution in ruby as long as nobody minds." I hear Google's like that. On the other hand, they think that somebody who was stupid enough to spend ten years of their life in college is actually smarter than somebody who spent those same ten years in the career of their choice. I digress.

So the reason I've had time to hack for myself is that I'm waiting for a few investigations to finish up before we can execute project Taipei, where I will be working with Dr. Ikari at NERV. I can't wait for the briefing. O frabjous day! Callooh! Callay! Details to follow.