I found myself wanting to show someone a particular xkcd comic (the one about dreams). Xkcd, for anyone who hasn't been introduced, is a wonderfully geeky, smart, and thoughtful comic strip drawn by Randall Munroe.
How to search for a comic strip? Xkcd has an archive page but that seems to have a fairly small subset of all the comics. But fortunately the comics also have titles and alt tags, which google can index.
But googling for
dreams site:xkcd.org gets me lots of
hits on xkcd's forum and blag pages (which I hadn't even known
existed) rather than just finding the comic I wanted. After some
fiddling, though, I managed to find a way to exclude all the fora
and blag pages: google for
xkcd dreams site:xkcd.com -site:forums.xkcd.com -site:fora.xkcd.com -site:blag.xkcd.com
In fact, it was so nifty that I decided I might want to use it again. Fortunately, Mozilla browsers like Firefox have a great feature called bookmarklets. Bookmarklets are like shell aliases in Linux: they let you assign an alias to a bookmark, then substitute in your own terms each time you use it.
That's probably not clear, so here's how it works in this specific case:
- I did the google search I listed above, which gave me this long and seemingly scary URL: http://www.google.com/search?hl=en&q=xkcd+dreams+site%3Axkcd.com+-site%3Aforums.xkcd.com+-site%3Afora.xkcd.com+-site%3Ablag.xkcd.com&btnG=Search
- Bookmarks->Bookmark this page. Unfortunately Firefox doesn't let you change any bookmark properties at the time you make the bookmark, so:
- Bookmarks->Organize Bookmarks, find the new bookmark (down at the bottom of the list) and Edit->Properties...
- Change the Name to something useful (I called it Xkcd search) then choose a simple word for the Keyword field. This is the "alias" you'll use for the bookmark. I chose xkcd.
- In the Location field, find the term you want to be
variable. In this case, that's "dreams", because I won't always be
searching for the comic about dreams, I might want to search for anything.
Change that term to %s.
(Note to non-programmers: %s is a term often used in programming languages to mean "replace the %s with a string I'll provide later.")
So now the Location looks like: http://www.google.com/search?hl=en&q=xkcd+%s+site%3Axkcd.com+-site%3Aforums.xkcd.com+-site%3Afora.xkcd.com+-site%3Ablag.xkcd.com&btnG=Search
- Save the bookmarklet (click OK) and, optionally, drag it into a folder somewhere where it won't clutter up your bookmarks menu. You aren't ever going to be choosing this from the menu.
xkcd "regular expressions"Voila! The first hit was exactly the comic I wanted.
(You'll find many more useful bookmarklets by googling on bookmarklets.)
[ 22:13 Jun 30, 2007 More tech/web | permalink to this entry | ]