Thursday, December 25, 2008

Merry Christmas

While there are tons of decorations in Tokyo, Christmas isn't actually a holiday in Japan. As such, I had to work on Christmas. While I wasn't able to spend Christmas with my real family, I did spend some quality time with the people who, over the course of the past year, I've come to be pretty close to.

Yep, I'm hijacking a light-hearted Christmas post to talk about trains in Tokyo.

I didn't actually take this picture, but it is pretty representative of how I spend 2 and half hours of my day, five days a week (Christmas included). Occasionally, especially in the evenings, it is so crowded I can't move or, worse, can't even stand over my own center-of-balance (meaning I'm just propped up by the surrounding crowd).

While I'm getting used to it, this was quite the contrast to the comfort of CalTrain, where I could almost always get a seat even when it was crowded. I've always been a big proponent of mass transit, but I now have I new appreciation for the comfort of one's own car. Even if you are stuck in traffic, at least you still have some personal space to call your own.

Monday, December 1, 2008

The Gay Chikan

Japan has a particular problem with gropers on trains. So bad, in fact, that 2/3 of all women in their 20s and 30s report having been molested or groped on the train. Considering that most women pass through their 20s and 30s at some point in their life, I imagine it is safe to assume that almost every women has been groped at one point or another.

To alleviate the problem of gropers, or chikan as they are known in Japanese, many train operators in Japan have implemented women-only cars to segregate the perpetrators from their potential victims. The chikan are still there, but now they have no choice but to keep their hands to themselves. In theory. In practice, the women-only cars are overcrowded (perhaps a further testament to how pervasive the groping problem is) and the pervert-to-woman ratio in the normal cars is inflated.

I don't know what the solution is, but I can sympathize with the plight of Japanese women.

'Cause I'll be damned if I haven't been felt-up by the same (male) chikan three times now. This morning was the third incident and he was about to receive the brunt of a year of pent-up stress in the form of all the beating this scraggly nerd could muster. But reason got the better of me and a gruff throat-clear and repositioning of my bag was enough to get him to back off. You see, the reality of the situation is:
  1. I've never fought anyone in my life. I'm a wuss. At 5'10 and 140lbs I've probably got 6 inches of height and 30lbs in my favor, but still, I've never kicked anyone's ass in my life. Frankly, I don't really know where to start. I'd be flailing there in my nerd rage kicking and screaming like an idiot.
  2. He has good plausible deniability. The trains are crowded; he was reading a book with one hand while feeling around for my package with the other. Now I know there was enough room that he didn't need to stand awkwardly close to me and position himself so his free arm was a close as possible, and I know that his free hand was not simply resting by his side but rather working its way my direction. But once I confront him, all that goes out the window. The train moves on and there I am, in my broken Japanese, trying to explain that this sicko was purposefully grabbing my crotch. It is just his word against mine. Gay chikans don't seem to get much coverage here...surely I'll just be seen as a confused foreigner.
  3. Had I beaten the shi*t out of him, I'd be the criminal. Honestly, this is probably true in the U.S. too. After all, feeling a guy up on a train may be a crime, but so is assaulting someone. It doesn't help that the popular image going around Japan the past few years is that most criminals are foreigners. Let's play pretend and say that I somehow managed to inflict severe injury on that pervert. If you are the police officer confronted with a bloodied and beaten Japanese man and an incomprehensible foreigner, who would you handcuff and haul off to jail? Yeah. I don't want to go to prison in Japan.
So all I could do was try to deter the guy. Luckily, he got the message but I don't really know what I can do if the pervert persists.

As a bit of history, I mentioned this was the 3rd time this guy has groped me. The first time, the train was really pretty full and, frankly, I was in denial at the time. It is pretty common for your hands to get pinned in awkward positions on a full train and he was being just subtle enough that it took me a while to figure out that it wasn't accidental. I was pissed, but thoroughly at a loss of what to do about it. That was almost a year ago.

The 2nd time, it was really obvious what he was up to. The train wasn't particularly crowded, but when he got on he positioned himself awkwardly close to me and turned such that his hand was next to my crotch. Within seconds he was feeling around while feigning reading a book. I turned to avoid him but he kept at it until I gave him a stern look and a gruff grunt. At which point he actually walked away and stood somewhere else in the train. That was about 8 months ago.

And then there was today. I had actually forgotten about this creep, but as soon as I saw him positioned awkwardly in front of me I knew what he was up to. I was channelling all of my pent-up frustration and anger to serve him up the best beating I could, but I knew I shouldn't. Luckily, clearing my throat was enough to tell him to go away and, like the previous time, he walked away and rode the rest of the way to Shinjuku at a safe distance from me. But god damn I was pissed. Pissed at this guy for repeatedly targeting me and pissed at the system for making it so hard to stop this jerk once and for all.

And this is exactly what almost every woman in Japan is forced to put up with.

At least a woman can grab his hand and call out "chikan" and have people believe her (at least in theory, this translation of a guide for woman on how to deal with chikans speaks volumes on the Japanese attitude toward the problem). But, seriously, I don't think I'm going to get the same support when I try to drag that gay chikan off the train. And, for some reason, I don't foresee the women-only car concept being extended to solve the gay chikan problem too.

Tuesday, November 18, 2008

RFC868 UDP Time Protocol Client

Here is an RFC 868 UDP Time Protocol Client implementation in less than 30 lines of python.
I know...just what you always wanted. It is a long story, but I needed a time protocol client (that would run on Windows) for testing a service we're developing at work. There are tons of implementations of the TCP version of the protocol, but I couldn't find a UDP implementation for Windows to save my life. Python to the rescue.
from socket import *
from struct import unpack
from time import ctime, sleep
from sys import argv

argv = argv[1:]
if len(argv) == 0:
argv = [ 'time-nw.nist.gov' ]

s = socket(AF_INET, SOCK_DGRAM)
s.settimeout(5.0)

for server in argv:
print server, ":",
try:
s.sendto('', 0, (server, 37))
t = long(unpack('!L', s.recv(16)[:4])[0])
# Convert from 1900/01/01 epoch to 1970/01/01 epoch
t -= 2208988800
print ctime(t)
except timeout:
print "TIMEOUT"
except:
print "ERROR"

s.close()
sleep(2)
In case you are curious, the sleep(2) at the end is there so our testers can simply click the icon on their desktop and have time to actually see the results before Windows closes the console window.

By default, it queries the time-nw.nist.gov server, but you can specify any number of servers to query on the command-line.

Sunday, November 16, 2008

A Calculus Lesson

I don't know what triggered it, but this morning I recalled a lesson I learned in high school Calculus class. You see, I was in one of those "advanced" AP Calculus classes, one that was supposed to prepare you for the Calculus AB AP Exam (i.e. the hard one). I don't know if that means anything more these days, but at the time, it was the class all the good students took.

But here is the rub: I was a terrible student. Seriously. This was senior year; while my classmates were keeping tabs on their class ranking to see who was in which position for the top 10, I just kind of floated along and daydreamed about computer programming. I think I had something of a C average in that class; I wasn't even in the top 25% of by graduating class, much less worried about being in the top 10.

Anyway, I never really bought the whole school competition thing. Don't get me wrong: I like learning stuff, but grades were always an afterthought.

The particular incident I remembered this morning, however, was a "challenge" assignment in my Advanced Calculus class. The teacher gave us an assortment of problems that he claimed he also used in his college classes. These problems were supposed to be difficult. We had a week or two to work on them, at the end of which we would turn them in and go over them. I don't recall whether they were to be graded or not, but I latched onto the challenge.

I think there were about 12 or so problems, a few of which weren't anything particularly challenging and everyone got those figured out pretty quick. A few more took a couple of days of trying to arrive at a solution. But the last few I recall being really hard. Each day, before class, my classmates would compare solutions to see if we all arrived at the same answers (we had no answer key).

To tell the truth, I rarely participated in these exchanges. The problem was that some students figured out they could be remoras to the ambitious students' sharks. While a few students compared their solutions and competed to be the first to solve each problem, others would take notes and write the solutions on their own papers.

Now, to me this seemed like cheating at the time. I thought the "smart kids" were getting taken advantage of. I suspect they knew others were copying their answers; maybe they liked the attention, I don't know. Nonetheless, I didn't want to be part of it. I tried solving each problem the best I could. If I was wrong, no big deal...I'd learn the proper solution when the challenge was over. The grade didn't matter, it was the challenge that was exciting. And I didn't want the accomplishment of solving a problem to be sullied by the doubt of having copied it from one of the good students.

Anyway, so things went for most of the assignment. It got down to just one problem that I didn't have a solution for. Again, I don't remember the details, but it had something to do with finding the area of a sphere inscribed in a cone inscribed in a cylinder with the dimensions of the cylinder given in some form. It turns out, that I was not the only one stuck on this problem. No one in my class had solved it.

Well I'll be darned if one morning the solution didn't come to me while I was in the shower. I think we only had a day or two left on the challenge assignment and I was thrilled that I might actually be able to solve all the problems. I think it was in Spanish class that I frantically jotted down my solution and solved to arrive at an answer. I used my intermediate results for the dimensions of the outer cylinder and the inscribed cone to calculate their respective volumes and confirmed that the volume I calculated for the inner sphere was less than the cone it was inscribed in and that the volume of the cone was less than the cylinder. In other words, if nothing else I knew my answer at least made sense.

So I kept my mouth shut in Calculus class that day. If anyone else had managed to solve it, they were apparently doing the same. I started getting excited at the thought that me, the lowest-ranked student in my class, may have actually done something no one there could do.

But the excitement didn't last. You see, the last day before the deadline I blabbed. No one had figured it out, the star students were getting frantic. And someone came over to my desk and asked me if I had figured it out. I hesitated for a second. With only one day left, the odds were I was going to be the only person to solve this particular problem.

And that is when it occurred to me: life isn't a contest. I could keep my solution to myself and be #1 for a day (which is saying something since I graduated 112th out of a class of 420 or so) or I could share the wealth so-to-speak. I didn't show them my answer, though. I spent the 10 minutes or so we had before class to explain how to solve the problem: what things you needed to calculate and how to obtain the parameters needed to calculate them. With that, I knew they could solve it and could still have a clear conscious knowing I didn't just give someone the answer.

Sure enough, by the end of class they had a solution and came back over to compare their answer with mine. Sure enough, they matched. They were happy to have it solved; I felt good having helped someone.

I won't say it wasn't a little disappointing to see them them immediately go back and share the answer with all of the other star students. I suspect almost everyone in the class ended up the answer for that very difficult problem. I'd be surprised if most of them were aware that I had solved it for them, but that was actually kind of fun in and of itself. More importantly, I knew at least one person solved the problem themselves, though, and I knew that they did it based on what I had told them. That felt really good.

Fast-forward 10 years and I found myself working at a Bay Area startup called Backplane with a bright guy named Matt Dillon. Not the actor, the software engineer. I remember a story that the CFO related to me about Matt's previous company, an Internet Service Provider named Best Internet. According to the story, Matt had found Best Internet with a few others and was largely responsible for the technical infrastructure. The servers and whatnot were all hosted in a data center and apparently Matt would, without hesitation, explain the details of how everything worked to any passerby who took an interest. This CFO, who was a childhood friend of Matt's, warned Matt that he shouldn't be giving away company secrets like that.

To which, Matt responded: if they know enough to understand what it is I'm telling them, then they already know enough to build it themselves anyway.

I think that is more-or-less the same thing I realized in my Calculus class so many years before, but he actually put it into words that have stuck with me ever since.

The insight, I think, is not that all information should be free, but rather that there are some truths that there is no benefit in hiding. While some processes, facts, or figures may hold special strategic value, an environment in which all information, no matter what its worth, is horded can be stifling to innovation.

In other words, you can assign a value to all information and a threshold on what you are comfortable sharing. The best engineers I have ever met tend to have pretty low information-sharing thresholds while management tends to err on the high side. The motivations are obvious. Matt, for example, is clearly an engineer while Backplane's CFO was coming from a management perspective.

What I discovered for myself, many moons ago in Calculus class, is that valuing information is a challenging thing. In my case, the information I possessed -- the solution to that problem -- was of questionable value to begin with (I didn't even know whether it was right) and the information would have zero value the following day. Furthermore, my threshold for sharing that information was unjustifiably high -- I didn't stand to gain or lose much if anything by sharing it. To make an unbiased assessment, the only obstacle I had to overcome was my own ego.

And that is the only thing I remember to this day about my high school Calculus class.

Thursday, October 23, 2008

We call those meeting rooms

If you regularly hold meetings in the office "break room", it isn't much of a break room. That is all I have to say.

Tuesday, June 17, 2008

Firefox advertising

I couldn't believe my eyes, but this morning I saw this ad for firefox on the train during my commute:



It is being shown on the in-train televisions on the JR Chuo-sen line during rush hour.

Translated, the text is roughly:

If you are using the Internet, use Firefox.
It's very very fast
I'm already hooked
The fox is crazy fast

Wednesday, May 28, 2008

Oktoberfest

I don't drink much, but I couldn't help but notice that the 2008 Hibya Oktoberfest is under way across the street from my office.

That's right: they have Oktoberfest in Japan.
In May, no less.

Sunday, May 25, 2008

The Perfect Web Interaction Language

I just noticed that my good friend JJ recently posted a rant regarding the mess that web application development has become. I've ranted about the same thing a couple of times in the past, but JJ's words carry more weight since he is a web developer by profession.

Most of this mess stems from the fact that user interaction via the web is defined by at least 5 different standards: HTTP, HTML, CSS, JavaECMAScript, and DOM. HTTP is a protocol; all of the rest are languages, each of which having completely different syntax from all of the rest. On top of that, each standard has multiple different versions. More importantly, each implementation of these standards has varying levels of compliance, effectively creating an ever-changing target to develop for.

Take HTML for example. It is a mess: each web browser has historically rendered the same HTML content slightly differently, supported different tags, and been accommodating of syntax errors to varying degrees. To move the web to a single, consistent, language for describing the content of web pages, the W3C wrote a new specification: XHTML.

Now, good web developers ensure that they always output conforming XHTML, but not everyone does. But then, not every browser accepts conforming XHTML, so there is good reason not to use it (and, as JJ notes in his rant, browser developers have recommended sticking with HTML 4.01 to "ensure the widest browser and search engine support").

This lesson of XHTML is important: it doesn't do any good to make a new standard because you cannot force all browser implementations to support it. In fact, it only makes the problem worse because it simply adds one more possible input a browser may be reasonable expected to accept, hence lengthening the already-too-long list of standards browsers must support (and developers will be expected to know).

CSS, ECMAScript, and DOM are all similar: each browser implements a different set of features that partially overlap each other and partially overlap the standards themselves. An experienced developer is expected to know (and keep up with) what subset of features are safe to use on all targeted browsers and which have equivalent functions and what hacks are necessary to trigger those functions on the implementing browsers. The fact the people even talk about targeting browsers shows just how far we are from having any consistent standard we can depend on to work no matter what browser the document is viewed in.

Now add to this the fact that the HTTP protocol itself, the protocol that is intrinsically linked to HTML, is 176 pages long and (from my experience) poorly understood by most web application developers. Or consider for a moment the fact that you even need to be fluent the mechanics of how the content is delivered to the user (and how input is delivered from the user) in order to write even a simple application. This is Joel's Law of Leaky Abstractions writ large.

Now, let's take a cue from John Lennon and imagine we could start from scratch -- what would the "perfect" environment for web application development look like?

At this point, the problems with the current model are pretty well understood. What if we pretend there is no baggage and we could just start over, developing a perfect language for describing user interaction. Imagine we could develop and deploy a new "browser" that understood this new language and implemented it perfectly to our specifications. Think about it. Seriously.

Not a re-implementation of HTML or XHTML. Not a better JavaScript. Not a better CSS. Those are all thinking too small. How about a single language the describes all aspects of user interaction with a single syntax?

You may say I'm a dreamer, but I'm not the only one.

In fact, as I mentioned above, the W3C has been making motions in this general direction for years. They proposed XHTML and CSS as replacements for the mess that is HTML. But if XHTML and CSS are still not properly implemented by all browsers almost 10 years after their introduction, why should we expect anyone to implement our "ideal" all-encompassing interaction specification language?

My suggestion: we don't.

May I suggest instead, a translator. One that takes a document written in our web interaction language as input and outputs all the hairy HTML, CSS, ECMAScript, etc. that is necessary to get the predominant browsers to behave the way specified by that document. That is, admit defeat and relegate the current web development paradigms to mere implementation details.

In fact, this may not be as crazy as it sounds. There are a number of XHTML templating toolkits for python that can be configured to convert generated XHTML documents into plain old HTML 4.01 documents that all browsers support. Consider extending this concept beyond just output generation, but to the whole of web application interaction.

Think of it as writing a compiler in which the output "machine code" is HTML, CSS, ECMAScript, and the server-side logic.

Is this pie-in-the-sky dreaming? Sure. Is it a hard problem? Sure. Does it risk running afoul of the Law of Leaky Abstractions? You betcha.

But codifying web best practices and cross-browser support behind a consistent high-level language and compiler is priceless. Just imagine the beauty, the joy, that web application development could be. Imagine how much more productive you could be if you weren't coding CSS hacks and having to test on 5 different browsers after each change.

Yeah, it's crazy. But what is the alternative? Convincing every browser vendor in the world to (finally!) implement standards correctly, convincing every person in the world to upgrade to the standards-implementing browsers and ensuring they stay up-to-date as bug-fixes are released for those browsers? Now who is talking crazy?

Friday, April 11, 2008

Turned 0x20

Wow, I just noticed that it has been months since my last blog update. Turns out that with the long commute, I don't have nearly the amount of free time I used to have. It probably doesn't help that I have to stand/walk for the entire 3-hour round-trip commute; I'm just exhausted at the end of the day.

Anyway, I'm just writing a post to say I turned 0x20 today. At least that is what I told my wife to say when she had her birthday back in February...she's having more trouble with getting old(er) than I am. She didn't like 0x20 because it looked "too young" so we compromised on 26 (duodecimal). She thought that felt more like it.

I'd just assume to tell people I'm 100000, but I don't think too many people would find that funny.