grep puzzler

Here’s a puzzler for all you shell-heads (you know who you are). Normal souls, please move along — nothing interesting to see here.

OK. You’re sitting in the parent of “dirname.” Inside dirname and its children are files that you know contain the string “string.” You want a text file listing the names of all those files. You run:

grep -r “string” dirname > dirname/output.txt

One of two things happens:

1) A few seconds later you have the file listing you need.
2) The command runs forever and output.txt grows indefinitely, until you run out of disk space.

As I discovered the hard way, which of these two occurs depends on which version of grep is installed on your system. In 2.5.x, you get outcome #1. Any version prior to that, you get outcome #2. On closer inspection, it’s easy to see what’s happening — grep is greedy, and is scanning the output file even as the shell is appending grep’s results to it. Reading itself and simultaneously reporting into itself. Devilish. Fortunately I spotted my error before I overflowed the drive. And sending output to any location outside of dirname avoids the problem, of course.

But here’s the puzzler: How was this fixed in grep 2.5? grep is not doing the output redirection — the shell is. grep only knows to pass results to stdout. Beyond that is a black box. So how is grep 2.5 able to avoid the problem of infinite recursion? How was it made aware of what the shell is doing? Cue Twilight Zone intro music.

Freaky deaky, super geeky.

Music: Stranglers :: Get A Grip

CSS Pencils

Stunning display of just how far CSS can be taken, given sufficient patience and a little imagination: There are no images on this page. Near as I can tell, he ran a bitmap through an image analyzer to determine the value of each pixel and translated each one into a corresponding DIV with matching CSS color value. He then created PHP transforms to let you drop channels, go grayscale, etc.

I’m not sure exactly how useful this is in practical terms, since the amount of CSS it takes to create a photographic representation exceeds the number of bytes it would take to represent the image as a JPEG, but it does seem to open a lot of doors for as-yet unimagined CSS designs. You’ve got to respect him just for showing that it’s possible. Check the fawning comments.

Described this to a non-geek friend and his only reaction was “That guy must have a lot of time on his hands.” Some people, ah swear.

Music: Linton Kwesi Johnson :: Di Black Petty Booshwah

Tivo, RSS, Gluttony

We recently purchased Tivo for the house.* Like many users, we got Tivo not because we’re TV junkies, but because we don’t have time for TV. When we do sit down to watch, we want to spend less time, and we want to watch better TV. For the most part, the formula is working – we’re no longer spending a third of our time watching (or trying to navigate around) commercials, and we’re not watching whatever crap happens to be on once the boy is down and the dishes done, just to enjoy some well-earned veg time.

But there’s an unanticipated consequence: Suddenly we have a library of shows we like at our fingertips, always ready to watch. As a result, there’s suddenly the desire to watch more TV, not less. Oooo! All in the Family re-runs! Let’s stay up! That’s not how it was supposed to work.

It struck me that this phenomenon is exactly like the backlash against RSS that some people are experiencing. At first, RSS feels like a great time saver — I can skim 10 sites in the time it used to take to skim one. But RSS readers make it so easy to harvest lots of great content that you have this tendency not to save time, i.e. to move on and go do something else after your daily news gulp, but to spend more time overwhelming yourself with information.

Who can eat just three M&Ms? The tantalizing aggregation of desirable content that Tivo and RSS readers provide only gives you the illusion of saving time; in truth, most of us are seduced by the overabundance that accompanies aggregation, and merely dig ourselves deeper into the content hole. Aggregation lends itself to gluttony.

The key to dealing with content overload is not just in finding better tools to manage the flow, it’s knowing when to get up and walk away.

* We’re feeding the Tivo via antenna, still not willing to pay $50+/month for cable** when we would only want a couple of extra channels; the inability to purchase cable channels on an a la carte basis should be a case for the feds. While there are some good arguments explaining why you can’t just buy the channels you want, it’s still an abuse of monopoly, as I see it).

** Basic cable is only $14/month, but we already get 90% of what we’d get with basic via antenna. We do have a reception issue with the antenna that we’d like to improve upon (most local stations are transmitted from San Francisco, to the west, except for NBC, which comes from San Jose, to the south; it’s tough to make one antenna receive from both directions happily without an antenna rotator, so we might end up doing basic cable for the duration of the Olympics at least).

Music: Stevie Wonder :: All Day Sucker

My Lame Powers of Prediction

In January 2003, I predicted that major browsers would have RSS readers built into them within six months, which would have put the first release of such a feature at around July 2003. Obviously, that didn’t happen. At WWDC today, Apple unveiled the major features in Tiger (OS X 10.4). Among them is an integrated RSS reader for Safari. That puts my prediction off by a year. Except that Tiger won’t be out until 2005, so make that 18 months. My crystal ball must have been hit by a stray neutrino.

A few readers have written me over the past week speculating about whether HFS+Finder in Tiger would more closely resemble BeOS’ spectacular BFS+Tracker combination, given that Dominic and Pavel have been working at Apple for the past year and a half. The answer is… sort of. Spotlight is going after metadata in a big way, and is making system-wide, instantaneous search on any type of heterogenous data seamless. The “Keywords” feature may or may not be similar to BFS’ Attributes. The key to making Spotlight as fast and flexible as BFS+Tracker will be, for me, whether attributes, er, keywords, are 100% customizable into arbitrary metadata forms, whether the metadata indexing is fast, automatic and efficient, and whether Apple finally releases a complete cousin to Be’s incredibly powerful FileTypes panel.

Also cool in Tiger: The very slick Dashboard (did Apple purchase Konfabulator?), full videoconferencing in iChat, and a powerful-looking scripting front-end called Automator. Oh, I wouldn’t mind a 30-inch aluminum-encrusted display, either.

Update: The Register confirms that Apple didn’t buy Konfabulator – they pulled a Watson on it (thanks Michael). I got a kick out of one of the propaganda posters Apple apparently has out at the WWDC: “Redmond, start your photocopiers.” Which is especially ironic given all the copying that Cupertino is apparently doing.

Music: Pat Kelly :: I Wish It Would Rain

Doctorow on DRM

Absolutely spot-on piece by Cory Doctorow on the interface between technology and copyright. Doctorow delivered this piece to Microsoft. Thesis: DRM systems don’t work, DRM systems are bad for society, DRM systems are bad for business, DRM systems are bad for artists, DRM is a bad business-move for MSFT. From the piano roll to Betamax to e-books to MP3. Sound dry? Old hat? Read it anyway. It’s juicy. A must-read not just for anyone interested in digital rights management, but for anyone living in the modern world who consumes media/information/entertainment. Check the Wiki version for updates and commentary.

Music: Gong :: Oily Way

Umask Animations

Getting so much out of this shell class. It moves fast, and the focus is on how things really work, not just how to get things done. Muster showed off some great instructive Flash animations demonstrating how umask works differently on directories and files. Try entering masks like 022 or 555 and see how the behaviors change. Never would have imagined Unix instruction lending itself to Flash animation, but wow.

Music: Blind Willie McTell :: Drive Away Blues

Panther Server, DBD Hair-Pulling

Spent the better part of last week at work wrestling with an upgrade of Jaguar Server to Panther Server. There were a lot of things we wanted out of Panther — the honed Active Directory integration and overhauled mail server chiefly among them. The upgrade seemingly went fine, and we were back online in an hour. Then I hear from one of our Movable Type users that they’re getting errors trying to post stories. Hmm… the installation can’t seem to find the DBD::mysql module. It’s still there, I can see it. Reinstall the DBD package to be sure. Installs successfully, but problem persists. Compile Bundle::DBI and DBD::mysql from CPAN — the latter fails. Start doing research — I’m not the only one with this problem — some wonky interaction between multi-CPU threading, the version of perl installed with Panther Server, and the module in question.

Over the next few days, tried every possible trick I could think of or find reference to, but no joy. Editing bugs out of perl’s Config.pm, tweaking the makefile, changing environment variables. What tanned my hide was the fact that all of this worked perfectly before the upgrade. Some small bug buried somewhere in the bowels of perl or the OS wasting days of my time.

Finally ran out of options and decided to do a clean install rather than the upgrade, which meant recreating users and shares, updating databases, etc. Everything I had hoped to avoid. But after the clean install, three tweaks to the makefile and one to Config.pm convinced DBD::mysql to compile cleanly, and MT came back online.

Nothing is as simple as it seems. Nothing.

Music: Gong :: Est-ce que je suis

AirTunes

Intrigued by Apple’s Airport Express / AirTunes announcement. Finally, an Apple-centric (but not Mac-centric!) way to get the iTunes library across the house and into the stereo. The solution is pretty unique — not at all what I (or almost anyone) expected, which was more like a wireless iPod-like home stereo component, maybe with video capabilities bolted on. AE plugs into a power outlet and into your stereo’s audio-in (analog or digital). Your Wi-Fi capable Mac then auto-discovers the device, and music flows like water. Cake. And it doubles as an AirPort Extreme base station and print server.

The good people at Slim Devices must be hating this. I personally sold our sliMP3 a while ago; had finally come to see our home stereo as the final refuge, a fortress from which I could escape the ubiquity of MP3 in my life. But AirTunes is a tantalizing prospect…

Music: Can :: Cutaway

Celebrating Ten Years of BeOS

It’s 2004, a decade since the earliest versions of BeOS started shipping to developers. Over at OSNews.com, Eugenia Loli-Queru has a nice memorial piece commemorating the anniversary.

I haven’t run BeOS for a couple of years now, though it was certainly the core of my technical life for half a decade. Recently dusted off my old laptop (an early generation dell pentium, 64MBs) and booted Win2K. It was so slow I simply could not use it. All I really needed was a shell and a text editor for the day, so I booted its BeOS partition for the first time in a long time and was amazed all over again. The exact same hardware, but the OS was easily 10x faster. Such a treat. I’m committed to OS X these days, and mostly love it, but will always consider BeOS my only OS “tru luv”. Thanks for the memory walk, Eugenia. And thanks to everyone who ever worked at Be for creating such an outstanding monument to technical possibility.

Music: Billy Bragg & Wilco :: Another Man’s Done Gone