Thursday, May 13, 2010

Mac-style wheel zoom, Exposé/Switcher on Windows 7

Having a Mac at work has been a mixed blessing, mostly good. There are some great OS features that I've become addicted to. Happily, I have discovered ways to duplicate them on my Windows 7 home machine, and with better customizability even.

Wheel zoom

On Mac OS, holding command and using the mouse wheel zooms you in and out of your screen view. This is on the operating system level, so it works in any application. Windows 7 has a similar (i.e. copied) feature where holding the windows key and pushing plus/minus zooms. Obviously it's nicer to use the mouse wheel. Luckily, with AutoHotKey it's easy to set this up on Windows and even make it better.

After installing AutoHotKey, run the following script:

; Only one instance running at a time
#SingleInstance force


; Mac-like zooming
~LCtrl & WheelUp::
  sendinput #{NumpadAdd}
return

~LCtrl & WheelDown::
  sendinput #-
return

~LWin & WheelUp::
  sendinput #{NumpadAdd}
return

~LWin & WheelDown::
  sendinput #-
return 

I derived this from AeroZoom by wandersick, which is an excellent set of shortcuts for presentations. I pulled out just the very simple zooming functionality and made it duplicate the Mac functionality more. Thanks to wandersick for putting his tool out with the source!

My mouse has side buttons that I usually use just for forward/back. I added the following so that now I can do the wheel zoom without the keyboard at all, just by holding the left side button and wheeling:

; Additional mouse-only zooming
~XButton1 & WheelUp::
  sendinput #{NumpadAdd}
return

~XButton1 & WheelDown::
  sendinput #-
return 

Exposé/Switcher

Exposé is the Mac OS feature that makes it easy to find windows when you have a thousand different things open at once. There is a very similar application for Windows called Switcher. I like having Mac OS setup so that when you push the middle button (the wheel) it calls up Exposé. With AutoHotKey, of course, it was simple to set up identical functionality on Windows 7 via Switcher.

On my home mouse, I find it easier to push both side buttons simultaneously than to push the wheel down, so I set it up that way. I also had trouble getting this to work with Switcher's default activation button (windows-`), so I added an additional Switcher hotkey (Switcher is very nicely customizable too) and then just setup AutoHotKey to trigger that:

; Mac-like expose, hooking into switcher
~XButton1 & XButton2::
  send #s
return

Hope that helps some other people suffering from Mac lust. Enjoy!

Cloud patterns from space

WiReD has a cool gallery of satellite cloud photos.

Wednesday, January 20, 2010

Mourning dove feeding

Finally got around to posting a video of the mourning doves that lived in our tomato plant last summer. I was working from home at the time, and this was the window right next to my desk, so I have a lot of videos and photos, but this is one of the more interesting ones: feeding time!

Thursday, December 3, 2009

Dapple

On vacation in Paris last month we visited the Musee D'Orsay to see some of the classics of Impressionism. One of my current favorites (and one of the most expensive paintings ever sold) is Renoir's Bal du Moulin de la Galette:

What I particularly like about this painting is Renoir's careful depiction of sunlight dappling through trees. Look at the man in the foreground, facing away from us, with the curious round dabs of sunlight across his back. If you focus on this point and think about it, the appearance of the dapples seems a little strange, yet holistically it feels right.

In fact, what Renoir has captured here is a true optical curiosity. As discussed by Marcel Minnaert in Light and Color in the Outdoors, sunlight dappling through trees often produces these beautiful, perfectly round or elliptical spots of light:


As Minnaert points out: "the surprising thing is that all these images have the same shape, although it is obviously impossible that all the holes and slits in the foliage happen to have the same shape."

This happens because holes in foliage that are sufficiently small result in dapples whose shape is dominated by the image of the sun, i.e. a disc, rather than the shape of the hole. If the sun were a mere point source rather than having a significant diameter, we would not see this effect. (I believe that the shape of the spot of light produced is essentially just the image of the sun, scaled by the projection throw length and then convolved with the shape of the hole, neglecting diffraction effects...)

This effect is most dramatic when something distorts or obscures the image of the sun. A classic example is the change in the appearance of tree dapples during a solar eclipse: as the sun becomes obscured, its image becomes crescent shaped, as do its dapples through the trees:



Update: new eclipse photo, this time at annular stage:

Monday, September 14, 2009

Wednesday, August 19, 2009

In the Styx

In The Amazing Adventures of Kavalier and Clay, Michael Chabon uses the idiom "out in the sticks", meaning "in the boondocks", "in the middle of nowhere". According to EtymOnline, this idiom arose around 1905, simply from the meaning of sticks as in trees as in a rural place.

I've heard the phrase plenty of times, but this must be the first time I've seen it (or at least first time I've noted it) in print. Without really thinking about it, my mental image of this phrase had always been "out in the Styx". Which of course, now that I actually think about it, seems pretty unlikely. Definitely more fun my way though...

Thursday, August 13, 2009

Marketing Coup

Overdone sales mailer from The Economist: "Handle with care. Contents may inspire."

Roget's Thesaurus:

Inspire: to breathe in
Synonyms: inhale, gasp, suck

Thursday, August 6, 2009

Work around Selenium IDE's iteration deficiency with Prototype JavaScript evals

Selenium IDE, the FireFox testing plugin, is a nice tool. One of its limitations is the lack of straightforward methods for iterating or doing other control flow during tests. This is one reason to switch to writing tests in Selenium RC. However, it is sometimes possible to work around the limitations from within Selenium IDE by evaluating arbitrary JavaScript. In particular, Rails applications using the standard Prototype JavaScript library have available some nice ways to iterate over elements.

For example, I recently wanted to write a Selenium IDE test to clear the shopping cart for a web app. To do this, I needed to iterate over all the elements in the cart, set their quantity to 0, and then update the cart. To accomplish the iterative set quantity to 0, we can use the getEval method to run arbitrary JavaScript: selenium.browserbot.getUserWindow().document.body.select('input[id^="line_item_"][id$="_quantity"]').each(function(elem){elem.value = 0}).

Going through this piece by piece:

  // This gets us the user window.  
  // Older versions might use getCurrentWindow() instead.
  selenium.browserbot.getUserWindow()
  
  // Gets us down to the document body
  // Because this is a standard Rails app, 
  // body has already been extended with Prototype.
  // select() invokes Prototype's $$() CSS selector.
  document.body.select
  
  // These are CSS3 attribute selectors
  // Basically we want to match id="line_item_*_quantity".
  // May require FireFox >= 3
  input[id^="line_item_"][id$="_quantity"]
  
  // Prototype's Enumerable.each() does the iteration,
  // with an anonymous function setting the values.
  each(function(elem){elem.value = 0})

Wednesday, August 5, 2009

Getting Selenium to wait for Ajax requests

Update: See here for one caveat in using Ajax.activeRequestCount.

Using Selenium IDE to test Ajax, you can usually use a waitFor condition reflecting on DOM elements to tell you when Ajax calls have returned. However, if you just want to wait until all Ajax requests have returned without relying on testing against page elements, there is this approach:

Command: waitForCondition
Target:  selenium.browserbot.getUserWindow().Ajax.activeRequestCount == 0
Value:   10000
This works for Prototype based Ajax pages, e.g. standard Rails. If you're using a different JavaScript library, you'll need to use a different call; see here for some possibilities.

(For earlier versions of Selenium, you might need to use getCurrentWindow() instead.)

Getting revision number in Tortoise Svn

http://stackoverflow.com/questions/89741/can-i-see-the-currently-checked-out-revision-number-in-tortoise-svn