All posts by jasonian

Writing code into the night

Every now and then I get into a code writing frenzy. Not that I’m much a programmer, but I enjoy the process (generally) and the satisfaction after a successful jaunt.

Last night (Tuesday), after a management meeting, I got back to the office, with the intent of catching up on email and heading out, when a question from a coworker got me investigating an issue.

I was able to get a basic (though not complete) answer out in a relatively short period of time, but finding the complete answer left me writing code into the late evening (and by “late evening” I mean 10pm. Yes, at work).

The problem was about the ability to receive drags from iTunes playlists and songs. I first looked at what iTunes was putting onto the OS X pasteboard by downloading and running PasteboardPeeker (from Apple’s Reference Libary).

The results of dragging an item from iTunes to PasteboardPeeker looked like this:

PasteboardRef: 3391984   ItemCount: 1
    Index: 1   item ID: 1
       "dyn.agk81a4dgsq"
       ""
       'phfs' ______ 14      hook  rWm1

       "dyn.agk81ez5rge"
       ""
       'rWm1' P_____ 70      H   04 Burnin .m4p

       "dyn.agk8yu6dgru"
       ""
       'Hpfl' ___n__ 70      H   04 Burnin .m4p

       "dyn.agk80w7dzr2"
       ""
       'itun' P__n__ 1754 

I had no clue what each of the items meant. (Remember, I’m not really a programmer, and I don’t know much about Carbon.) I spent about an hour (re-) writing code to handle the dragged items (I started with CocoaDragAndDrop, another sample code from Apple’s Reference Library), with many false starts, trying to figure out how to interpret ‘phfs’, and so on.

I ended up modifying CocoaDragAndDrop to output the raw drag and drop information (looking back, I should have probably done this from the start, but I was learning as I went along). I added the following code:

NSPasteboard *pboard;
pboard = [sender draggingPasteboard];
NSLog(@"Types: %@", [pboard types]);

This returned

Types: (
"CorePasteboardFlavorType 0x70686673",
"Apple files promise pasteboard type",
"CorePasteboardFlavorType 0x72576D31",
"CorePasteboardFlavorType 0x4A524653",
"CorePasteboardFlavorType 0x4870666C",
"CorePasteboardFlavorType 0x44736964",
"CorePasteboardFlavorType 0x4F69646C",
"CorePasteboardFlavorType 0x6974756E"
)

Hm. A few Google searches later, I found propertyListForType, and, after some trial and error, figured out that CorePasteboardFlavorType 0x6974756E gave me a dictionary I could easily parse out:

{
 "Application Version" = "6.0.3";
 Features = 1;

[...]

 Tracks = {
  333 = {
   Album = "Wicked (Original Broadway Cast Recording)";
   Artist = "Idina Menzel & Kristen Chenoweth";
   [...]
   Location = "file://localhost/Volumes/[...]
   Name = "Defying Gravity";
   [...]
   "Store URL" = "itms://itunes.com/album?p=4426862&s=143441&i=4426835";
   "Track ID" = 333;
   "Track Type" = File;
  };
 };
}

Excellent! With just a few lines of code, I could pull out any information I wanted about the dragged items. For example, I could grab the song name and artist easily enough:

NSPasteboard *pboard;   
pboard = [sender draggingPasteboard];

NSDictionary *iTunesData;
iTunesData = [pboard propertyListForType:
  @"CorePasteboardFlavorType 0x6974756E"];

NSDictionary *tracks;
tracks = [iTunesData objectForKey:@"Tracks"];

NSEnumerator *trackEnum = [tracks objectEnumerator];
id value;
while ((value = [trackEnum nextObject]))
{
  NSLog(@"Song: %@, Artist: %@", 
     [value valueForKey:@"Name"], 
     [value valueForKey:@"Artist"]);
}

This results in:

Song: Defying Gravity, Artist: Idina Menzel & Kristen Chenoweth

It was fun (and frustrating!) digging through Apple’s documentation, Google results and so on to piece together stuff I’d never dealt with before, and extremely satisfying to get a working application that lets me parse out any dropped iTunes item.

MacBook impressions

Had a chance to play with a new MacBook (white) today. 2 GHz, 512 MB RAM. First impressions:

  • It’s an iBook. Same milky white, glossy exterior.
  • It’s thinner than either my old 12″ iBook or my current 12″ PowerBook (though only barely for the latter).
  • It’s almost 2″ longer than my PowerBook. The PowerBook fits “inside” the MacBook.
  • The weight difference is noticeable in direct comparison, but is not significant with the lid closed.
  • Holding it by the edge, the weight is more noticeable (as when lifting to move around). More strain on my hand.
  • Opening the MacBook is much nicer.
  • The glossy screen, when turned off, is a mirror. When the screen is on, the gloss is not bad, under direct light (office, upward facing florescent, sunlight through drawn shades). It’s still there, however, just ghosted. It’s a little distracting, but not hugely so.
  • Doing a CD import, the first song ripped at about 5.3x, the second song at 8.5x.
  • Basic functionality feels fine.
  • Metallic power cable snaps into place with a rather satisfying click-thunk. Very cool.
  • Power cord has a neat “button” led showing orange for charging, green for charged, rather than the ring around cord.
  • The screen brightness is amazing, like night and day between the MacBook and PowerBook. Not even close.
  • They keyboard is… interesting. I like the sturdiness, but the spacing between keys is odd and and I feel I need to hit them harder and square on for them to register.

That’s it for now. Overall, looks like a very solid machine. I’ll probably pick one up before the end of the year. Probably pick up the black one though.

Hi, I’m a Mac….

You’ve probably seen them all over the place. They’re the new commercials from Apple Computer, touting the benefits of owning a Macintosh over a generic “PC”. There are six of them, and each highlights some benefit the Macs have, for example, the lack of thousands of viruses, or the easy connections to electronic devices.

The two actors are great. The Mac is depicted as young and hip by actor Justin Long, while the PC is portrayed as an older suit by John Hodgman. They each bring charm to the roles that might otherwise have come across as either whiney or defensive.

I’ve enjoyed them immensely (but then, I would), and the new Get A Mac campaign (which replaces the “Switch” campaign) has some great information (even if the tone is a little supercilious).

Me drink beer!

OK, so most people who know me know I enjoy beer. But not just any beer. No, it has to be good beer. No cheap watery beers for me, thank you very much. Some may say I’m rather a bit of a beer snob in fact. I tend to prefer beer connoisseur.

This is why I took great interest in the latest in “social software”, Coastr.com. (Have you noticed the trend to drop the vowel before a final consonant in these “social software” sites? Thanks Flickr.)

Coastr calls itself “the social guide to beer”, and aims to connect beer drinkers of similar tastes. They’ve even coined a rather disturbing term, “social beermarking”. Shudder.

The idea behind Coastr is to keep a list of the beers you like and the places you like to drink it, and see other people who have the same tastes. Of course, there’s also the “learn new beer” aspect: if a bunch of people who like the beers you like all like some other beer you’ve never tried, why not try it? (That’s the part I’m looking forward to the most!)

Influence… Take Three

Another precious quote from Ying:

I first fell in love with it in a parking lot in the back of Ron’s car

If you’re wondering what she might possibly be talking about, it’s her 15″ PowerBook.

Ah, double entendres… you can never have enough.

Open letter to TiVo and its advertisers

Dear TiVo:

I love my TiVo.

I also enjoy supporting TiVo and the TiVo advertisers by watching the various extended ads that often show up.

This was the case tonight, when my TiVo showed an “Exclusive Preview-24 Season Finale!” line, and selecting it offered me “an extended sneak preview of the 24 two-hour Season Finale event”, presented by Sprint.

Imagine my disappointment when instead of a “sneak preview”, we instead were treated to two minutes of flashbacks and recaps.

I was so disappointed that I didn’t even bother watching the Sprint ads themselves, and took time to write to you expressing my displeasure.

Please explain to Sprint and any other advertisers who may want to do something similar that it’s important they live up to their promises, or people like me will look askance at their advertising attempts.

It’s time for Animaniacs

And I’m zany to the max!

More than a decade since they first burst out of the water tower, Yakko, Wakko and their sister Dot will (finally!) be coming to DVD: Animaniacs, Vol. 1 will be released July 25, 2006. To add to the madness, that same day will also see Pinky and The Brain escape from their cages. Yes, Pinky and The Brain, Vol. 1 is also set to take over the world. Talk about faboo!

I can’t even being to explain how thrilled I am about the news. I’m a huge Animaniacs and PaTB fan. I own several toys (released at McDonald’s), an Animaniacs baseball cap (thanks Harris!), and the soundtrack. I’ve been hoping and wishing for a DVD release for ages, and was tremendously disappointed I could only get various VHS compilations (I haven’t used a VCR in probably five years, maybe longer!).

If you’re not familiar with Yakko, Wakko, Dot, Pinky, The Brain, and the multitude of other characters that forms the world of Animaniacs, I can only describe them as the very model of cartoon individuals. A cartoon ostensibly for children, many (so-called) adults found themselves addicted to the zany antics of these wacky animations.

The Warner Bros (Yakko, a Groucho Marx homage; Wakko, a food gorging Ringo Starr sound-a-like) and Dot, their awfully cute sister, made sly pop cultural references, parodied classic movies and songs, and engaged in relentless cartoon violence. Oh, and along they way, it also managed to educated kids with songs about the planets (“You forgot Uranus!”) and ettiquette.

The other characters included Rita, a singing cat (voiced by Bernadette Peters); the Goodfeathers, three very familiar sounding wise-pigeons from New Yawk; and two lab mice, Pinky and The Brain (a large-headed Orson Wells, um, tribute), who did the same thing every night, tried to take over the world, in painfully funny (and unsuccessful) ways (like becoming big country music stars).

In all likelihood, I’ll have to buy two or three copies of these DVDs, for fear of wearing them out with constant viewing. I already plan on my yet-to-be-conceived children becoming huge fans of these shows.

Hello Nurse!

A fantastic day for a ballgame

Baseball.

There is no other sport I’d give up a precious vacation day for. No other sport that begs for me to play hooky in the middle of the work week so I can catch an afternoon game with my girlfriend.

And when the day is the first warm and sunny one you’ve seen in about two months, there’s no other sport with which to take full advantage of the weather.

Yes, baseball is back, and today I enjoyed my first game of the new season at Pac Bell… I mean SBC… no, make that AT&T Park. Ying and I took the day off, and we were rewarded with gorgeous weather and a great game, with a Barry Bonds home run to add to the excitement.

Today’s game was the rubber match between the New York Mets and the San Francisco Giants. After winning the first game, the Giants dropped the second.

(It’s been a rather difficult series for me, since I’m a New Yorker at heart, with 18-plus years of rooting for the Mets, and only eight years rooting for the Giants. In the first few years living out in California, it was easy: I rooted for the Giants when they played anyone except the Mets. Things are more complicated now, and I find myself rooting for the Giants against all-comers, including the Mets, yet I still find myself disappointed when the Mets don’t win.)

Today’s game was fantastic: the Giants lead early, the Mets tied it up then went ahead most of the game, then the Giants tied it up in the bottom of the ninth on a two-run pinch-hit home run by Barry Bonds, before the Mets took the game in 11 innings.

It was a hard-fought game, and very enjoyable. The absolute highlight of the game, of course, was the homer by Barry. With the Giants down by two runs with two out in the bottom of the ninth, Bonds came in to pinch hit, against the Mets’ closer Billy Wagner. Bonds had never before hit a home run against Wagner, but that all changed with one massive swing of the bat. It was Barry’s 711th home run of his career, this time several rows into the center-field bleachers, leaving him only three bombs behind Babe Ruth for second on the all-time homers list.

This is another history-in-the-making moment for me and Barry: back in 2001, I had the pleasure of watching him take a pitch to deep right field in Dodger Stadium for his 67th home run of the season, on his way to hitting 73.

I’m looking forward to home run 714 and then 715. I hope against hope that he stays healthy and productive enough to make to 755 and beyond.

Wine tasting in Sonoma County

One of the reasons I love living in the Bay Area is how close we are to interesting activities outside “the city”. One of these activities is visiting wine country, either Napa or Sonoma. And going to wine country is a day trip at worst, even from the south bay: a couple hours drive and you’re surrounded by grape vines and group tours.

We decided to head up to Sonoma Saturday, to satisfy a craving Ying had: visiting J Vineyards & Winery to buy a bottle of their pear brandy. She’d thought it sounded good, but without having tasted it, was hesitant to buy a bottle (which starts at about $45 for 375 ml).

After hearing positive reviews from a couple of friends, she decided to take a chance and splurge, so we took the drive north. Joining us were Dave and Becky, two of Ying’s friends from college.

I’m a big fan of J’s, and not just because of the cool baseball cap, so of course I couldn’t leave empty handed. While Ying bought her pear brandy, I tried (liked and bought) their Ratafia, a golden dessert wine that’s sweet but not cloying (and comes in a nicely designed bottle). I also picked up a bottle of the pear brandy for myself, and found the one remaining bottle of their 2004 Viognier. I enjoy viogniers, so I’m looking forward to opening this bottle.

(I also really like J’s Pinot Gris, but didn’t buy any this trip. I’ll have to head back up there soon.)

Of course, even though the destination was J’s, we expected to hit a few other wineries, and hit them we did. I don’t remember all the wineries we made it to, but among them were:

  • Rodney Strong Winery, mostly because it was next to J’s. They reinforced the reputation they have with me for mediocre wines.
  • Foppiano Vineyards, where we had a decent 2003 Petite Syrah and 2004 Cabernet Sauvignon (I bought two bottles of the Cab Sauv. At $7.50 each, it will make a perfectly acceptable table wine. Their tag line, in fact, is “Pure and Simple”.)
  • Martinelli Winery, which isn’t the sparkling cider people as we’d hoped, but which had a surprisingly good 2004 Zinfandel (a grape I tend to not like), and a very good 2003 Syrah. They were pretty expensive wines, though, averaging about $45 per bottle. I picked up the “Giuseppe & Luisa” Zinfandel, which was only about $25.
  • Taft Street Winery, where most the wines seemed rather dull (but it was the last winery we hit, and our taste-buds may have been overloaded). The best of the lot was a Chardonnay, which Dave picked up.

I think we went to four or five wineries. By the end of the day, we’d tasted 20 or 25 wines and bought at least two bottles each.

It was a fun way to spend a Saturday.

Here are the wines I purchased this trip:

  • 2004 Riverside Cabernet Sauvigon (Russian River), Foppiano
  • 2004 Giuseppe & Luisa Zinfandel (Russian River), Martinelli
  • 2004 Hoot Owl Vineyard Viognier (Alexander Valley), J Winery
  • Ratafia, J Winery
  • Pear Liqueur, J Winery

Influence… Take 2

Ying does it again. Last night, once again, we’re lazing around, this time after a day of wine tasting in Sonoma County. On tv is Pretty Woman. At some point after Julia Roberts is offered “the deal”, Ying turns to me and asks:

“This may be a stupid question, but if you hire a hooker for the week, do you do it as often as possible?”

Oh my.

Her theory is if you’re paying a flat fee for something, you might as well get as much “value” from it as you can.

I wish I could poke holes in her theory, but you know, she’s right….