Sunday, March 29, 2009

Fixing Spidermonkey's readline()

I had occasion to try out the Spidermonkey Javascript engine today and found an annoying misfeature for which I was able to generate a fix; so I thought I'd put it out here in case other people are as annoyed by this as I was.

Because Spidermonkey is designed to run as an interactive command-line shell and not in a web browser, it includes a readline() method for getting input from the user. It's a very handy feature, but it has a bug: there's no way to tell when you've reached the end of the input stream. I'm apparently not the first person to be annoyed by this. Awesome Andy tried to fix it with a horrible hack which just made me cringe and think that there has to be a better way. There is. That's the wonderful thing about open source. If you don't like the way something works you can change it.

The Right Way to fix Spidermonkey's readline is to simply have it retain the linefeed at the end of lines. That way, empty lines have length 1. When you get to the end of file (and only then) you get a result of length zero. The fix is absolutely trivial. It's a one-line change to the file js.c:

*** js.c.~ 2007-04-20 11:45:18.000000000 -0700
--- js.c 2009-03-29 12:46:36.000000000 -0700
*** 630,635 ****
--- 630,636 ----

/* Are we done? */
if (buf[buflength - 1] == '\n') {
+ buflength++;
buf[buflength - 1] = '\0';

That's it!

Tuesday, March 24, 2009

Different band, same old song

It's nice to be done with eight years of living under the repressive weight of George Bush and Dick Cheney's disdain for the Constitution, but don't breathe a sigh of relief just yet. Democrats are apparently no more reluctant than Republicans to jettison the Constitution when it suits them. Here's Rahm Emanuel speaking at a Brady Center event:

"If you are on the no-fly list because you are known as a possible terrorist then you cannot buy a handgun in America.... If you're on that no-fly list your access to the right to bear arms is cancelled because you're not part of the American family. You don't deserve that right. There is no right for you if you're on that terrorist list."

At least under the Republicans we could console ourselves by looking forward to the day when we could vote them out of office. But now we have voted them out of office, only to find that it might be a different band, but it's the same tired old song. Your rights end as soon as someone in the government decides you're not entitled to them any more. No due process, no right to confront your accusers (or even know who they are), no appeal.

Now what are we supposed to do?

Saturday, March 21, 2009

What are the odds?

And no, these cars are not owned by the same family. "We write" is my wife's car. I have no idea who owns the van. (Besides, it's a Georgia plate. Click for the full-size original.)

Thursday, March 19, 2009

A glimpse of the future

The future seems to arrive in the Silicon Valley before the rest of the world, which is why although I make my home in Los Angeles, my heart lives in Palo Alto (and it commutes to Mountain View). So every six months for the past couple of years I make a pilgrimage up north to attend Y Combinator demo day. Lately the event has gotten so popular that they repeat it two days in a row so that all interested people can attend.

This past week I was able to attend both days, once in person, and once by robot, courtesy of Trevor Blackwell's AnyBots and their new QA telepresence robot. It's like a remote-controlled Segway but made with a controller designed by Trevor. With a sleek-looking white body, it looks like something straight out of the Jetsons but without the cheese.

Although there were quite a few rough edges (mainly having to do with connectivity problems) I came away quite impressed. In particular, I was surprised at how usable the system was even with the glitches, and how much being able to move around added to the richness of the experience. It wasn't quite like being there (couldn't help myself to the buffet) but it was much closer than I was expecting.

The most interesting thing about the experience was how much more aware I suddenly became of my sensorimotor limitations than I am when I'm on, say, a phone call, or watching a video feed, or even in a teleconference. I don't know how much of this was due to novelty and how much will remain over time, but on occasion when we lost the video feed I actually felt the same kind of visceral reaction that I would have if someone had put a blindfold over my eyes. When we needed to switch off my ability to control the robot so that it could be manually moved around, I felt like a gimp in a wheelchair. When I was able to move the robot in front of a mirror (not an easy trick -- there was a three-second round-trip communications delay that made precise positioning very tough) I felt in a weird transitive sort of way that I was looking at myself for the first time.

That's "me" on the right, along with the Anybots crew: Daniel Casner, Trevor Blackwell and Benjie Nelson (from left to right).

Some refinements are certainly needed before it's really ready for prime time, but it wouldn't surprise me a bit for these things to be in common use five or ten years from now. Who knows, maybe in 20 or 30 years when we run out of jet fuel we can "travel" through these avatars instead. Maybe by then they will have figured out how to transmit smells and flavors over the internet as well as sights and sounds so it can really be just like being there.

Sunday, March 15, 2009

A dog-shaped hole

In December of 1998 my wife Nancy and I moved from a cozy little townhouse into a new 2500 square foot house. No one outside of Stanford had never heard of Google. You could still take large bottles of shampoo onto airplanes in your carry-ons. Al Gore was still Vice President. And I was looking forward (or maybe "resigned" would be a more apt description) to a long career at JPL.

Now that we had some extra space, my wife wanted to get a dog. She didn't really want a dog, she wanted a cat. But I was allergic to cats, so a dog was the next best thing.

I didn't really want any furry creatures in the house besides me. We had had a cat when I was a kid, and once the initial charm wore off, taking care of it became a horrible chore. Emptying the litter box was the worst. I learned the hard way that I get terribly squeamish about the smelly realities of biology. But my wife promised to do all the dirty work and batted her eyelashes at me and I succumbed.

We made a list of the characteristics we wanted in our dog: He had to be a rescue animal. Neither one of us wanted to go to a breeder. He couldn't be too big or too small. We wanted a dog that we could take hiking with us, but not one that we couldn't pick up and carry if we had to. He had to have short hair. He had to be housebroken, and preferably already trained. No barkers, no diggers, no chewers.

We spent a year looking for the perfect dog. We must have visited every pound and rescue organization in Los Angeles. We researched all the breeds. We looked at akitas and malamutes, shepherds and sheepdogs. (Well, actually we didn't look at sheepdogs. Long hair, and all. But I couldn't pass up the alliteration.) We found out that there's a reason that all these animals end up in the pound. If someone has the perfect dog, they tend to keep them.

I finally threw up my hands in despair and agreed to get a cat and deal with taking antihistamines for the rest of my life. So we went to the Pasadena Humane Society and picked out a beautiful orange manx whom we ultimately named Purrcy. While Nancy was in the office filling out the paperwork I happened to notice a lady in the parking lot with a nice looking brown dog. To kill time I decided to go say hello. It turned out the dog wasn't her's, it was a stray that she'd found and was bringing in to the pound.

He was medium-sized.

He had short hair.

He looked at me with sad puppy eyes.

I said, "Hi boy, can you sit?"

He sat.

I said, "Can you shake?"

He held up his paw.

He never made it into the pound. We bought a leash at the humane society's store, put him in the back seat of the car and brought him home. Purrcy arrived a few days later, and after a few skirmishes the two negotiated a peace settlement that lasted for the next nine years. And I, who didn't want any animals at all, suddenly found myself with both a dog and a cat.

Nancy wanted to name him Hobo and I wanted to name him Mojo. We compromised and called him Mobo. In retrospect we should have named him Pogo because he bounced. He bounced when we fed him. He bounced when he walked. His floppy ears would wiggle up and down like Dopey and it would make me happy just to watch them as he trotted along. He was just a bouncy dog, and quite the hiker. We'd take him up into the Angeles National Forest and let him run off leash so he could chase chipmunks and squirrels and the occasional deer. (I don't know what he would have done if he ever managed to catch one.) I lost count of the number of times he vanished (which always freaked Nancy out) only to show up half a mile down the trail, panting furiously, with this huge doggy grin on his face saying, "What the heck took you guys so long to get here?"

But then, as all dogs do, he got old. His legs got weaker. We took him to the vet and learned that one of his hind legs was completely missing the ball part of its ball-and-socket joint. It was amazing that he could even walk, let alone run up and down mountains. But somehow he managed. We started giving him pain pills and that helped for a while. Then he had knee surgery. Then he started making these horrible hacking noises. This time it was a lung tumor, which turned out to be inoperable. That was two years ago.

Today, Mobo finally succumbed. He'd been in a pretty steady declined for a while. His legs were so weak that even standing was becoming a struggle. His breathing was getting raspy and labored. He was on four different kinds of medications. And then he had one horrible no good terrible very bad night and we decided it was time to say goodbye.

I never in a million years dreamed that I could become so attached to an animal. Taking him to the emergency clinic to be euthanized was the hardest thing I've ever done. (I've lived a pretty easy life.) I don't think I've felt so much emotional pain since I was a teenager and my first girlfriend dumped me. His passing has left a dog-shaped hole in my soul. I miss him more than I ever imagined that I could.

No more hikes.

No more sad puppy eyes.

I don't know how anyone who has been through an experience like this can't find at least a little bit of sympathy for people who turn to God for emotional solace. I am a non-believer to the core, and yet the temptation to ease the pain by saying, "You're going to a better place where you can chase squirrels to your heart's content" was overwhelming. And despite the fact that part of me knew it wasn't true, saying it (and I confess I did say it) actually helped. Imagine how much more effective it might have been if I actually believed it. And imagine how much more necessary it might have been if it had been a dying child I was dealing with instead of a dog. Even now I can't even begin to imagine what that must be like.

Mobo, I will miss you. You made a dog person out of me, which I didn't think was possible. Wherever you are now, I hope there are squirrels to chase.

Never turn down a sales lead

I would not have even bothered to write about this -- it's so obvious it sounds patronizing -- had I not met with a startup company the other day (not a YC company) who actually did this. Sometimes even the obvious needs to be stated, so here's a bit of free advice for startup companies. (Actually, this is good advice for any company, but startups in particular.)

Never turn down a sales lead.

When someone offers to put you in touch with a potential customer, always accept, and do it graciously. You don't have to actually follow up on the lead (although you'd be foolish not to -- even if you're absolutely sure that the lead is worthless you never know when you're going to be pleasantly surprised). But under no circumstances should you tell the person offering you the lead that you have no intention of following up even if it's true. Most of the time honesty is the best policy, but not in this case. You are much better off saying, "Thanks for the lead, I'll follow up on it ASAP" and then not doing it than you are explaining all the reasons why you think the lead is useless. In the former case you can always plead schedule overloading or amnesia or something like that (assuming you are ever in a position where you have to explain why you didn't follow up, which is extremely unlikely). But if you start trying to explain why you think the lead is useless there are only two possibilities: either you're wrong, in which you will sound like an idiot, or you are right, in which case you will make the person who offered you the lead feel like an idiot. Either way it's not going to help.

So rehearse this line and add it to your repertoire of little white lies: thanks for the lead. I really appreciate it. I'll follow up on it as soon as I can.

UPDATE: There is one exception to this rule, and that is if the lead is one you have already followed up on, in which you can (and should) say, "We already tried them and it didn't work out because of X and Y and Z."

Friday, March 13, 2009

So much for openness

The Obama administration has taken the position that the details of a treaty on intellectual property need to be kept secret in the interests of national security.

Let's hope that this is the action of some lower-level bureaucrat left over from the Bush administration who didn't get the memo from the President explicitly directing a halt to this sort of bullshit. That's not a particularly good outcome given how much trouble Obama is having keeping things under control. But it's a hell of a lot better than the alternative.

It would be funny if it weren't so sad

What does it say about our society when the best investigative journalism comes from Comedy Central?

The link goes to John Stewart's final showdown with Jim Cramer. It's in three parts. Well worth the time to watch all three.

In praise of SpamSieve

I get a ton of spam, and it was starting to overwhelm the filter built in to the OS X mail client. I've recently started running my own mail server, so I started tweaking the settings to try to cut down on the processed breakfast meat, and discovered that Microsoft Outlook has a serious bug (what a surprise). One of the ways an SMTP server can cut down on spam is to require clients to connect with a fully qualified domain name (FQDN). This will prevent many botnet machines from connecting because they tend to not be configured to send a FQDN. Unfortunately, it works a little too well. As far as I have been able to determine, it is not possible to configure Microsoft Outlook on Windows to send an FQDN. I have clients using this server who use outlook, so I had to disable the FQDN requirement.

I could have installed a content-based spam filter on the server, but the problem is that spam is personal. One man's spam is another man's hot deal of the week from his favorite on-line vendor, and the training process can get really annoying if it's not integrated into the client. I was about to throw up my hands in despair and set up a second mail server for Microsoft users, when I decided instead to try SpamSieve. I was a little skeptical that it would work much better than Apple's built-in filter, but there's a 30-day free trial so I didn't have much to lose.

I've become a believer. I've only been using (which is to say training) it for three days, but the situation is already dramatically better than it was before. I've had one false positive during the training process, and the false negatives have rapidly dwindled to 1-2 a day. My spam problem is (I almost dare not say this for fear of tempting fate) effectively solved.

So I recommend SpamSieve. It's well worth the $30 it costs.

I do have one complaint: the instructions for the initial training process are a little unclear, and in one place downright misleading. The instructions say to delete the messages in your current spam folder before setting up SpamSieve. DON'T DO THIS! The training process requires about 600 representative spam messages. The instructions suggest fishing these out of your trash, but the problem is that if your spam is in the trash it's almost certainly mixed in with a lot of good messages and now you have to manually tease them apart. So if you're going to be using SpamSieve, keep a collection of spam in a separate folder for training before you begin. You'll be glad you did.

Monday, March 09, 2009

Can OS X really suck this badly?

I was playing around with Git because that seems to be what the cool kids are doing nowadays, and stumbled onto what seems to be a rather nasty bug in OS X. Apparently, creating a lot of files with names in a random lexical order is reeeeeaaallllyyyy slllooooowwwww. Here's a demo (in Python):

import hashlib, datetime, os
l1 = [hashlib.md5(str(i)).hexdigest() for i in range(3000)]
l2 = [x for x in l1]


def test(l):
t0 =
for x in l: open('test/%s' % x, 'w').write('test')
os.system('rm test/*')


On Linux, both tests run in about the same amount of time (about a second on my machine). But on OS X, test(l1) is seven times slower than test(l2). This is enough to cause real pain when trying to deal with a large repository because Git uses the filesystem as sort of a poor man's database.

If anyone happens to know a fix for this, or how to get Apple's attention, I would be most grateful. I've reported this to Apple Feedback and also their discussion forums but I'm not holding my breath.