George V. Reilly's Technical BLog

Preload Ajax Data as JSON

http://blogs.cozi.com/photos/uncategorized/2008/05/27/preloadajaxdata.png

Preloading Ajax data as JSON has helped improve the load time and perceived performance of our family software application. Most of the pages in our web client are dynamically generated in the browser from a complex set of JavaScript and CSS, so we're always looking out for ways to make them appear more quickly.

More at the Cozi Tech Blog.

Sharing Dotfiles between Windows and *nix
Sharing Dotfiles between Windows and *nix

Tomas Restrepo wrote a post about sharing dotfiles between Windows and Ubuntu, specifically about sharing .vimrc (Linux) and _vimrc (Windows) and the .vim (Linux) and vimfiles (Windows) directories.

I have a different solution. On Windows, my C:\AutoExec.bat includes:

set HOME=C:\gvr
set VIM=C:\Vim
set VIMDIR=%VIM%\vim71
set EDITOR=%VIMDIR%\gvim.exe
set PATH=%PATH%;C:\Win32app;C:\GnuWin32\bin;C:\UnxUtils;C:\SysInternals;C:\Python25\Scripts

%HOME% (C:\gvr) contains _vimrc, vimfiles, and other stuff accumulated over many years. This directory is stored in a personal Subversion repository at DevjaVu. All my Vim files are stored with Unix LF endings, not Windows CR-LFs, so that they'll work on my Mac OS X and Linux boxen. I play some games with if has("win32") and if has('gui_macvim') to ensure that my _vimrc works cross-platform.

On my *nix boxes, the gvr folder lives under my home directory at ~/gvr, and ~/.vimrc and ~/.vim are symlinks:

$ ln -s ~/gvr/_vimrc ~/.vimrc
$ ln -s ~/gvr/vimfiles/ ~/.vim

In addition, the dotfiles that I keep in SVN are stored locally in ~/gvr/dotfiles without a leading period in their names, which makes them easy to see:

$ ln -s ~/gvr/dotfiles/bashrc ~/.bashrc

This arrangement works well for me.

Multiple Firefox Profiles: Run Firefox 2 and 3 Side-By-Side, and More

http://blogs.cozi.com/tech/images/2008/03/31/multiplebrowsers.png

I find it useful to have multiple Firefox profiles for developing and testing. A clean profile for testing allows you to replicate most users' environments, who don't install extensions. Running a development profile in a separate profile lets you restart the browser without messing with your default environment. You can also run Firefox 2 and Firefox 3 side-by-side in separate profiles.

More at the Cozi Tech Blog.

Debugging JavaScript in IE from Visual Web Developer 2008 Express Edition

http://blogs.cozi.com/tech/images/2008/03/19/vwdscreenshot_2.png

It's not at all obvious how to use Visual Web Developer 2008 Express Edition to debug JavaScript in Internet Explorer. So I wrote it up at the Cozi Tech Blog.

Daylight Savings Time and JavaScript

http://www.georgevreilly.com/blog/content/binary/js-date-dst2.png

The JavaScript engines in Firefox 2 (Windows) and IE6 can't handle the new Daylight Savings Time rules in the U.S. The Date() function returns a value that is off by an hour if the system time is between the second Sunday of March and the first Sunday of April.

More at the Cozi Tech Blog.

Update 2008/03/14: Mea culpa. This is not a widespread problem. It is caused by the presence of set TZ=PST8PDT in my C:\AutoExec.bat. Per KB932590, the existence of the TZ environment variable will cause the CRT to use the old DST rules. (I can't remember why I set TZ several years ago. It's part of the accumulated mess of files that I bring everywhere with me.)

Transparent PNGs can Deadlock IE6

http://www.georgevreilly.com/blog/content/binary/deadlock_thumb.jpg

Over at Cozi, we've started a new technical blog. I just put my first post up, describing a nasty problem we had late last year.

Here's the summary:

Internet Explorer 6 does not support transparency in PNG images. The best-known solution is to use the DirectX AlphaImageLoader CSS filter. It's less well known that using AlphaImageLoader sometimes leads to a deadlock in IE6. There are two workarounds. Either wait until after the image has been downloaded to apply the filter to the image's style, or use the little-known transparent PNG8 format instead of the filter.

More here.

Er, er

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.

Virtualization

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.

Greasemonkey for demos and mockups

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.

Cozi is Hiring

http://www.cozi.com/images/cozi_logo_transp.png

Cozi is hiring. We have positions for Developers and Web Developers.

We're a small Web 2.0 startup, based in the Smith Tower in downtown Seattle. Our Cozi Central product is groupware for families: it helps parents manage their own and their kids' schedules, shopping lists, and reminders, from computers, PDAs, and mobile phones.

If you're interested, let me know.

Update: we have some non-developer positions too.

Posted: Sep 24 2007, 01:36 PM by george_v_reilly | with no comments
Filed under:
More Posts Next page »