November 21, 2014

Gottalove Gattaca!

Just for the record, let it be known that I wasn't one of the detractors who voted against this essay. I'm actually promoting it.

I love it.


December 31, 2012

Quora answer on Programming advice for novices

It’s that time of year when I can sit down to write letters and other waffly things. I have wanted to follow up on this question ever since my friend Josh Levy posted an excellent answer many moons ago. Here’s my chance to chime in with an orthogonal perspective.

A popular anonymous quote best captures what I’m about to say, and be warned - it’s going to look counter-intuitive at first: “Please excuse the length of this letter. I do not have the time to be brief.”

After many years of soaking in the field, first as a hobbyist in my teens, then as a formal student of CS, as a practitioner coding for hours on end in various languages, as a faculty member teaching the science and the art, as a hiring manager of many top-notch programmers with whom I am proud to be associated, and most importantly as a nerd unafraid to code at every available opportunity, I have come to realize the subtle truth in the following dictum. I now try to impart it to aspiring newbies any time I’m able to:

“Strive to code many hours, but few lines.”

Continue reading "Quora answer on Programming advice for novices" »

December 3, 2011

Do it with D3 - Lazy Loading Images

I'm lucky to have stumbled upon Mike Bostock's excellent D3 library when I was looking for a good implementation of force-directed layouts for certain kinds of graphs. I now use it for many more things than graph rendering. Data Driven Documents are indeed the future of the web and HTML5 apps, and d3.js is sure to have an enormous impact.

As an example of how D3 helped me greatly simplify things I'd hitherto put together using plain ol' javascript and jQuery, Here's an adaptation in D3 of a lazy image loader I'd written last year. The old code was over 50 lines long and not as simple as befits an obviously simple task such as lazy loading.

Now, using D3, the code is an awesome 10 lines of pure simplicity. See the demo here. (View Source to copy).


October 16, 2011

A Google room with two doors

A room with two doors and scant else. Despite some points made in Steve Yegge's fantastically well-written and enjoyable rant, I've always thought Google's obsessive product focus and extreme emphasis on minimalistic designs a wise investment. After all, you can always furnish an empty house with furniture of your liking (as long as the doors are wide enough), but you can't reconfigure a home crammed with someone else's favorite furniture that's bolted right down.

But then I recently noticed an alarming misstep in Google's product design - Almost half as bad as LinkedIn's horrible home page that has 'Sign Up' fields showing by default rather than 'Sign In' fields with an optional link to 'Sign up if not already a member'. The latter and better design makes it easy for returning visitors (which a CEO should hope to be many). The former makes it one search-and-click harder for loyal users while embarrassingly making this implicit admission - that there is a greater business need for new users than for retaining existing ones. The latter says we'll take good care of you once you're with us. The former says "We love those that don't love us more than those that do - That's natural human psychology, and you better get used to it right now, so there!"

Continue reading "A Google room with two doors" »

May 9, 2011

What's a Yot?

Last week, on the way back from my swim at the Y, I noticed a number of cop cars outside the house opposite the Y. I was consumed with curiosity as any sane person would be, but wouldn't dare stop and ask them what it was all about. We all know how much cops like lookie loos.

Continue reading "What's a Yot?" »

May 8, 2011

Ode to Tech Cooks

I wrote this for my wife's recipes website a few months ago. But I like it so much that I have decided to share it with everyone :-) :-)

Ode to Tech Cooks

No potatoes, no carrots, no garlic nor leeks
But algos and APIs, ambrosia for us geeks

No whey, no milk, no butter nor curds
Just programming poils, to bond with fellow nerds

Not how to make pickle, with dills that are kosher
But how to get out of one, with clever use of closure

Not how to jazz up that boring curry with spices
But how to resize in real-time with push, pop and splices

No mention of pesto, pate, or fry-less fwitters
We're itchin' to share how we wall-posts and twitters

You won't find us by the oven, or sweatin' by the stove-top
We're lounging on that sofa, logged into our lovetop

Not chopping, not dicing, not sifting by the pound
But hacking, tuning, refining, 'til Zarro boogs found!

PS. BTW, I know at least one other person (Stewart Alsop of Alsop-Louie) likes this poem. But he's a self-confessed foodie like me.

A proof from the mouth of a babe

One of the high points of this last academic year has been volunteering in Katya's 2nd/3rd grade English and Math classes. I was suitably rewarded for this just a few weeks ago with a delicious treat of an elegant mathematical argument from a 2nd grader (Katya's in 3rd). Here's the puzzle and its solution (names of individuals have been changed).

It all started with the teacher, Judith, posing a seemingly simple problem to the kids. She was teaching fractions that Thursday. In the latter half of Math class, the kids were each given rectangular cards, and asked to imagine they were cookies (or pizzas). Since classes at Ohlone are always mixed between two grades, the problems are always posed in a range of difficulties. With this one, the kids had to divide up their cookies into 2, 4, 8 and 3 equal parts. The more different ways you could slice it up, the more points you get.

The puzzle I want to talk about concerns the division of the rectangle into 4 equal parts. Most kids did it the conventional way, by which I mean folding the rectangle in half, first vertically, then horizontally, and cutting along the creases. Edgar (name changed), however, adopted a different tack. He folded the rectangle along its two diagonals.

The cool thing about this is that it's not immediately obvious that this way of cutting the rectangle produces 4 equal cuts, especially not to 2nd or 3rd graders. See the figure below, for instance:


Can we tell immediately that Slice A is the same size as Slice B? Edgar claimed they were, but wasn't able to explain it - he just felt it in his gut. Judith, awesome teacher that she is, immediately recognized the opportunity to enrich and picked up on this issue, calling the attention of the entire class to the problem. She wrote it up on the white-board and named it "Edgar's challenge". Anyone who was done with the rest of the problems was welcome to give it a shot. Can they show that the four slices were the same size?

Continue reading "A proof from the mouth of a babe" »

February 24, 2011

Gmail Autologout and Timed Session


If your family is anything like ours, and your home is anything like ours, then you probably have one laptop per member on average, but everyone seems to prefer to use the "living room laptop" that's always sitting on the coffee-table. Thank Google for this - We don't really need to live down on earth any more, preferring instead the lofty locale of the clouds wherein most of our data resides.

The upside of this situation is that we are much more tolerant of individual computer crashes, since every machine to us is pretty much the same once we login. But the downside is that we invariably forget to log out of sessions in the common pool of machines we tend to use. This is normally no big deal, but the living room laptop tends to get used by our guests too. I have too often had to log out of private email sessions left open by our guests (as I hope my hosts will do for me in their homes :-)

To save time, worry and potential embarrassment, I've always wished that Gmail provided a configurable Autologout feature that users can turn on in their personal profiles. This would save them the trouble of having to remember whether they logged out of their sessions before they left for home.

Finding no such "Labs" feature and waiting all too patiently for it to appear, I eventually ended up writing my own (based on Chris Nguyen's cool Greasemonkey script for Searching Unread mail in Gmail). Because I have it on good authority from my friends at the big G that a full featured auto-logout will likely make its appearance in Gmail Labs sometime soon, I saved myself the trouble of embellishing the bare-bones functionality of this feature. But I find it useful, and hopefully so will you, until the official feature is released from the plex.

Here are the few really simple instructions on how to get a timed Gmail session with auto-logout within your browser. Oh, BTW, I implemented a Timed Session, rather than auto-logout based on inactivity - it's a quicker hack; I didn't have to listen for events and such.

Continue reading "Gmail Autologout and Timed Session" »

November 6, 2010

Client-side image crop and then upload

Earlier this week, Mathangi wanted to know if it's possible to crop an image in the browser and then upload it to the server for her website. I promised I'll think about it over this weekend. So I got up early today and spent a good hour looking around for a solution. There seems to be a ton of code out there that lets you crop an image using JavaScript and PHP, including the excellent JCrop library. However, these all seem to be written for pre-HTML5 days. While you can define the crop area on the client, actual cropping is done on the server. See for example, at the time of writing, the disclaimer in the JCrop manual.

Jcrop creates an interface to crop an image. However, actually creating a new, cropped image file is obviously beyond the scope of a client-side plugin. It may also be the most challenging part of implementing such a process in your web application (now that you've found Jcrop).

Unfortunately, this defeats the whole purpose of the upload for my wife. She wants the image cropping to be done on the client because the upload will be much smaller, and only consist of the area of interest that the user wants to upload. Not the whole 10MB JPEG file. But fortunately, the task may not be as challenging as the disclaimer suggests.

So I put together a quick and tiny solution using a combination of JCrop, JQuery, HTML5's neat File and Canvas APIs, and a "clever" trick. Here is the full code in its awesome smallness (only about 32 lines for the HTML file and 55 lines for the JS including comments). Obviously you need to embellish it considerably.

You can see this code in action at this demo here. Of course, it only works in HTML5 compatible modern browsers, such as Chrome, Firefox and Safari.

If you're just interested in the code, feel free to grab it by Viewing Page Source, and then linking through to the JavaScript in the file crop.js.

Continue reading "Client-side image crop and then upload" »

November 3, 2010

How much energy does a 100kg human pack?

One of the things I absolutely love about dropping Panini off at JLS is to engage in some absolutely refreshing nerdy conversations. These are always interesting, often funny, and frequently educating to both of us.

Today, we talked about fusion and energy. It turns out he was just learning about the periodic table and the elements. He asked how a helium atom can be made from hydrogen atoms and enquired why the mass of the helium atom is less than the mass of the "ingredients" that went into it.

I, of course, took that opportunity to introduce fusion at a high level and said that some of the mass is turned into energy. He was amazed to learn, as we all are at first presentation, that mass is a compact form of energy. So he naturally asked "How much energy is there in a person if we turn them completely into energy?"

I said that's pretty easy to calculate. Let's make some simplifying assumptions. Take a person that weighs 100 Kilograms so we can work the numbers in our head while still paying attention to the road. Einstein's equation tells us that the mass of this person, if converted entirely into energy is given by E=mc2. If we assume c to be 300,000 kilometers per second, or 3x108 meters per second, then c2 is 9x1016. If we multiply this by the mass of the person, we get 9x1018 Joules.

Here is where the fun really starts. On face value, 9x1018 Joules is just a number, albeit a pretty large one in energy-speak. When you state a bland fact like "A 100 Kg person can be converted into 9x1018 Joules of energy if we completely annihiliate them, reactions will be very mixed, ranging from "Wow that's interesting" (meaning actually not) to "that's a huge amount of energy, isn't it?" (meaning, "I have no idea what that means").

Continue reading "How much energy does a 100kg human pack?" »

Powered by
Movable Type 3.35