Programming Library Conventions

Java: Readers and Writers work with Unicode Characters, while Input and Output work with raw bytes.

A side study of mine is how developers write (and organize) libraries and then [inadequately] document them.

Consistency is a good thing, and while I’ve never seen the following fact explicitly pointed out, it does represent some extra thought on the part of the Java library authors.

With the realization that applications are not just for USA English speakers, Unicode support is becoming mandatory. Standard ASCII bytes allows for 256 characters, but Unicode supports everything, including foreign characters.

Java’s strings use Unicode characters, not bytes, although we all know a Unicode character is represented by a sequence of one or more bytes. This is why the storage size of the representation is not necessarily the same as the string’s length.

With the Java libraries, anything that talks about Readers and Writers is working with content in terms of Characters.

Anything that talks about Input and Output is working with content in terms of raw bytes.

Knowing that is how the library is sliced up makes it much easier to find the routine you’re looking for.

Portupgrade on FreeBSD

Ran into a “pkgdb.db: unexpected file type or format” during a portupgrade on FreeBSD. Here’s the fix.

I’m using FreeBSD, and keeping it up to date with the ports collection is normally a fairly simple thing to do.

  1. Make sure DNS is working (check you /etc/resolve.conf file)
  2. # portsnap fetch
  3. # portsnap update
  4. # portupgrade -a

Only, today I got a strange error message doing the portupgrade:
/var/db/pkg/pkgdb.db: unexpected file type or format — Invalid argument

Whether something broke, got disconnected, terminated in the middle of processing, or the database format or version changed, I dunno.

However, the fix is easy. Get rid of the problem files, and let portupgrade rebuild them.

# rm /var/db/pkg/pkgdb.db
# rm /usr/ports/INDEX*.db
# portupgrade -a

Printing Arrays in Perl

My quick playing with printing arrays in Perl’s here documents.

Recently I had the need to do a lot of text processing, where I was taking text from a number of sources, munging it, and creating a new source. Obviously Perl was the correct way to do this.

Unfortunately, the data sources I was reading were a mish-mash of stuff, and my Perl code had to sort things back out into neat piles so the very quick and efficient data loads could be done into a database. For the curious, I was taking a pile of INSERT statements that took forever to run and doing a block load into Postgres with the COPY command.

My first attempt was to use Perl’s string concatenation operator. $string .= $more_stuff_to_append;

The problem was that an awful lot of string manipulation was going on, and the poor string pool was being beaten to death.

My next thought was to use Perl’s push operator, but discovered that this was faster:
$array[++$#array] = $stuff_to_append;

This basically gets the length of the existing array, adds one to it, and then inserts the element at that new position (at the end).

But I got an interesting surprise when I went to print it in a here-document.


print <<EOT;
blah blah blah
@array
blah blah blah
EOT

This did something I wasn’t expecting. The first element looked fine, but the following elements were all preceded with white space. And that white space was confusing the database bulk load operation.

Example:
Thing1
 Thing2
 Thing3

That’s when it struck me. The here document is like putting something in double quotes.

With Perl, doing this:
print “@array”;
…will print each element of the array separated by spaces for readability.

But, doing this without the quotes:
print @array;
…will print each element one right after the other with no separator.

Simply moving the array outside the here document resolved the problem.

Google Image Labeler – Game or Tool

Here’s one I bet you didn’t know about: Google Image Labeler… it’s like a game, and it makes finding Google Images better.

Ever wonder how Google Images seems to zero in on images so well?

I just stumbled into the Google Image Labeler, and it’s addictive.

Google shows you a random image, and you enter in as many keywords as you can think of in real time. Meanwhile, a partner you’ve been paired up with does the same thing. When you match one of your terms, you progress to the next image.

You’re given a finite amount of time to do as may as you can, scoring points as you complete match after match. A score board is kept so you can see your ranking, as well as compete for the top titles.

So, while you’re playing this game with a mystery person on the net, you’re actually seeding Google with image tags, the ones where you both match are given validation that two independent people looking at the same image came up with the same tag.

Clever. And fun!

U3 Removal

How reclaim all the drive space on a U3 thumb drive so you can format it.

On Black Friday, I purchased a small handful of 1GB micro thumb drives from Staples for $7 each. These were SanDisk U3 Smart drives labeled Cruzer micro 1.0GB, model BB0609O3B, SDCZ6-1024. They got a retractable USB plug and illuminate when connected.

The idea behind U3 technology is to do what many geeks want: keep a small collection of useful applications like Firefox, a virus checker, and so forth on a portable device without having to go through the installation process. If they simply put the special version of the applications on your disk preloaded, I wouldn’t have a problem with it.

The problem, however, is that U3 is invasive. The thumb drive comes with two partitions on it. The second partition, while small, is marked as read-only, and includes an autorun file which starts the U3 program, putting it annoyingly in the system tray on XP. Meanwhile, on OS X, a second drive image also mounts. Again, annoying.

The problem is you can’t re-format the device on either platform using the standard tools. OS X gets close, being able to see the logicals drives, partitions, and images. But, in well behaving Apple fashion, it refuses to destroy data it doesn’t own in configurations right out of the box.

While I’m looking for a solution that zaps the USB drive at the raw bit level, the only solution I’ve found is a specific U3 removal tool (which toasts all the data on the drive, so be careful) at these URLs, which reclaim all the drive space:

I know some thumb drives have the ability to password-protect themselves, making them literally read-only. I suspect that may be what’s going on, and hence the reason for the removal tool: it unlocks the device.

Aside from that, the drives themselves work quite well.

Forkin’ Eh?

You’ve heard it said, “if you’re going to live in America, learn to speak English” — but how about this, if you’re going to work in fast food, at least recognize the name of the product you’re selling to the public.

Immigration is the big topic these days, and I suspect it has to do more with the dilution of the culture than it has to do with any particular individuals. In every country, other than America, when you go there, you’re expected to learn the language. But what about smaller localizations… say a burger place?

I got to observe something amazing first hand today in Fuddrucker’s of Herndon, VA.

A customer (not me) ordered a salad, and in Fuddrucker style, it came in a small trough. Problem was, the customer wasn’t given a fork to eat it with.

Now if you’ve been to any Fuddrucker’s, you’d know that by the self-serve condiments are the eating utensils. You simply help yourself.

This customer didn’t know where the location was and politely asked, “excuse me, where are the forks?”

The person behind the counter looked at him like he was speaking a foreign language.

He tried again. “Where are the forks?”

The person was confused, and went to enlist the linguistic skills of someone working the grill.

The guy pointed at his salad, and was clearly getting frustrated, “The forks?”

The new guy shrugged and had to get the manager.

She came over and he said, “All I’m trying to do is get a fork.”

She looks down at the take out bin and asks, “You want a plastic one? Cause we have metal ones.”

To which he replies, “Metal, thank you.”

And she looks down and says, “You’ll have to get them yourself, I only have plastic here” and she walks away!

He screams out “WHERE!?!? That’s what I’m trying to find out!!!” He storms off and I never did get to see if he found his eating utensils.

The point of the story, however, is that there is a very limited set of common vocabulary used in the restaurant business. Simple works like: Coke, Napkin, Fork, Bathroom should be so common in repeated daily usage that one of even low intelligence would picks up the sound and associate a meaning. There seems to be deliberate effort to not learn even the fundamentals.

Even more localized, I can’t count anymore the number of times I’ve walked into a McDonald’s, ordered a Big Mac, and the person working the register had no clue what I was talking about. Literally. However, order an “Numero Uno” and they have no problem. I don’t understand how the mandatory training required by these places allows people to slip through to dealing directly with customers without being able to understand the primary product names when heard.

Review: The Green Tree

Thinking about trying The Green Tree in Leesburg, VA? Don’t. There’s a McDonald’s up the street with much better customer service.

On Saturday, Nov 25th, 2006 I attended dinner at The Green Tree in Leesburg, VA.

What looked like a cozy little home cooked meal from generations ago turned into an experience of personal hell.

Let’s start with the food. Any food item of remote interest had ham, bacon, wine, bottom dwelling sea creature — anyone who has even the simplest of dietary needs or preferences is helpless. I ended up ordering the chicken… which was bland. And dry.

Service was slow and inattentive. A small argument ensured between the wait-staff of who’s job it was to refill our water glasses and who’s it wasn’t. We didn’t need to see that. Or wait for it to get resolved.

Prices were about what you’d expect, but the real torment happened when multiple people had plastic only and the waitress wouldn’t split the check. Instead, it was everyone’s job to figure out — to the penny — how much their part was, because she’d already rung up tax and tip (to which she gave herself a healthy 20%). No calculator was provided.

What made matters worse was that the manager sat there watching it all. He didn’t get involved. He didn’t even offer.

While all this was going on someone nearby lit up one of the worst smelling cigarettes I’ve ever experienced second hand and it was clear there was no division between smoking and non-smoking that made any difference what-so-ever.

My wife and I threw down cash and walked out. We later learned from the rest of the party that they were kept there for well over an hour.

A little research on the Internet shows that in the past The Green Tree used to be a nice place, but now it, and its sister restaurants on the same strip owned by the same owners have terrible reviews. I was forced to agree.

If the The Green Tree is on your social plans, change them.

Walt gives The Green Tree a big thumbs down.