Sunday, June 4, 2006

Battle of Midway

Sixty-four years ago today, the naval battle now known as “The Battle of Midway Island” commenced. It lasted for four long days:

From the U.S. Navy’s official Midway history site:

The Battle of Midway, fought over and near the tiny U.S. mid-Pacific base at Midway atoll, represents the strategic high water mark of Japan’s Pacific Ocean war. Prior to this action, Japan possessed general naval superiority over the United States and could usually choose where and when to attack. After Midway, the two opposing fleets were essentially equals, and the United States soon took the offensive.

Japanese Combined Fleet commander Admiral Isoroku Yamamoto moved on Midway in an effort to draw out and destroy the U.S. Pacific Fleet’s aircraft carrier striking forces, which had embarassed the Japanese Navy in the mid-April Doolittle Raid on Japan’s home islands and at the Battle of Coral Sea in early May. He planned to quickly knock down Midway’s defenses, follow up with an invasion of the atoll’s two small islands and establish a Japanese air base there. He expected the U.S. carriers to come out and fight, but to arrive too late to save Midway and in insufficient strength to avoid defeat by his own well-tested carrier air power.

Yamamoto’s intended surprise was thwarted by superior American communications intelligence, which deduced his scheme well before battle was joined. This allowed Admiral Chester W. Nimitz, the U.S. Pacific Fleet commander, to establish an ambush by having his carriers ready and waiting for the Japanese. On 4 June 1942, in the second of the Pacific War’s great carrier battles, the trap was sprung. The perserverance, sacrifice and skill of U.S. Navy aviators, plus a great deal of good luck on the American side, cost Japan four irreplaceable fleet carriers, while only one of the three U.S. carriers present was lost. The base at Midway, though damaged by Japanese air attack, remained operational and later became a vital component in the American trans-Pacific offensive.

The full story of Midway Island could be a Tom Clancy novel for all its drama, technology, larger-than-life characters, luck, turning point nature, and heroic actors. It’s very sad for this history buff to know how few young Americans know this story…

From an historical perspective, of course the most important thing about the Battle of Midway Island is that it is the beginning of the Allied victory in the Pacific war against the Japanese Empire. Since the preceding December 7, when the Japanese struck Pearl Harbor, the Americans and their allies had been subject to six months of almost unrelentingly bad news in the Pacific. There were many knowledgeable and informed people at the time who were uncertain the Allies would be victorious — the Japanese Army and Navy had a definite air of invincibility about them. Those were dark days indeed for Americans. About the only positive news before Midway was Jimmy Doolittle’s amazing raid on Tokyo, just two months earlier. That raid, while terrific for morale, had little military significance. Midway, on the other hand, was an unqualified and very significant military victory:

Battle of Midway: 4-7 June 1942: Combat Intelligence Released as of 14 July 1942

21. The following is a recapitulation of the damage inflicted upon the enemy during the battle of Midway:

(a) Four Japanese aircraft carriers, the Kaga, Akagi, Soryu, and Hiryu were sunk.

(b) Three battleships were damaged by bomb and torpedo hits, one severely.

(c) Two heavy cruisers, the Mogami and the Mikuma were sunk. Three others were damaged, one or two severely.

(d) One light cruiser was damaged.

(e) Three destroyers were sunk and several others were damaged by bombs,

(f) At least three transports or auxiliary ships were damaged, and one or more sunk.

(g) An estimated 275 Japanese aircraft were destroyed or lost at sea through a lack of flight decks on which to land.

(h) Approximately 4,800 Japanese were killed or drowned

22. Our total personnel losses were 92 officers and 215 enlisted men.

Of course I was not there at the time — I wasn’t born until 10 years after Midway — but I have read extensively about the period. One thing comes through loud and clear: both in the military sphere and in the civilian world, the victory at Midway had an electric effect. It was a proof point that America and her allies could prevail; that the Japanese were anything but invincible.

Midway was also a triumph for our intelligence services, in particular the cryptanalytic team who cracked the Japanese codes. For anyone with a technical bent, the story of how that team cracked the codes is fascinating (and entirely declassified — so the complete, authoritative history is available). Likewise, the story of how they deliberately used disinformation to figure out that a particular code phrase referred to Midway Island is just as thrilling.

But most of all, when I think of the Battle of Midway Island, I think of the “Greatest Generation” — the courageous generation of my parents — who lived through such dark days (Hitler, Stalin, Hirohito, and Mao all at the same time!), rallied and persevered through months and months of unmitigated bad news, until finally one day they were victorious. Can you even begin to imagine the joy and relief every American must have felt on that happy day?

The Battle of Midway was the first uplifting step on the path to that day of victory. And today is the sixty-fourth anniversary of the first step…

Able Ajax

Geek alert!

If you’re not a Javascript/Web developer, skip quickly to the next post — that will minimize the pain. If you are a Javascript/Web developer, you might be interested in this.

I’m working on an application now that has several different needs (and almost certainly more to come) that all fit the same pattern: quite large tables (100s of thousands of entries) that need to be viewed, scanned, filtered, and sorted. The entries in these tables represent real-world electronic trading events; it’s vital for the information to be up-to-date and accurate.

My first stab at a solution for this took advantage of the fact that modern web browsers are fully capable of displaying truly gigantic HTML tables in an IFRAME element, making a nicely scrollable (horizontally and vertically) UI element. However, there were quite a few shortcomings with this approach. First, the HTML was generated at the server and delivered to the client in a GET; this means that every change in the view required a complete download of that portion of the table that was being viewed — definitely not a zippy operation, and quite a server load as well. Second, a little thing but very annoying: the table headers scrolled right off the screen unless you were at the very top of the table. Third, and probably worst of all: when the table had more than about 8,000 rows, it was completely unreasonably slow — and the client’s CPU utilization went to 100% (always a bad thing!).

Some investigation on the third problem led me to an interesting discovery: the browser (Firefox 1.5 in my case) uses a fairly inefficient algorithm to insert a row into a table. It doesn’t matter whether the row is being parsed from an HTML document or is being inserted by client-side Javascript code operating directly on the DOM — it’s still slow. From the behavior, I think it’s an n^2 algorithm; I speculate that they are copying the entire table on every insert operation.

After a little thought I realized that the real root of my problem was that I was trying to render thousands of table rows just to see 30 or 35 of them. There had to be a better way!

The approach I chose relies heavily on Ajax techniques. First, I wrote some stuff to fetch the underlying data and store it in Javascript arrays. I used JSON as the encoding on the messaging layer, as this is very lightweight on the client side (as it’s natively supported by Javascript). This code queries the server on a configurable interval to get the data; the end result is that the array in client memory is up-to-date within that interval. This stuff was easy to write (prototype.js is my friend), it is very fast, and it imposes almost no measurable load (other than a few 10s of megabytes of RAM consumed).

Then came the really tricky Javascript part — tricky for me, anyway, as I am no Javascript guru. I created an object (I call it ViewManager, and it has some associated objects for filtering, sorting, and so on), whose purpose in life is to maintain a small (e.g., one screenful) table that is a view onto the much larger underlying array of data. Using HTML and CSS, I created a vertical scroll bar that is entirely operated by my Javascript, rather than by the browser. The HTML table seen by the browser has only 30 or 40 rows in it (the size can be changed by the user by dragging a corner) — this renders blindingly fast, with practically no CPU consumption. When the user scrolls around in the table, what’s happening under the covers is that the ViewManager object gets told to move around on the large array of data, and it simply re-renders the entire HTML table as needed to simulate this.

Because my code is managing the table’s presentation, it’s a snap for me to keep the headers on top — that works fabulously well. I handle filtering and sorting by keeping a secondary array whose elements represent the items actually being viewed, in the order that they should be viewed. Each element of this array contains an integer index to an element in the main data array. This arrangement allows me to sort and filter without actually modifying the data table — and this means I can very conveniently always return to a normal unsorted, unfiltered view. With a data array containing 500,000 items, a sort and/or filter operation takes well under one second — awesomely zippy compared to the initial method. And best of all, the server is completely uninvolved in this!

I was pleasantly surprised at how easy all this code was to implement. It’s very reminiscent of low-level GUI implementations, especially in the event-driven nature of it. The trickiest bits turned out to be accurately figuring out where an object happened to be rendered on the screen — in a browser like Firefox, the user can do things like change the font size, or resize the window, and that will re-render the screen, sometimes in unexpected ways. I’ve not found good documentation on stuff like this, so I ended up doing quite a bit of reverse-engineering and experimentation — but that’s ok, I learn a lot every time I do something like that…

The bottom line on this experience: a modern web browser, using Ajax techniques, can do just about anything that an old-fashioned WIN32 GUI can do, with just as much interactivity and zippiness. The only exception I am currently aware of is for graphical elements that you’d really like to create on the client — Javascript provides no tools for manipulating or creating images. But the vast majority of the business applications I’ve worked on had no such requirements. Without such a requirement, for me choosing a web client over a thick-client GUI application is a no brainer. With such a requirement, I’d be looking very hard at other approaches, either server-side or with client side Java applets. I’d also be looking for someone’s add-on to Javascript for image manipulation…

Saturday, June 3, 2006

Thumbs

Miki (our rambuctious little field spaniel puppy) and I were just playing in our living room. He decided that my right thumb was a chew toy, and those little puppy teeth are sharp! Before I could extract my thumb from his mouth (actually it was partway down his throat!), those little razors he calls teeth had raked a couple of nasty gashes down the length of my thumb.

I washed them out and discovered that if I carefully held my thumb perfectly straight, the blood didn’t gush out quite so badly. In fact, with just a bit of pressure for a couple of minutes, the bleeding stopped altogether. This meant that I could safely leave the kitchen sink and head for the bathroom, where I knew we kept a package of bandages. Debbie was out grocery shopping, so I was on my own.

Here’s where the challenge was: I had to get three bandages (to cover the length of the two cuts) out of the box, out of their paper wrapper, and remove the little papers that cover the sticky part — all without bending my thumb and starting the gusher all over again. Does that sound easy to you? Or at least feasible? Trust me: it is not easy…and in fact I could not do it at all. I eventually gave up trying, and just bent my thumb to get the job done and let the blood run into the bathroom sink. Once I had three bandages lying sticky-side-up on the counter, I straightened my thumb, reapplied pressure, and stopped the gusher again. Then I was able to put the bandages on with just my left hand; that wasn’t too hard.

It’s amazing how dependent we are on such a simple little thing like a thumb bending…

I remember another similar revelation about thirty years ago. This was a much more impactful situation: I had broken my right wrist rather badly, and I had a cast (the old-fashioned plaster kind) from my shoulder to my hand, with only about half my fingers protruding. The cast was strapped such that my forearm was held against my chest. I’m right-handed, so the only hand I could use for the eight weeks I was in a cast was my left hand. Everything was more difficult, even simple little things you’d never imagine, like opening a door (or a hatch on the ship I was stationed on; I was in the U.S. Navy at the time). Driving my stick-shift car was only possible when I rigged up a shift lever extension (a buddy welded it up for me) that let me use my left hand to shift — and I had to let go of the steering wheel to do that. Taking a shower was really challenging. For me the worst of all was trying to do my job (as an electronic technician): trying to use tools like soldering irons or pliers with my left hand was unbearably awkward and totally frustrating.

Not being able to bend my right thumb is much less of a problem, not least because within a day or so it will have healed enough to use again. But it sure is a reminder of all the human characteristics that we just take for granted, day in and day out…

Imminent Employment

I don’t think I’ve blogged about this before, but I’ve actually been unemployed for the past eight months — I was laid off from my role as CTO of FutureTrade this past October. Unemployed, in my case, does not mean without income: I’ve been consulting for several companies, and I’ve had a generous severance package from FutureTrade. So this period has not been one of hardship for us, thank goodness — and in many ways it has been quite enjoyable. For one thing, all of the consulting work has been done from my home office…and I just love the work environment here. But most importantly, all of the consulting work has been honest-to-goodness hands-on engineering. I haven’t had this much fun earning a living for a good many years!

But now one of my consulting clients has decided to offer me a job, and I’ve accepted their offer. As of this Monday (June 5), I’m officially employed. I can hear the snarky comments already — what on earth was this company thinking? They worked with me for a while as a consultant, and they still wanted to hire me? What is wrong with this place?

The company is Conifer Securities. And all snarking aside, I am just tickled pink to join a company with (a) a real need for someone with my skills and experience, (b) that is willing to have me work from home, (c) needs the skills and experience that I most enjoy employing, and (d) has a great bunch of folks (whom I already know!) to work with. Conifer is located in San Francisco, some 650 miles from me, but I don’t anticipate this making any difference at all…

Curta Calculator

When I was in high school (in the mid '60s), there were no electronic calculators. We did our math either by longhand (which I’m still fairly competent at) or with slide rules. As I was very interested in electronics, practical mathematics (algebra, trigonometry, and simple calculus) was an essential skill. I got fairly good at using a slide rule (more on that another day), but Dr. Brown (my high school physics teacher) had something even better for many purposes: a Curta mechanical calculator. He let me use it a few times, and I just loved it — but its cost was way over anything I could imagine my parents buying for me (a couple hundred dollars, as I recall), so I never even mentioned it to them.

The Curta was almost magical — it could add, subtract, multiply and divide numbers with up to 8 digits of precision (and answers to 14 digits). It used no batteries, and had no motors or electronics. The Curta worked through dozens and dozens of mechanical parts interacting in a complex way. You could hold it in one hand easily, working it with the other — and with a little practice, you could calculate far more accurately than is possible on a slide rule, and darned near as fast.

Oh, how I wanted a Curta.

Now I have one, thanks to a winning bid on eBay. Of course it doesn’t hold a candle to today’s miraculous calculators (not to mention personal computers). But it is still a marvelous little gadget, a testament to Curt Herzstark’s mechanical engineer genius. And it’s fun to use it! Just for fun, I will divide 48772.33 by 4.5538848 … and the answer (which took me 53 seconds to compute) is: 10710.049. Of course I confirmed that answer in about 5 seconds on Windows Calculator (and got a more precise answer), but that’s not the point!

Summer Is Here

It’s certainly no surprise to us that the temperature is 90 degrees (Fahrenheit) by 9 AM — this happens every summer. But it shocks us every year when the lovely spring weather (last weekend it was in the low 70s) gives way to our blast-furnace summer norms. This is the season when the house air conditioner is a prerequisite for life, not merely a luxury.

The graph at right (click for a larger version) shows the past week’s temperatures (in red, left scale) and relative humidity (in green, right scale). Last Saturday the high was 64, Sunday it was 73. Each day this week got progressively hotter; yesterday peaked at 90 and today is predicted to be in the high 90s or low 100s. Last night the humidity never went over a few percent; this tells you that it is very dry indeed, and all the surface water has evaporated — this is what happens just before our hottest days.

I went out to work this morning quite early, to take advantage of the relative cool. But even at night it was 74, and the temperature spiked as soon as the sun rose. By 8:30, working with my Husqvarna weed-whacker, I was panting from the heat, sweating profusely, and feeling light-headed. I quit work outside for the day at 8:30 am! Tomorrow I plan to be out at daybreak (about 5:30 am) whacking away — it’s a good thing my neighbors are some distance away!

Friday, June 2, 2006

Entitlement Mentality

If you died as one of the random victims of 9/11, your heirs are compensated (on average) over a million bucks. If you die as an American soldier volunteering to fight in the war on terror, your heirs are compensated a tiny fraction of that amount.

Doesn’t seem right, does it?

By Rush Limbaugh:

I think the vast differences in compensation between victims of the September 11 casualty and those who die serving our country in Uniform are profound. No one is really talking about it either, because you just don’t criticize anything having to do with September 11. Well, I can’t let the numbers pass by because it says something really disturbing about the

entitlement mentality of this country. If you lost a family member in the September 11 attack, you’re going to get an average of $1,185,000. The range is a minimum guarantee of $250,000, all the way up to $4.7 million.

If you are a surviving family member of an American soldier killed in action, the first check you get is a $6,000 direct death benefit, half of which is taxable.

Next, you get $1,750 for burial costs. If you are the surviving spouse, you get $833 a month until you remarry. And there’s a payment of $211 per month for each child under 18. When the child hits 18, those payments come to a screeching halt.

Keep in mind that some of the people who are getting an average of $1.185 million up to $4.7 million are complaining that it’s not enough. Their deaths were tragic, but for most, they were simply in the wrong place at the wrong time. Soldiers put themselves in harms way FOR ALL OF US, and they and their families know the the dangers.

We also learned over the weekend that some of the victims from the Oklahoma City bombing have started an organization asking for the same deal that the September 11 families are getting. In addition to that, some of the families of those bombed in the embassies are now asking for compensation as well.

You see where this is going, don’t you? Folks, this is part and parcel of over 50 years of entitlement politics in this country. It’s just really sad. Every time a pay raise comes up for the military, they usually receive next to nothing of a raise. Now the green machine is in combat in the Middle East while their families have to survive on food stamps and live in low-rent housing. Make sense?

However, our own U.S. Congress voted themselves a raise. Many of you don’t know that they only have to be in Congress one time to receive a pension that is more than $15,000 per month. And most are now equal to being millionaires plus. They did not receive Social Security on retirement because they didn’t have to pay into the system.

If some of the military people stay in for 20 years and get out as an E-7, they may receive a pension of $1,000 per month, and the very people who placed them in harm’s way receives a pension of $15,000 per month.

I would like to see our elected officials pick up a weapon and join ranks before they start cutting out benefits and lowering pay for our sons and daughters who are now fighting.

When I first read this, I worried that it might be an urban legend — so I ran it by Snopes. It really is a piece of commentary from Rush Limbaugh, from early 2002. And it’s mostly accurate (only the bits about the Congressional pensions are wrong — that is a persistant urban legend, repeated here by someone who really ought to know better). In reality, Congressional pensions are generous, but nothing like as generous as Rush would have you believe. The worst thing about the Congressional pensions is the way they’ve removed themselves from the Social Security system — in effect saying it’s good enough for us, but not for them. Hypocrites!

If the families of each of the soldiers we’ve lost in Iraq and Afghanistan were compensated at the same level as the 9/11 families, that would add less than $3B to the cost of the war on terror. That sounds like a lot of money, but it’s actually a small fraction of the war’s overall cost. Even a percentage of that — say a quarter — would represent a huge increase in compensation for the soldiers' families. That’s something I would certainly support, and I would think that politicians would have a hard time saying “no” to it. But I must be wrong, because nothing remotely like that has happened.

When I was in the U.S. Navy lo these many years ago, there was another conflict still raging: Vietnam. I remember well how the Navy made relatively cheap life insurance available to all the sailors headed for the war zone. I was single at the time, so insurance wasn’t a consideration for me — but every family man I knew signed up for the maximum amount (as I recall, that was $100,000). I wonder if the same thing is being done today?

Hat tip to reader (and relative!) Mike Dilatush.

Thursday, June 1, 2006

Puppy Class

Miki (and us!) had a very good time at the final puppy class on Tuesday night. There was a bit of training, but mostly it was contest, fun, and games.

I took some time at the beginning of the class to walk around and get some “portraits” of our classmates. Maverick is the gray-and-black dog — he’s huge, and is just learning how to play well with others. His owner has the biggest treat bag (the size of a grocery shopping bag) we’ve ever seen, and its easy to see why. Gracie is the golden retriever; a very pretty dog, and very attached to her family. Sadie is the black poodle — beautiful and bubbly, always happy.

'Tis a fine class of pooches!

The first event was “recall” — meaning that someone holds your dog (and pretends to be a tree — Bree’s challenge for us humans) while you walk away some distance. Then you call your dog, and the goal is to have the dog run to you. Apparently this is a challenge for some puppies, but not for any in our class — no matter how far apart Bree put us, all of our puppies ran straight to us. Bree declared Miki the winner because “…he has such a cute butt”. Now that’s a good example of female logic!

Last week Bree (our instructor) challenged all of us to train our dogs to do a “trick” of our choice; demonstrating our trick was the next event. I spent hours over the preceding weekend in an attempt to do just that, but I failed miserably. The closest we got to a trick was to train him to reliably lay down, sit up, and spin either left or right, all on a gesture (and the promise of a bit of hot dog!). But that didn’t count. On the theory that he might accidentally retrieve something for us, we tossed out a toy for him — which he promptly pounced on, but just laid down to gnaw on it. Oh, well, so much for Miki’s trick! Some of the other dogs did some very credible tricks — I was most most impressed with Gracie (the golden retriever), who would roll over and do high fives with the little girl who trained her. They were terminally cute together…

The final event — and by far the puppies' favorite — was “play time"! We just let them go, two by two, to have a rough-and-tumble good time. And a great time was had by all!

Now I have to get back to work, so without further ado here are all the photos of the class…