Execute-Notify

Multitasking in the right manner helps one be productive. Do it too much, and quality declines as you get more stressed. Do it too little, and, well, you get less done. I think the crucial element is minimizing significant context switches while allowing as many things to proceed on automatic pilot as possible.

In particular, when executing long commands on the computer (like, say, compiling a binary), it is better to switch to a different activity (preferably with lower intellectual demands, so as to keep the coding context in one’s working memory) than to sit idly twiddling your thumbs. My problem when I do this, especially since I have a different virtual desktop for each context, is that I may forget to go back and check whether my compilation succeeded and my tests passed.

I recently found out (on emacsfoo) about notify-send, a useful command-line interface to libnotify that lets alerts pop up on the desktop. As is the case for many others, I like the idea of using this tool to notify me that my long-running jobs are finished, so I can switch back to my main context. Thus, I wrote a simple command-line utility (en, for “execute-notify”) that you can use to wrap an arbitrary command and be notified when it exits. I strove to make it fairly general and customizable, and may add more features to it as needed.

The simplest invocation is simply to prefix your command with en:

en  gcc -o myprogram myprogram.cc

If the compilation failed, you would see a message like this:

A typical failure message conveyed by 'en' without any options

There are options to control the notification parameters, like so:

en --expiration 0 --title Compilation \
   --command_label "the usual gcc command" \
   --icon_success /usr/share/icons/gnome/32x32/status/info.png \
   gcc -o myprogram myprogram.cc

A customized 'en' notification when the underlying command succeeded

Here’s the help text for the command:

$ en --help
en Execute a command and notify when finished
Usage: en [FLAGS...] COMMAND [ARGS...]
   executes COMMAND ARGS... and sends a notification to the status
   panel upon completion, indicating the result of COMMAND. The
   exit code of COMMAND is the exit of en.

Each flag to en begins with "--"; flags take zero or one
arguments. The first argument to en that is not interpreted as
a flag or value is taken to be the command to execute.

Possible no-argument flags are:
  --help  Show this message
  --debug Print debugging information about en

Possible one-argument flags are:
  --title Prefix to the "Success" or "Failure" title of the
notification

  --command_label Description of the command to be used in the
notification text in place of the command itself. Useful for
succinctly describing a long command, or for use with --exit_code
flag

  --exit_code Simulated exit code from COMMAND to use when generating
the notification, Setting this flag causes COMMAND to not actually
execute, and is useful for testing that the notification is
formatted as desired without actually invoking COMMAND or of the
form

  --PROPERTY_OUTCOME where PROPERTY is one of "icon", "urgency", or
"expiration" and OUTCOME is one of "success" or "failure".
All the properties are used in creating and dispatching the
notification, but the outcome used depends on the exit code of the
command being run.
   icon: the icon to be used in the notification
   expiration: the duration of the notification (ms)
   urgency: the notification urgency, as defined by send-notify

Example:
  en --icon_success /usr/share/icons/gnome/32x32/emblems/emblem-default.png \
    --expiration 600000 --title "Directory listing" ls

Enjoy it and let me know what you think!

Intelligence and How to Get It

I recently finished reading Richard E. Nisbett’s Intelligence and How to Get It. This is a compelling book on the factors that determine intelligence, academic and social achievement, and how these are measured. Nisbett refers to many studies and applies clear reasoning to argue that nurture is much more important than nature for thinking about and improving the intelligence and functionality of the population as a whole.

He talks about the effect of socioeconomic status. For example, the heritability of intelligence is much higher in upper-class families because their environments are already highly optimized to make people as smart as possible. In contrast, in more disadvantaged settings a small improvement in the environment has a much larger effect on intelligence than any congenital variation.

The book also analyzes how different social and cultural groups have been performing on intelligence and achievement metrics, and the apparent causes for those results. He touches on African-Americans, East Asians, and Jews as distinct groups in American society (as well as on previous groups that were the world’s intelligentsia in the past) to illustrate how cultural expectations play a role. He also mentions the juicy tidbit that we are getting smarter overall, probably due to the higher prevalence of cognitive tasks (such as reading and video game playing, for example!) in everyday life.

Nisbett discusses the child-rearing practices that foster intelligence. He emphasizes talking to one’s child in terms the child can understand, relating new ideas to old ones, and asking “known answer questions” where the child knows that the questioner knows the answer; this latter appears to be a big help in school. Most fundamental of all, however, is the knowledge that intelligence is malleable; those who believe this do in fact work harder and both measure higher in intelligence and achieve higher socially than those who think intelligence is intrinsically immutable.

It was very gratifying to read a solid book that confirms my opinions: intelligence and achievement, in the end, are largely a product of the environment. In the right setting, with hard work, people can indeed excel at cognitive tasks.

Animal, Vegetable, Miracle

Kingsolver's Vegetannual

I wasn’t interested in gardening when I was growing up. It felt like an obligation when I would much rather be living in my head, playing with thoughts and ideas, reading, programming.

As an adult, though, I am more and more fascinated by it. On a personal level, it’s a good break from being inside my head all day. It is also a chance to be mindful by focusing on a simple activity, and to be attuned to the wonder that is the complex system we call life. Philosophically, it makes sense to break the pernicious cycle of store-bought food from all over the world, always available, intensively farmed: the production cycle of these foods often damages local ecosystems, increases global pollution, decreases bio-diversity, and exploits workers.

Of late, there has been renewed interest in eating well and sustainably. Barbara Kingsolver’s Animal, Vegetable, Miracle: A Year of Food Life is yet another offering to this particular audience. In this book, Kingsolver uses the chronicle of her family’s resolution to eat mostly home-raised and local foods for an entire year as a springboard for discussing food sustainability in general.

While this experiment was made easier by the family moving to a farm where they could devote significant time to agriculture, Kingsolver inspires both the back-yard gardener in me to try heirloom varieties to keep them in circulation, and the urban dweller in me to be more conscious about local and free range products in the supermarket.

The book has a companion website with recipes and local food resources. I found it enjoyable and inspiring, and recommend it to anyone thinking about eating and living more responsibly.

A library in my pocket

Amazon Kindle Barnes & Noble Nook Sony Reader Touch Edition


In high school, a bunch of us entered a competition “designing” a cool new technology. I remember our team’s entry was an electronic reader that you could use to read books and magazines everywhere. Though we didn’t win, we were pretty enthused about the idea. It was conceivable yet wild and futuristic.

Well, the future is here.

Electronic book readers have made it into the mainstream. To be clear, e-readers are not small computers or large phones (two other devices one could use to read electronically); they are small, lightweight devices with passive displays that don’t themselves draw power except during updates. Amazon’s Kindle appears to be the most popular, in my perception, with the Sony Reader and Barnes & Noble’s Nook also in the mix. These readers all use the electronic ink created by the eponymous eInk Corporation, a privately held MIT Media Lab start-up. There is also an upscale, color e-reader manufactured by Fujitsu using their own electronic ink technology.

In our household, our evaluation centered on comparing the Kindle to the Sony Reader. The Nook was just about to come out (but the separate LCD screen at the bottom seems gimmicky, taking up useful real estate and drawing unnecessary power), and the Fujitsu is inaccessibly expensive for most consumers (and apparently only being marketed in Asia at the moment).

The Kindle is used primarily for books in Amazon’s proprietary DRM-restricted format, AZW. Although it can also read other types of files (Mobipocket, plain text, and PDF), and although Amazon offers an email-based service for converting images, HTML, and Word documents to AZW, the Kindle does not support the ePub e-book standard. The Sony Reader, of course, does not support AZW, but it does support ePub, thus making a huge number of books, both DRMd and not, available from libraries and the web in general. Analogous to the Amazon’s Kindle Store, where one can easily sample and wirelessly buy books, is The eBook Store from Sony (which, apparently, does not allow sampling books as the Kindle Store does).

Neither of the two platforms is a clear winner in usability. I like the minimalist hardware on the Sony Reader Touch Edition: unobtrusive buttons allowing a smaller form factor and a sizable touch screen. The software interface, however, seems smoother and friendlier on the Kindle.

In the end, the Sony Reader appealed to us more because of its support of the ePub standard. We are constantly striving to live clutter-free, so we’ve reduced our book-buying to a trickle and relied instead on the library, thus saving storage space and money. With e-books, the physical storage space ceases to be an issue regardless of whether or not one purchases books. Buying still takes money, however, although I see nothing wrong with regarding that money as a “usage fee” that goes back to the authors (in part) in return for my enjoyment. With the Sony Reader, we can have both: books from the library when we want to save money and can wait, and books from the store when we really want a permanent copy or can’t wait at all. Moreover, by borrowing e-books we hope to build demand for libraries to stay on the cutting edge of technology and make content available to wider segments of the population (on the arguable assumption that one day the poor and the young will have e-readers just like they now have cell phones, but may not have the money to buy books constantly).

Image from the Harvard Divinity School library

But, ah, the library. The library issue brings up a host of DRM and usability issues that highlight how green the industry is, still. Here are the annoyances I’ve encountered in a typical e-library cycle:

  • The Seattle Public Library website has a section for digital books, but its search page is too simplistic. There is also no capability for easily browsing books in an intuitive interface that’s reminiscent of the real world, such as the iTunes “cover flow” interface.

  • The books are supported in two major formats (and some others): “Adobe EPUB eBook” and “Adobe PDF eBook.” The ePub format seems to work quite well, though in the one book I’ve read cover-to-cover thus far, sections that were called out in the paper version with shaded boxes, for example, were displayed in the main flow of the e-book with little (though sufficient) visual demarcation. On the other hand, the PDF format turns out to be quite bad for e-readers because the text does not re-flow when changing the zoom level: if one’s not looking a full page at a time, scrolling forward shows the remainder of the PDF page in a whole new e-reader screen. This breaks the metaphor of the reader screen being equal to a book page in favor of the poorer metaphor of the reader as a magnifying glass on a section of the book page.

  • Books can be checked out for up to 20 days. This is implemented by some some sort of expiration mechanism built into the e-book formats. This means that one can’t return a book early (since “returning” is handled by the library knowing that a copy will become inaccessible at a certain time) and one also can’t hold on to a book past the due date (which one shouldn’t but, ahem, I’ve done on occasion with physical books).

  • One can highlight passages from the book and then look at the list of highlights to be able to quickly jump to the source page. However, at least with the Sony Reader, the highlighted content is not itself copied to the list; only references to the file positions are. This has two bad consequences: one can’t download the highlights, which ought to be permissible to under fair use; and, when a library book expires, one loses access to its highlights.

  • Supposedly (I haven’t verified this), lending a purchased book to a friend follows a similar pattern to borrowing from the library: one sets a specific loan duration, during which time the book is inaccessible to the lender. This time cannot be changed once set.

  • Apparently, buying a book from the Sony Store ties the purchase to a handful of computers and readers by digitally signing the file. This is done, understandably, to prevent piracy, but gets at a much larger issue of how digital rights and restrictions should, in fact, be handled.

In addition to the library and the Sony and Amazon stores, there are many websites that make e-books available, such as Project Gutenberg, feedbooks, and Google Books. To manage e-book collections, the Sony Reader comes with adequate but not gripping software for Windows and Mac. However, there is a cross-platform package (written in Python) called Calibre for managing e-book collections on the computer and uploading them to various types of readers.

As Knox says, there is no question that at some point we will become a two e-reader household. I like having to carry only one device to read a large number of books, whether I’m on a half-hour bus commute, a 23-hour flight, or a two-week vacation. That said, our actual purchase of the Reader at this time was more obsession and excitement than anything else. If hard-copy books are adequate, it makes sense to wait a bit longer until the e-book ecosystem stabilizes, the usability kinks are worked out, and the DRM issue becomes more consumer-friendly.

Trinity College Library, Dublin. Picture by Candida Höfer