coding


Note: I wrote this about five days ago, right after I got back from Seattle.

I spent this past weekend in Seattle… what a blast. I loved hanging out with my cousin and his new wife. Everytime I’m with my cousin I remember the good times when we used to be in India. Now he’s got a great job, a wife, a car, a house. It’s truly amazing how quickly time passes. The only real downer this weekend was that Northwest lost my baggage on my way to Sea-Tac. That sucked.. I had to basically wear the same clothes for the two days after that (including during the interviews).

The night before my interviews was weird… I slept well, but I had two nightmares — 1) I missed my interviews and 2) I made a fool of myself at the interviews. I woke up in a state of panic/disillusionment/confusion/relief. In that order. Anyways, I got ready (didn’t have much of a selection of clothes), and we headed over to Microsoft’s campus in Redmond.

I remembered it exactly as I left it two years ago when I interviewed as a freshman. That was a harrowing experience — I basically got screwed in the first interview when they asked me to code a string-wrapping solution, and I took the brute-force approach. The interview after that was with a guy who had worked with Microsoft for 10 years; I felt like a toddler when I tried to explain to him the differences between Java and C++. The interview after that was basically trying to explain how an XML parser would work. Either way, as a freshman I didn’t know much and alas, I was too young and the experience turned out to be nothing more than humbling.

This time was different… drastically different. After losing out on a greuling, stressful interview process with Amazon (I went through three technical interviews — I made it to the “bar-raiser” — but didn’t get an offer), I decided to approach the Microsoft interviews with a sense of “try my best” and “think through everything”. More importantly, I was able to de-stress myself by taking the entire thing as a multiple-step process.

I met with the HR rep and I had a fun conversation with her — I felt relaxed and explained my reasons that I was interested in Microsoft. Throughout the rest of the day I would realize more of those interests. She told me that I’d be interviewing with the WinFS team (a truly revolutionary filesystem) and the XML Runtime team; my goal was to get dual offers. She led me outside to the recruitment shuttle and I headed off to my first interview. The recruitment shuttles are pretty sweet — completely electric cars (I think modified Prius’?) with dashboard panels that display stats on the entire car — it’s battery, etc.

The first interview was with a lively developer who was really interested in my past experience. I told him about my research in abstracting web frameworks as well as the software engineering project I’m working on. He was really friendly, and when I ruefully explained my baggage situation and addressed the fact I was dressed so poorly, he stopped and said not to worry, as he pointed to some pretty large ink blotches on the pockets of his jeans. We talked through some team-based scenarios first. Eventually he got to the coding question, which turned out to be more of a design question. It was an interesting problem that required me to find the problem first, and then the solution (Usually in computer science we’re given the problem and asked to find the solution). Eventually I solved it, and I was happy with my solution, but gave a few alternatives and analyzed time/space complexities.

The next interview was my favorite — a super-friendly developer who looked like he had been in the game for a while. He was old, but extremely knowledgable; his office was filled with books on various topics of computer science. We had a great conversation, and I explained to him a few projects I had done as well as some current projects. He asked me to describe Ajax, since he wasn’t extremely familiar with it. So I tried to take a descriptive, high-level approach by drawing state diagrams and such. I gave him an example, delineated my theories on the history of Ajax, and explained to him the problems associated with Ajax and how developers can address them. He seemed satisfied. He then asked me to write some code — specifically, to find the first non-unique character in a sentence. I thought for a bit and gave an O(n) solution, and then coded it on the whiteboard in front of him. I analyzed boundary conditions, and talked about some of the limitations. He guided me to some other limitations later on, but remarked that it was a good algorithm. It was definitely an interesting problem, and there were lots of complex issues involved.

My next interview was with an Indian guy. I was scared. He was the real bar-raiser, and asked me if I knew topics relating to Operating Systems. Unfortunately I am not taking an OS course until the Fall, so I was shaky on some of the concepts. I knew a little about thread programming, but not a lot. Fortunately, I was able to explain the concept of deadlock and how we can resolve it. He eventually pushed me towards a better solution. He asked me to code a solution to a simple problem, but what threw me off course was the fact that I had to explain all boundary conditions as I coded the solution. That was rough, but I made it through eventually.

After the third interview, I was basically sitting in the lobby and wondering if I did well. After some time, an elderly Indian man walked out and introduced himself. This was my final interview, with the guy who managed the three previous interviewers. This PM was amazing — his team includes some people who are known in the industry for their inventions, including Ajax. I knew this was the final interview, so I basically tried my hardest to show my passion and ideas regarding the state of technology. Our interview was about an hour and a half, and I had conversations with him about a wide variety of topics — how my interviews went, what I feel is most important about being on a team, what I’d like to do at Microsoft, what I think is the next big innovation on the Web (I gave two), and the general state of technology. I was asked to write some code — to reverse a linked list. I did it in O(n), and although I did it hastily, I stepped through the code for a couple of cases. He seemed pleased, and then asked me to code another problem — pretty interesting one actually, and it was more math than computer-related. I eventually got it and we took a break — I asked a few questions, and we had a light-hearted conversation. Ultimately, the interview ended and he called a recruitment shuttle for me to head back to the recruitment building.

All in all, I think I tried my best. I learned _a lot_. I had thought so much the entire day that my head was pounding by the time my interviews were over (they had gone from 12pm to 6pm). At least relative to my dreams the night before, I think I did pretty well. By the time the day ended, I had a newfound respect for Microsoft (not that I didn’t have one before). Here’s a company that takes a lot of crap from people about the stability, usability of their software, when ultimately they have a profound impact on the world. Hundreds of millions of people use Windows XP.Why? Because Microsoft knows their users the best. I am a huge fan of open source, but I have to acquiesce that open source is not a user-centric approach. It is a community effort among developers, but it is detached from the rest of the world. I think though, we’re starting to see more of a convergence with amazing software like Firefox and several other open source projects focused on attracting the common user. IBM as well has respectfully adopted open source, and the backing of a successful company like that is without a doubt going to result in something great. No matter what happens in the end, I’ve come to respect both fronts. In the end, we’re all developers, architects, designers, and managers, working for the common goal of creating software that helps people — I’m just humbled to be working with the major players in the game.
Crossing my fingers and hoping for the best…

*Update: 2/25/06 | 3:26 AM: I got an offer from Microsoft. I’ll be hanging out with my cousin and working in Seattle this summer :]

A couple of weeks ago, a friend (he worked on a different project at IBM Extreme Blue last summer) and I applied to Paul Graham’s YCombinator. It sounded really cool; if we were accepted, we would instantly get our own company incorporated and receive funding from a venture capitalist angel. We’d spend three months working in Cambridge, Massachusetts to develop a powerful product that would allow our company to hopefully be bought by some of the heavy hitters in the industry (Microsoft/Google/Yahoo). We spent a month basically researching and planning before we wrote up the application defining our product. We originally had one other person in it, but he backed out at the last minute. So last night, we basically found out. Probably in the wierdest/saddest way possible:

23:48: Phil calls. He says that he heard back from YCombinator, and he’s going to paste the email to me in an IM. Before he pastes it he says “it doesn’t look like they were in our favor…”. And then he pastes it:

(23:49:02) phil: Your proposal looks promising and we’d like to meet you in person. See http://ycombinator.com/interviews.html for details. We’ll send follow-up emails with specific interview slots soon. See you in Mountain View, Y Combinator Staff
(23:52:24) phil: http://ycombinator.com/interviews.html

At this point, i’m saying “holy sh*t” several times over, taking a deep breath, and trying really hard not to get a heart attack. I go outside on the balcony to call my Dad, I call my Mom. I’m going crazy. Then I come back to my room.

(00:03:57) phil: hey, are you there?
(00:05:30) phil: call me when you get this IM
(00:08:51) adi: hey
(00:08:52) adi: yeah i’m here
(00:09:03) phil: dude
(00:09:08) phil: they just sent me _another_ email
(00:09:09) phil: :
(00:09:17) phil: worst thing I’ve ever seen
(00:09:19) phil: You were recently sent an email with an invitation to an interview. This was due an error in managing lists of email addresses. Below is the email you should have received:
(00:09:23) phil: We’re sorry to say that we can’t accept your proposal for the Summer Founders Program. Please don’t take it personally, because most of the proposals we rejected, we rejected for reasons having nothing to do with the quality of the applicants. For example, we were very reluctant to accept any proposals with only one founder, because we think starting a startup is too much work for one person. We also rejected a lot of proposals simply because we couldn’t understand them, or didn’t understand the problem domain well enough to judge them, or because the project seemed too big to start on only three months of funding.
(00:09:28) phil: We realize this process is fraught with error. It’s practically certain that groups we rejected will go on to create successful startups. If you do, we’d appreciate it if you’d send us an email making fun of us; we want to learn from our mistakes. Thanks Y Combinator Staff
(00:09:54) phil: I wonder how many people they made that mistake with
(00:10:00) adi: oh my god
(00:10:00) phil: there were shouts of joy around the country a few minutes ago
(00:10:03) phil: and now dispair
(00:11:21) adi: no way
(00:11:33) phil: utter rejection
(00:17:23) adi: that’s even worse than rejection
(00:17:31) phil: much worse
(00:17:40) phil: maybe that means we were some ind of finalist or something
(00:18:01) adi: maybe
(00:24:08) adi: the fact that they did something like this doesn’t speak well for themselves
(00:24:48) phil: no, not at all.

I was forwarded both emails later on, and confirmed it. I also realized that the headers of the screwed up emails were coming from http://www.anybot.com, a product that was created through YCombinator. How ironic. A few minutes later, I go to digg.com and another wave of irony swept over me:

irony_small.jpg

Google had just made their Page Creator public — this was exactly the type of application we wanted to build. Of course, we had known about the rumors (it was codenamed Trogdor at the time we were writing the application), and we put in something small in our application that said that Yahoo, Microsoft, or other competitors could look to buy our application in competition with Google.

Oh well. I suppose we really did have a great idea if it was designed and implemented by Google. A few days ago my dad told me a line i’ve heard many times — everything happens for a reason. I guess I am too young to attempt startups and all the glory associated with them. I definitely need more industry experience. We’ll see what happens. Either way, I’m glad Google created something like this. It’s definitely an amazing product, and I hope lots of people use it.

Sounds simple enough but can be a total pain in the ass since JS passes the nodes by reference:

var _UISwapDOMNodes = function(parentNode, node1, node2) {
     tempNode1 = node1.cloneNode(true);
     tempNode2 = node2.cloneNode(true);
     parentNode.replaceChild(tempNode2, node1);
     parentNode.replaceChild(tempNode1, node2);
}

iFold

For my software engineering class, we essentially spend the entire semester working on a project requested by a client. We constantly keep in contact with the client and also adhere to various software engineering principles and methodologies. Our project is called ‘iFold’. The problem is that our chemistry department has software to analyze protein data and generate images and movies of proteins, but this could take anywhere from 15 minutes to 15 months. The issue is multiplied when people all over the world are trying to access the software and get denied because the queue is full.

So our goal is to provide a nice interface for these outside scientists to see the queue as well as submit jobs, etc. In addition, we have to develop our own little web server to handle the transactions coming in and going out of the visualization software. You can access our admin site here.

The next version of Javascript seriously needs a good threads implementation. Ajax communication isn’t the only example. I’ve been swearing at a single, stupid script for the last half hour. Using opacity attributes, let’s say I want to fade an image for 200 milliseconds when a user mouses over it. I also want to fade out that image for 200 milliseconds when a user mouses out of it. So what happens when a user moves their mouse across the image for 100 milliseconds?

Javascript naturally doesn’t call the mouseOut handler. So the entire thing is broken. I was using moo.fx for the fading effects, and considering the way it was designed, I got around the problem by assigning two objects the two different functions (instead of letting one object try and handle both mousing over and mousing out).

var fade = function() {
     for (var i=0;i<fade.arguments.length;i++) {
          $(fade.arguments[i]).oOver = new fx.Opacity(fade.arguments[i], {duration:300});
          $(fade.arguments[i]).oOut = new fx.Opacity(fade.arguments[i], {duration:300});
          $(fade.arguments[i]).oOut.custom(1, 0.3);
     }
}

Either way though, you’ll have a collision when you leave the image within that 200 millisecond timeframe, and the fading will flicker. Also, what if you have 100 images that you want to have this fading effect on? 2 times the objects. Sucks.

Moo.fx could try and handle this by allowing a developer to prioritize one method over another and allowing a developer to ‘halt’ another method in its process, regardless of the duration. Nevertheless, this would require a hackneyed Listener implementation where the method(s) with the lesser priority would be constantly checking a variable. So basically, javascript sucks at the moment.

Run PHP4 as an Apache module, run PHP5 as a CGI binary on a port-based virtual host.

Listen 1338
 <Virtualhost _default_:1338>
     ServerName localhost
     ServerAdmin me@localhost
     DirectoryIndex index.html index.php
     ErrorLog logs/error.log
     <Location />
       <Limit CONNECT>
         Order allow,deny
         Allow from all
       </Limit>
     </Location>
     DocumentRoot “D:/www/”
     ScriptAlias /cgi-bin/ “C:/php5/”
     Action     php5-script /cgi-bin/php-cgi.exe
     AddHandler php5-script .php .html
 </Virtualhost>

Pretty easy, especially if you’ve already set up PHP4 with your extensions and stuff. There are other ways, especially on Linux, of setting up two httpd.conf’s and using startup CGI scripts to alternate between them, but this is definitely the easiest way. It also allows you to switch between the two at “runtime”. So now http://localhost:1337 uses PHP4 and http://localhost:1338 uses PHP5.

There are tons of neat things you can learn about outside of school, especially in computer science. There are really specific products like Tomcat, methodologies like connection pooling, or new things like Ajax, and sometimes, even optimization techniques on algorithms — things you should learn about in school. Bitwise operations are a good example. Although more complex operations aren’t really that readable, there are some cool tricks you can do. For example, you can use XOR in C++ to cleverly reverse a string without temporary storage (although on a lower level, the ‘0′ bits of first and the ‘1′ bits of last together compose the temp variable). Either way, it’s fast:

void reverse (char *str) {
     char *first = str;
     char *last = first + strlen(str) – 1;
     for (;first < last; first++, last–) {
          (*first) ^= (*last);
          (*last) ^= (*first);
          (*first) ^= (*last);
     }
}

You can get even more compact with the body of that for loop by just writing: “(*first) ^= (*last) ^= (*first) ^= (*last)”. Or you can find out whether an integer is a power of 2 by using a bitwise AND to compare the integer and one less than the integer:

int isPowerOfTwo(int num) {
      return !((num-1) & num);
}

When you subtract one from a power of two, you get a string of ones. Use bitwise AND to compare that and the original number and you get a string of zeros, so you can use a logical NOT to return 1 if true, or 0 if nonzero.

I was reading a story on Marketwatch and noticed out of the corner of my eye that the text was actually changing. On closer inspection, I realized that stock information next to company names was actually changing in realtime. Pretty nifty use of Ajax. You can also mouseover the company’s name to display a full stock chart and more links. The stock ticker is interesting though.. it sort of reminds me of Pushlets. I wonder how effective it is. Just thinking about the audience, I can imagine that someone who reads stories like this are casually interested in them — they’ve got the time and they’re just browsing. I highly doubt that a changing stock ticker will actually influence them to jump on a decision to buy shares of a mentioned stock at that moment. I think the mouseover graph is definitely useful though, as it helps a casual reader to see whether or not a company has been doing well over the past quarter.

Ajax is a technology that relies on fleeting events, and it’s ultimately important to decide whether or not to use it based on the environment — I think the realtime stock ticker is useful, but not within the context of news stories. I can see it as a personalizable widget that sits on the front page of Yahoo/Google or even on the ‘homepage’ of a mobile device, but definitely not a news story where the attention of the reader is somewhere else.

For a recent project at school, I implemented a real-time search using Ajax (Openrico) that communicates with a Struts frontend, and eventually an EJB backend, all on a Websphere App Server. You can see the effect here (viewable in only Firefox). In my implementation notes, I had a section regarding this:

———————

While the Realtime search is useful in helping a user find exactly what they need by trimming down the search results in real-time, it is also theoretically the worst example of Ajax. This is why we don’t see Google Suggest come out of beta. Here’s why. Realtime search is nice, but it is horribly unefficient. There are ways to get around this but as of right now, every time the user presses a letter, it performs a subsearch that hits the HTTP server, and hits the database.

If we had a regular search, the user would type in what they need and hit the “search� button, hitting the HTTP Server and database once. However, depending on how efficient the search is, the user could theoretically hit the back button and do another search, resulting in two HTTP requests (one for reloading the page, another for performing the search request) and another, possibly more hits to the database. This also degrades the user experience.

So the key is to figure out how to optimize the realtime search. There are a few options which were planned to be implemented but were neglected due to lack of time. One option is to only perform a search when javascript detects that the user has not typed in the searchbox for 0.5 seconds. This makes sure that we don’t perform a search every time the user presses a key (for example, they might mistype something, then hit the back button, and type the correct letter – this would result in 3 hits to the HTTP Server, as opposed to 1 hit if we do it the aforementioned way).

Another possibility is to cache xml strings on the client side. For example, suppose the user searches for “dan� and doesn’t find what they need, so they type “iel� to make “Daniel�. Then, they don’t find what they need, so they backspace three times to “dan� again. We shouldn’t have to hit the HTTP server again for “Dan�, since we performed this search already. We should store, in a hash, the xml response returned from “dan� in javascript, so that when we reference it again, we can check the hash in O(1) time whether the xml string exists, and if it does, we display that instead of making an Ajax request.

This way, we ultimately approach the efficiency of a regular search, and in some cases, even perform better than the regular search. Remember when we mentioned the regular search and supposed the user did not find what they were looking for? They hit the back button, and searched again, hitting the HTTP server two times. However, the same situation can exist with a realtime search, but the user would only hit the HTTP server one time. They would type “dan�, wouldn’t find what they were looking for, so they would backspace and retype a new request; after 0.5 seconds of no typing, it would search again, without reloading the page.

This kind of algorithmic analysis is essential in Web 2.0 applications to evaluate the necessity of ground-breaking features like Realtime search and what effect they would have on the user as well as the server.

Decided to move from the blogspot address (http://distilledtemplate.blogspot.com) to this one mainly because of the ridiculous amount of comment spam. And because the WordPress CMS rocks. The group of developers I used to work with at ibiblio just released the 0.6 beta of Lyceum, a multi-user blogging package that uses WordPress. Check it out — very cool stuff.

« Previous PageNext Page »