Big-endianness and LTR
Wednesday, September 29, 2010
I go slow when mentally adding commas going backwards from the last digit, because it's unnatural for me to read right to left. So I do this instead: I scan forwards (left to right), mentally checking off groups of three digits, and when I reach the end, I see how many digits were left over, and jump back to the beginning of the number and make the call.
So I go: 143, 334, 455, with one digit left over (7), jump back and say, that's 1.4 billion.
Of course, it would be a lot easier if it were just written with the commas to begin with (1,433,344,557), but I don't always have that luxury.
The Goggles... they do something!
Monday, September 13, 2010
I found a picture of Djokovic through an images search, zoomed into it on my computer, took the photo shown here with my Android phone and then fed it to Goggles. Goggles nailed it! The first and only result I got back was Sergio Tacchini.
It was amazing, given that my photo was rather crappy, and taken off an image on my monitor. I suppose I could also have found the answer through Wikipedia, but Goggles was just so much cooler to see in action.
Speculative parsing and chunk size
Wednesday, September 01, 2010
You probably know that the latest browsers perform "speculative parsing" (a.k.a. "preload scanning"). Say the UI thread is waiting for a script to download. The thread won't (can't) continue building the DOM from the rest of the page, because the script may affect the DOM. So the script must be parsed and executed first. However, there's nothing wrong in at least scanning the rest of the page quickly for resource URLs and queueing them up for download, while waiting for the script to arrive.
However, once the script has arrived, the UI thread will get busy parsing and executing it. It won't be able to look for any more resources if some more page content arrives during that time.
Consider an HTML page that's delivered in two chunks:
<!-- chunk 1 -->After the first chunk arrives, the browser parses it, discovers the script (foo.js) and queues it up for download. While waiting for the script to download, the UI thread is idle, so it scans the rest of the chunk, discovers the image (bar.jpg) and queues it up for download as well. Now, assume the script finishes downloading before the second chunk of the page. The UI thread will start parsing and executing the script. Imagine the script takes a while to execute, and during this time, the second chunk arrives. The UI thread will not get to the chunk until the script is done, so you'll see that the second image (quux.jpg) isn't discovered or queued for download until much later.
<!-- chunk 2 -->
I was trying to demonstrate this effect in Chrome. However, even though I was sure that I was flushing the first chunk properly, Chrome didn't seem to even start downloading the first script (foo.js) until the page was done (all chunks had been received). Safari behaved the same way. After some more testing, I realized that it was because my tests were too small. These WebKit browsers do not scan the rest of the chunk unless the chunk is at least 1KB in size! Firefox doesn't have this issue. It scans the rest of the chunk no matter how small it is.
A couple of my colleagues (Tony and Bryan) suggested that this was due to charset sniffing. Indeed, that was the case. When I specified the charset, the issue seemed to go away. Chrome issued the fetch requests for the script and image right away.
However, when I made the first chunk even smaller than before (but still specifying the charset in the Content-Type header), the issue came back. I.e., Chrome still waited to buffer up more chunks. I realized that this is because of content sniffing. I confirmed that once 256 bytes had been buffered, the chunks would get parsed.
For each resource, Chrome may buffer the first few bytes before parsing them. It does this to figure out the content-type, the charset (encoding) and the doctype (i.e., whether quirks or standards mode). Specifying content-type and charset explicitly helps, but for text/html resources Chrome still needs to buffer to detect the doctype, due to underlying webkit constraints. The buffering may be 256 or 1024 bytes depending on the above.
Monday, February 15, 2010
It was a nice and warm day; the trail was well kept; the scenery was very pleasant (photos). At the top at Rose Peak, we could see the clouds below us. We walked the last hour in the dark, but thanks to Gurmeet's flashlight, it was not so bad.
Towards the end of the hike, I found it hard to say which I found more painful - uphill or downhill. Uphill was slow-going, heavy-breathing and groin-aching. Downhill was knees-killing. It didn't help that I had to lug around my backpack loaded with a lot of useless things, including an umbrella, extra pair of shoes and a couple of t-shirts.
It was my first time. And it was awesome!
Wednesday, February 10, 2010
I'm not a basketball fan, so I didn't know anything about the teams (Golden State Warriors vs Dallas Mavericks). I kinda assumed that they were some random teams, so I thought it'd be like a random little league game, with a few die-hard fans thrown in.
Whoa, was I wrong.
The thing that struck me the most was the professionalism of the whole thing. The stadium (Oracle Arena) was in full swing. Lights, ads, real-time TV display, awesome camera work in replays, slow mo and angles, popcorn vendors, etc. Every timeout, every gap between the quarters, the NBA had something going on - trampoline stunts, 3rd grade kids playing, pizza give-aways, t-shirt guns, lucky draws, guess-the-song contests, and uh, the cheerleaders. Having played a minor logistics role back in my school days, I appreciated the co-ordination and practice needed to pull off such a smooth operation.
The game itself was not as much fun. The Warriors led for the most part, though both teams were playing very fast and loose. Eventually, the Mavericks tightened up their game, and won handily. Apart from the 3rd grade kids playing full-on basketball, the most fun I had was listening to a couple of vociferous Warriors supporters nearby. "Are you blind, referee??!! Come on man! The guy was sliding on his ass! Dirk No-game-zki!" and so on.
I can only imagine what it would have been like if the Lakers and Kobe were playing...
Sunday, December 14, 2008
— Mohandas Gandhi.
Sunday, December 14, 2008
— Richard Dawkins, Preface to The Blind Watchmaker, 1986.
Liberty and security
Sunday, December 14, 2008
— Benjamin Franklin, Historical Review of Pennsylvania, 1759.
Pursue a dream
Thursday, December 11, 2008
— Guru Profile, http://www.guru.com/channel/tech/portrait/P66.jhtml, Aug 1999.
Not run but proven
Thursday, December 11, 2008
— Donald Knuth, Notes on the van Emde Boas construction of priority deques: An instructive use of recursion, Mar 1977.
Not wrong but illegal
Thursday, December 11, 2008
— Richard Stallman, Interview with RMS by Hiroo Yamagata, Aug 1997.
Then they came for me ...
Thursday, December 11, 2008
— Martin Niemöller, Congressional Record, Oct 1968.
Make a bonfire of your reputations
Saturday, November 08, 2008
"I give you this one rule of conduct. Do what you will, but speak out always. Be shunned, be hated, be ridiculed, be scared, be in doubt, but don't be gagged. The time of trial is always. Now is the appointed time."
— John Chapman, Commencement Address to the Graduating Class of Hobart College, 1900.
What's your project?
Saturday, November 08, 2008
I know mine. I started on it about 6 years ago, pursued it on-and-off for about 2 years, and then ignored it completely for the next 4 years, as I moved jobs. Now, I am on the threshold of moving into a new role, and I am filled with a determination to get back to my life's goal. One of these days, I will have done enough work on it to perhaps even submit it for a Ph.D. thesis.
When it's done, it will have a deep impact on traditional software engineering.
Saturday, November 08, 2008
Today, I set out to do some work in the morning, which I finished by noon. It was an okay piece of work (nothing great, just a side-by-side evaluation). Still, I knew I wasn't going to do anything as good for the rest of the day. I had some other stuff to do - emails and facebook messages to respond to, expense reports to file, etc. But, they all seemed so much lesser (in worth or excitement) by comparison. It was going to be downhill for the rest of the day.
That made me very lethargic. I just lazed around, to the point of falling asleep. I tried watching a movie, but even that wasn't very exciting. I told myself "Okay, tomorrow, I'm going to wake up early, exercise, and finish all these items on the to-do list right away." I was just procrastinating.
After several hours, I forced myself to get back onto facebook, and voila, I was having fun again. Perhaps it was the social nature of the task. Or perhaps I had just gotten past the activation energy point. In any case, I understand a little bit more about myself now, and how to get myself off my butt. I need to nail it, to get those sadhabhishekam videos done.
Tuesday, March 25, 2008
It's hard to avoid that feeling. That private thrill of "Serves him right!". Despite that I am more secure in my life than most, it happens to me too. Recently, I witnessed a negative comment about somebody's code that made me feel a little smug.
Ask yourself: The last time you said "I am happy for you", were you really so? Or, was it because it was the right thing to say?
As with most failings, I think just recognizing that we are prone to them is winning half the battle. To go further, we should remember the instances when we succumbed and consciously try to overcome them.
Power and discretion
Saturday, March 22, 2008
Recently, I was walking out of my office building when a security guard stopped me. I was headed towards an exit which was not "officially" opened. Never mind that it was fully built and functional, that I and others had already used it a few times before, that it was in fact going to be officially opened the next day, that there was nothing blocking the exit save for a tiny string, that it was the shortest route out or that there was no physical, logical or spiritual harm in letting people walk out that exit.
He felt bound to enforce an arbitrary rule. He made me walk around to the official exit (which was anyway right next to the one I wanted).
Just a few days before that, the security guards and their manager at a food court tried to stop me putting tables together. In this food court, all the movable tables and chairs are arranged so that they seat four persons each. We were a larger group, so I pulled two tables and their chairs together. We were about to eat when these chaps showed up and demanded that we separate the tables. No amount of logical reasoning could disabuse them of the notion that the food court's rule about not joining tables was sacrosanct. I pleaded to let us eat in peace, and after we were done, to have their way. Ultimately, they relented.
In general, I find that the guys in smaller positions of authority (security guards, middle managers, constables, clerks in government offices, etc) tend to wield their power absolutely. They don't use their discretion. Their standard defense is that those are the rules, that they didn't make the rules, and that they will get flak from their higher-ups otherwise. To some extent, that defense is valid, but I see it used even when it's okay to bend the rules sometimes.
I have seen this a lot in Singapore. Few people feel empowered to use their discretion. In fact, there are many who relish being stubborn about the rules. Sadists.
On the contrary, the people in higher positions of authority tend to be more flexible. The CEO of my company has his eye on the big picture, on the things that really matter. He is less likely to say "No" to a little extravagant spending, for example, than the immediate manager who approves the expenses. The CEO doesn't want to waste his time bickering about little rules.
As a manager with a little power myself, I am acutely aware of my responsibility to not fall into this trap. I try to consciously think about these things when I invoke a "rule".
Foolish consistency is the hobgoblin of little minds.
Expertise and effort
Tuesday, January 08, 2008
Okay, that was very opaque. Let me explain. Let's take an expert doctor, for example. He's able to diagnose illnesses accurately. We are amazed by his skill. How could he guess correctly that the child was not using her arm because of a specific injury called the Nursemaid Elbow? How did he know just by looking at her?
This sort of expertise is apparent expertise (as opposed to innate expertise, which is skill that one is born with). A lot of skill and knowledge is acquired over time. We may have an aptitude for certain skills, but we still have to work hard at acquiring them. The doctor didn't get to where he is today without a lot of study and hard work.
Moreover, the doctor has to stay on his toes. He has to keep up with changes in the field of medicine. He has to learn from his experiences every day. He has to put in a lot of effort to keep up the appearance of his expertise.
Another problem we don't realize often is that expertise in one area doesn't usually translate to expertise, or even just competence, in another. For example, you may be an expert in a field, but it doesn't mean you can explain it well to your students.
I gave a talk today about an internal system. It seemed to have been received well, but I was disappointed. I thought it was haphazard and lacked coherence. I've yet to see anyone criticize a technical talk, so I don't place too much faith in the seemingly positive reception. I know the talk was bad. The problem is that though I am a reasonably good speaker, have no stage fright and am very comfortable giving talks (having been a lecturer before), lack of preparation hurt. There's no getting around putting in the effort to prepare a talk.
Similarly, no matter how good you think you are, how experienced you may be, you have to make the effort to prepare. You have to plan your interview questions beforehand. You have to think ahead of a detailed work plan for you intern. Otherwise, the outcome will usually be suboptimal.
Tuesday, July 31, 2007
Learn to listen. Don't dismiss people or ideas outright, no matter how wacky they may be. If your colleague's argument seems to be full of crap, look deeper. Look for the gem in their argument.
If somebody criticizes something you feel passionate about, try to understand what it is that caused them to feel that way. People freely use extreme words such as "never" and "always" without really meaning to. Perhaps your colleague is overgeneralizing, extrapolating to situations that make the argument obviously bogus. If so, ignore those generalizations. See if the argument is applicable in some context, any context. Find that positive thing.
How does it matter?
Tuesday, July 31, 2007
My advice to you is to focus on what matters. Even if your colleague hasn't expressed himself well, even if he hasn't highlighted the important things, concentrate on the core of the idea or argument. Resist the temptation to tear the rest of the idea down. Ask yourself if the thing you are bringing down really matters to the point being made. If it doesn't, ignore it.
This is similar to the concept of "constructive criticism," but not quite. Constructive criticism is a good idea, but it has been overexposed. At the workplace, I cringe when a pacifist uses this sword to silence a vocal, unpopular, detractor. It's worth understanding the difference. The pacifist insists that you should not criticize unless you have a solution to offer to the problem. That's too onerous a requirement. I think you'll agree that many times, we can easily see what's wrong, even though we may not know how to fix it.
My point with "How does it matter?" is different. Feel free to criticize, without offering any constructive solutions, but do focus on what really matters. A common scenario is when dealing with analogies. Few analogies are perfect. Instead of pointing out how your colleague's analogy is flawed, because of this-and-that, try to understand the essence of the analogy and see whether you agree with it. If possible, ignore the analogy completely, as it's only supposed to be an aid in understanding the argument, and not the argument itself.
Harry Potter and the Hallows
Wednesday, July 25, 2007
Rowling's style is not as bad, but her abuse of adjectives irks me. She has an obsession to adorn every noun with an adjective. Stephen King has similarly criticized her overuse of adverbs. Here's the evidence (choice excerpts from the first two pages):
Really! Do we care that the floor was made of stone or the handle of bronze? "Roaring fire," "handsome marble mantelpiece" and "gilded mirror"? Argh. I know I'll still finish the book. It's magic, you know.
The lane was bordered on the left by wild, low-growing brambles, on the right by a high, neatly manicured hedge.
"Thought I might be late," said Yaxley, his blunt features sliding in and out of sight as the branches of overhanging trees broke the moonlight.
They turned right, into a wide driveway that led off the lane. The high hedge curved with them, running off into the distance beyond the pair of impressive wrought-iron gates barring the men's way.
A handome manor house grew out of the darkness at the end of the straight drive, lights glinting in the diamond-paned downstairs windows. Somewhere in the dark garden beyond the hedge a fountain was playing.
The hallway was large, dimly lit, and sumptuously decorated, with a magnificent carpet covering most of the stone floor. The eyes of the pale-faced portraits on the walls followed Snape and Yaxley as they strode past. The two men halted at a heavy wooden door leading into the next room, hesitated for the space of a heartbeat, then Snape turned the bronze handle.
The drawing room was full of silent people, sitting at a long and ornate table. The room's usual furniture had been pushed carelessly up against the walls. Illumination came from a roaring fire beneath a handsome marble mantelpiece surmounted by a gilded mirror.
Prudence is the better part of valour
Monday, July 23, 2007
I am not talking about putting foot in the mouth, blurting out secrets, being obnoxiously garrulous, etc. I am talking about other situations where our instinct is to say something, but the world would be a better place if we restrained that impulse. Here are some examples:
You are head over heels in love. You can't contain your enthusiasm. You want to keep professing your love for your significant other. You know what? Sometimes, you should just put a lid on it. It is good advice, as is most other "don't overdo it" advice. Withholding a little can make the relationship last longer. Keep him/her running.
You are incredibly smart. Any time any topic comes up, you have the definitive answer or a very strong opinion. You solve everyone's problems, even when the question is not directed to you. Stop doing that! People hate know-it-alls.
You are completely truthful. You tell your spouse or your best friend everything. This thing on your mind bothers you, though. It is a little too personal. Be discreet. Convince yourself that it's insignificant. You share all the important things. Those that matter, anyway. As someone said, knowledge changes things. Your friend may be affected irreversibly by that knowledge. The very fact that they have a certain knowledge changes the world.
Your kid believes in Santa Claus. Your coworker wouldn't understand why you were told he's about to be fired but he wasn't. Your dad doesn't know that everyone can see past his innocent bullshit. And so on. Use your discretion.
Domain hosting with Google
Saturday, July 21, 2007
When I got sreeram.org in 2000, I hosted it on Srikant's machine. He was employed at the National University of Singapore (NUS) and had his own static IP and a Debian box. I preferred OpenBSD. I put my own machine next to his, and connected the two through a crossed-cable. My machine used to make a lot of noise, which bothered Srikant. So, I hid it inside a cabinet. However, I didn't have enough cooling, and eventually the box fried.
Soon, I joined NUS myself. I took care of the systems and network at the Medical Computing Laboratory, so I was able to move my site there. The School of Computing didn't allow incoming connections. Ordinarily, it would have been impossible to host my website there. However, we had a static IP for the lab where we hosted the lab's website, so I was able to use that for my site as well. The school's security policies regularly inhibited my site from working. While I worked around most of them, eventually I gave up and looked for a better home.
Kartik agreed to host the site on his cable-modem connection. He installed OpenBSD on a spare PC, and I administered it remotely. This worked well for a while, including after I left NUS. However, one day that box failed and my site went dormant. For the next three years, it dropped off the web.
I have now brought it back. Instead of insisting on free hosting and OpenBSD, I've now resorted to Google. Google provides free hosting for web, email, blogs and a suite of other applications (calendar, chat, docs and spreadsheets) through its Google Apps For Your Domain (GAFYD) service. This, along with the goodies it comes with (online administration, backup, failover, great bandwidth, etc), is as good as it gets for hosting your domain for free.
A technical issue: With GAFYD, it's not possible to use the root domain for your website. You have to use a subdomain, typically "www". You can't use a CNAME for the root record, and just specifying the IP address of the www site doesn't work. Luckily for me, my domain registrar provides free web forwarding, so I have redirected the root domain to the www site, so http://sreeram.org/ works.
No, but ...
Friday, July 20, 2007
Why do we do this? Kartik suggests that it's because of a subconscious need to have the last word. Agreeing with somebody doesn't feel like you had the last word. You feel that the person who proposed the thing you agree with had it. Hence the need to assert the last word by disagreeing and putting forth your point of view.
I agree that this plays into it. However (heh :) "No, but ..."), I think a deeper cause is that we don't really care for what other people have to say. We care more about having our say. We love to hear our own voices. The "No, but ..." really says, "Yeah, whatever. Now, listen to me. I think ..."
I am reminded of an exhortation my dad had scribbled on the inside of an encyclopaedia: "Speak because you have something to say. Not because you have to say something."