Thursday, October 25, 2007 

http://www.georgevreilly.com/blog/content/binary/ErEr.png

I've grown fond of the JavaScript || idiom:

 function FrobImage(img) {
var width = img.width || 400;
var height = img.height || 300;
// ...
}

FrobImage({height: 100, name: "example.png"});

If img.width exists and it's truthy, then width = img.width; otherwise, width = 400. Here, it will be 400 since the img hash has no width property. More than two alternatives may be used: x = a || b || c || ... || q;

A few weeks ago, while cleaning up the error handling in some batch files, I came across a similar idiom:

 foo.exe bar 123 "some stuff"  || goto :Error

Only if foo.exe fails (exit() returns a non-zero value), is the second clause executed.

Perl's die is typically used in a very similar idom:

 chdir '/usr/spool/news' || die "Can't cd to spool: $!\n"

though the or keyword seems to be preferred nowadays to ||.

This morning, I came across the ?? operator in C# 2.0, aka the null coalescing operator:

 Customer cust = getCustomer(id) ?? new Customer();

If getCustomer(id) is not null, then that's the value that cust gets; otherwise it's set to new Customer().

All of these idioms are syntactic sugar and all of them are in my toolbox.

posted on Thursday, October 25, 2007 7:12:34 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [0]
Tuesday, October 23, 2007 

content/binary/virtualization.jpg

Picture this.

An external USB hard drive plugged in to a machine running Win64. The OS has virtualized the underlying transport so that it's essentially indistinguishable from an internal IDE, SCSi, or SATA drive. Call the machine, Boss, and the USB drive, L:.

Boss is running Virtual PC, which is hosting a 32-bit virtual machine on top of Boss's 64-bit OS. Let's call the 32-bit VM, Sidekick.

Sidekick is not only a VM, but a virtual network host. Boss is bridging connections to Sidekick, and Sidekick and Boss both appear on the LAN as separate network hosts.

The USB drive has several ISO images, which Sidekick wants to use. Sidekick connects to \\Master\L$ over the virtual network, and uses a tool like VcdTool to mount the remote ISO on a virtual CD drive.

Amazingly enough, it all just worked for me last night.

I'm trying to set up an environment where I can build Vim with various 32-bit and 64-bit Microsoft compilers and, more importantly, run the Win64 binary. I have a set of VM images with distinct flavors of MSVC, which was necessary to update INSTALLpc.txt and to keep Make_mvc.mak building.

In previous iterations, I got Remote Desktop access to a colleague's Win64 machine, but that was at Atlas, so it's no longer an option. I bought a new AMD64 desktop system a few months ago and over the weekend set it up to dual boot.

posted on Wednesday, October 24, 2007 3:57:53 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [0]
Monday, October 15, 2007 

http://images.amazon.com/images/P/0060764899.01.MZZZZZZZ.jpg

Title: The Lion, The Witch and the Wardrobe
Author: C.S. Lewis
Rating: 4 stars out of 5
Publisher: Harper Collins
Copyright: 1950
ISBN: 0060764899
Pages: 256
Keywords: fantasy, children
Reading period: 13-14 October, 2007

We saw the movie last week and I remarked that I had never read any of the Chronicles of Narnia books, so Emma dug out her copies.

The book is old-fashioned and innocent. It reminds of some of the British books that I read in my childhood, such as the Famous Five.

By way of an enchanted wardrobe, four plucky human children fall into a parallel world, where they are acclaimed as saviors, fulfilling a prophecy. They quickly fall afoul of the evil tyrant, the White Witch, but make their way to Aslan, the noble lion, who eventually saves the day after a noble sacrifice.

Indeed a classic children's tale.

posted on Tuesday, October 16, 2007 5:42:31 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [0]

http://images.amazon.com/images/P/0151003580.01.MZZZZZZZ.jpg

Title: At End of Day
Author: George V. Higgins
Rating: 4 stars out of 5
Publisher: Harcourt
Copyright: 2000
ISBN: 0151003580
Pages: 383
Keywords: crime fiction
Reading period: 30 September-7 October, 2007

At End of Day is Higgins' last novel, published after his death. McKeach and Cistaro are crime bosses who have avoided arrest for more than 30 years. Partly because they're very smart, very competent, and quite paranoid. Partly because they have a secret deal with the local FBI office: they provide information in return for protection. All good things come to an end, of course.

Higgins' style is odd, conducted largely in monologue. His characters jaw and jaw. Boy, do they love the sounds of their own voices. It works, but it's tiring to read.

Higgins tells a complex tale: a slice of life of the FBI, the Massechusetts state police, and the crooks, both in the present and in flashback. No one is particularly likeable, but it's hard to look away.

Recommended.

posted on Tuesday, October 16, 2007 5:40:55 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [0]
Thursday, October 11, 2007 

http://www.wired.com/wired/archive/13.09/images/ST_34_monkey1_f.jpg

I've been meaning to play around with Greasemonkey for a couple of years. Greasemonkey is a Firefox extension that allows users to install scripts that make on-the-fly changes to the look and feel of third-party websites. For example, adding price comparisons to Amazon or thumbnail images to Google search results. UserScripts.org has a large repository of Greasemonkey scripts.

I finally built my first script the other day. We're putting together a new feature at Cozi that integrates partner websites with our site. Since the feature is not yet announced, I'll just say that partners will add a link to Cozi on many of their database-driven pages. That link has a complex, page-dependent querystring. Until the partners do the work to add the link to their sites, we were limited to testing and demoing with hand-modified pages.

I wrote a little Greasemonkey script that finds the right spot on the partner pages to place the link, scrapes some context to construct the querystring, and inserts the link. Now we can test against the real sites and show a compelling demo. Of course, it only works on Firefox and it requires you to install both Greasemonkey and this script. Our partners will have to make minor changes to their sites before ordinary users can take advantage of the feature.

Some gotchas with Greasemonkey. Inserting, say, <b>Click here</b> is as simple as document.getElementById('spot').innerHTML = <b>Click here</b>. However, inserting a <script> node requires:

 var scr = document.createElement('script');
scr.type = 'text/javascript';
scr.text = 'createLink(' + p1 + ', ' + p2 + ', ' + p3 + ');';
document.getElementById('spot').appendChild(scr);

Greasemonkey will definitely become part of my repertoire.

posted on Thursday, October 11, 2007 7:05:48 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [0]
Thursday, October 04, 2007 

http://images.amazon.com/images/P/1590597273.01.MZZZZZZZ.jpg

Title: Pro JavaScript Techniques
Author: John Resig
Rating: 3.5 stars out of 5
Publisher: Apress
Copyright: 2006
ISBN: 1590597273
Pages: 347
Keywords: programming, javascript
Reading period: 16 September-4 October, 2007

At Cozi.com, we use the jQuery JavaScript library to do all kinds of complex and wonderful DHTML and Ajax tricks in our web client. Extremely powerful, very elegant: I commend it to your attention.

John Resig is the lead developer on the jQuery team. This book is not about jQuery, though if you work your way through it, you'll be well equipped to understand the jQuery source code.

This book covers modern JavaScript techniques, in particular, object-oriented JavaScript, unobtrusive DOM manipulation, Ajax, and cross-browser warts. It covers a lot of ground and shows the underpinnings of many of the popular JavaScript libraries that power Web 2.0 sites, showing uses of jQuery, Scriptaculous, Dojo, Prototype, and more. His examples are clean and well-chosen.

It's a good book and I learned a great deal from it. It's not as good a book as it could have been. The editing is sloppy and there are too many typos. Resig fails to follow Strunk's dictum, omit needless words: the writing is clumsy and wordy. Inline <code> should be typeset in a distinct font in a programming book. Finally, no one should talk about consuming JSON without mentioning browser security.

posted on Friday, October 05, 2007 6:17:59 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [0]

http://lh5.google.com/ethnamamamia/RVspddQYABI/AAAAAAAAAKE/yW5-1h7kmaM/DSCF1292.JPG?imgmax=576

My little brother, Mark Reilly aka the Alien Resident, successfully defended his doctoral dissertation on Tuesday and may now be addressed as "Dr. Reilly."

He studied part-time at the European Graduate School in New York City, while juggling several jobs. His doctorate is in Media and Communications and the topic was Propaganda of the Dead: Terrorism and Revolution, which he picked before 9/11.

He is only the second PhD in the family. My uncle Pat Deasy was the first.

Congratulations, Mark!

posted on Friday, October 05, 2007 5:50:18 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [1]

http://icanhascheezburger.files.wordpress.com/2007/09/im-in-ur-kitchen-doin-parkour.jpg

http://icanhascheezburger.files.wordpress.com/2007/09/128340436056562500unosaywecul.jpg

About a year ago, I posted a link to some silly cat pictures. I just found the motherlode.

http://icanhascheezburger.files.wordpress.com/2007/09/128340438109062500whyihaztohol.jpg

posted on Friday, October 05, 2007 5:46:25 AM (Pacific Daylight Time, UTC-07:00) 
#    Comments [0]