Monday, January 30, 2006

Rasmus’ 30 second AJAX Tutorial

I find a lot of this AJAX stuff a bit of a hype. Lots of people have
been using similar things long before it became “AJAX”. And it really
isn’t as complicated as a lot of people make it out to be. Here is a
simple example from one of my apps. First the Javascript:

function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function sndReq(action) {
http.open('get', 'rpc.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();

if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}

This creates a request object along with a send request and handle
response function. So to actually use it, you could include this js in
your page. Then to make one of these backend requests you would tie it
to something. Like an onclick event or a straight href like this:

[foo]

That means that when someone clicks on that link what actually happens
is that a backend request to rpc.php?action=foo will be sent.

In rpc.php you might have something like this:

 switch($_REQUEST['action']) {
case 'foo':
/* do something */
echo "foo|foo done";
break;
...
}

Now, look at handleResponse. It parses the “foo|foo done” string and
splits it on the ‘|’ and uses whatever is before the ‘|’ as the dom
element id in your page and the part after as the new innerHTML of that
element. That means if you have a div tag like this in your page:



Once you click on that link, that will dynamically be changed to:


foo done

That’s all there is to it. Everything else is just building on top of
this. Replacing my simple response “id|text” syntax with a richer XML
format and makine the request much more complicated as well. Before you
blindly install large “AJAX” libraries, have a go at rolling your own
functionality so you know exactly how it works and you only make it as
complicated as you need. Often you don’t need much more than what I
have shown here.

Expanding this approach a bit to send multiple parameters in the
request, for example, would be really simple. Something like:

function sndReqArg(action,arg) {
http.open('get', 'rpc.php?action='+action+'&arg='+arg);
http.onreadystatechange = handleResponse;
http.send(null);
}

And your handleResponse can easily be expanded to do much more
interesting things than just replacing the contents of a div.

-Rasmus

It was 6

It was 6 in the evening and the Sun was at the horizon. The four years of ecstasy and struggle was over. I was at the gates and nostalgically beamed my thoughts at some sweet reminiscences which seemed to leave a lasting impression on me. There was pervasive silence or perhaps. I wasn’t ready to listen anything. Breeze was gently playing with my hair and it was lovelier than it had ever been. The barren land around the gates some years ago, was then teaming with green grass and the trees, lining the road to the admin building, grew a bit taller in four years.

I kept standing motionlessly. “It’s over now”, voice echoed. Looking everywhere I found nobody. Voice came from inside me and nowhere else... the Sun went down bringing an era of halcyon times to an end.

It is getting dark and I am not sure if I really know the place. There are two streets ahead of me, neither of them have street lights. Probably because the city has been abandoned by its dwellers or may be it has all been done for me. I have a feeling that it has to be the later one. But, who could be it. Is it my manager at office or S, the other guy who is behind A? Meanwhile I am strolling down one of the streets. The silence is more intense than I had ever felt in my life(?). The buildings on both sides seem to have been abandoned by their dwellers. Am I terrified by the frightening combination dark and silence? Is this place a haunted one? I guess the place is too frightening even for the ghosts. My eyes are getting adapted to the level of darkness or may be it’s just a hallucination. I can see a big gate in front of me.

I hesitantly approached the gates splashing the rain water on the street. Opening the gates gave out a frightening creepy sound which broke the noisome silence in the air. My breathing got brisker and deeper. Moon had never been so dreadful and to make things worse, it began drizzling. The road was long leading to a huge majestic mansion. Silvery moonlight on the mansion rendered a ghostly appearance. Slowly but cautiously, I paced up towards the mansion and frequently monitored the shrubs running parallel to the road. Thunders struck and lightening illuminated the skies. Far off, a few bats encircling the chimney protruding from the roof. Perhaps, I thought, life at office with the irritating manager was better.

The old mansion gives me a hope of meeting someone. Doesn’t matter if I hit into a ghost. Somewhere down the line ghosts have lost grounds against me and I no longer fear them as I used to in my childhood days. A ray of light is coming from the creek of the door. I push open the door. There is a lighted candle which seems as if it had been burning there for years. I can’t actually decide about entering the house. The rain outside didn’t bother me much but the disturbance that I may cause to the residents does. I felt a little hesitant but suddenly strong wind from outside pushes me inside the house. The wind also blows away the candle. Was it really wind? Because it’s very rare to find a lonely stream of wind and that too of such incredible strength. Was it someone pushing me? My manager or S? But, the blowing away of the candle suggests that it was wind. This realization relieves me. Now it’s dark again. But, even at such a moment there’s a silver lining (?), I have a roof on my head. I look up to the roof and to my amazement there’s no roof as I can still see the dreadful moon up there. This weakens my earlier reasoning that wind blew away the candle as the culprit could be the rain as well. Manager or S?

Entering the old creaky mansion gave me the creeps that I never ever had felt. Someone was inside the hallow mansion, am I sure of it? I don’t think so, never ever after I crossed the threshold have I been sure of myself. Am I sure that someone is there or is it something? Something that might have been there since time immemorial. How can one ever be sure? One has to cross the threshold, that invisible boundary to go beyond the edge. I here remember the words of one of my favorite programs, “to go where no man has ever gone”. But then again am I sure that no man has ever stepped here in this mansion. The word “hallucination” means that one has the feeling which might be of hearing, smell or sight without any external stimulus. So is it all real, is there any external stimulus or is it my own imagination?

Here I come to a bend beyond which I see a ray of light.




(This is a novel piece of writing. The writers are sharaf, dr manu and amit srivastava. It all started when sharaf sat down and wrote a couple of paragraphs. I bounced upon the story and decided that i'll continue from where he left. Without any discussions with him, i wrote the next paragraph and ruined his story-line. Now it was his turn. The rule of the game was that no one can discuss/clarify/edit what has already been written by others. dr manu came in between and he too enjoyed the game after writing a para of his own)

Labels:

shashi settles down

last wed'day we got a call from shashi bhai. shashi is in jamshedpur to attend the marriages of two of his friends. atleast this is what the world knew. on the marriage day of mayur, shashi finds yet another girl and falls for her, decides to marry her too, talks to her parents (not sure if he talked about all this with girl also). when asked about the 'saamnewaali girls' promplty comes the reply 'AB MAIN SETTLE HO CHUKA HOON'.

Labels:

Rang de Basanti


Saw the movie on last sat'day, the 10pm show at pvr classic. Probably, I was the most ignorant of all the movie-comers about the movie before entering the hall. It was just the aamir's poster where he is riding a horse that i had seen. but when i came out, i knew that it is one of the best movies i have ever seen. a real gem.

the movie is a true aamir's movie. it revolves around five univ students, who probabaly have graduated out 5 yrs back but refuse to go out to the real world. an english woman who has been given the task of making a documentary on indian revolutionaries wants them to work for her movie. They do agree but don't believe in the patriotism thingy. they are hopeless about india, about her corrupt politicians and blah blah blah. according to them it's foolish to give ur life for the country. But as the movie progesses they realise how wrong were they. that no country is perfect and it is upto us to make it perfect.

the best part of the movie is that the message has been conveyed so beautifully that nowhere does it look preachy as was the case with 'swadesh'. The message has never been conveyed explicitly but it comes out automatically.

rakyesh mehra has done a very impressive job and has already raised the bar for other movie-makers right at the start of the year.

To quote rediff.com's review "Is it a patriotic film? Yes and no. Is it a coming of age film? Yes and no. Is it a fun film? Yes and no. Is it a serious film? Yes and no. Does it have a neat ending? Yes and no."

See it again to believe it :)

Labels:

Tuesday, January 24, 2006

lasers/rails

Monday, January 23, 2006

my room: the transition

Before my room: before


After my room: after

Labels:

last week was a bit turbulent. i mean, i again started thinking, thinking what to do. it is at such times that my blog comes to my rescue. i ve already decided about what i've to do. a re-thought is out of scope now.

Labels:

Thursday, January 12, 2006

Confusion


Let's face it, it's not just me in the industry, who doesn't really know what he/she is doing? Most of my friends have good, nice, fat-paying jobs. They are quite happy in worldly terms. But, almost all of the know that this is not the way that they want to lead their life. that this is not what they wished to do. this is not what they dreamt of doing in childhood, the most cherished time of our lives. Some accept this fact, while most are still reluctant to accept the truth.

a few days back shashi, sharaf and me thought of starting a website which will give short-tips to small-investors like who can't really go through all the material that is there on the web.

then today morning as i reach office, i find a personal mail from shashank. no points for guessing he too feels that he also isn't very much excited about his work at his company. wants to somehow enter media thing. or may do something of his own. shashank and me developed a portal for our batch's yearbook at iitk. that was one real sexy piece of software that i was involved in. that is probably the only software that i was really excited about till the end, yes! till the end. now shashank wants to sell it off to various others schools throughout india. we still have to think over it, but it would be a great thing.

Labels:

Google has my blog

As usual i tried searching for my blog on google. Typed 'amitsrivastava.in' and to my amazement my blog was there.

Thursday, January 05, 2006

My New Cam


finally i got my digicam that i ordered through santok while he was in duke. It's a konica minolta dimage z3. Santosh reached bangalore on 25 dec and that was the day when i first had a look of the cam. It looked nice and was much smaller than what i expected. But, before i could get it in my hand the batteries exhausted :(. Also, the stock memory card was a mere 16mb so i decided to get a 1gb sd card and a set of rechargeable cells.
I had heard that u get such items cheaper on SP Road, so decided to get them from there. But since the road is quite far from out place and also since i dont know the exact location of the road, it all started getting delayed and my cam laid unused.
So, after a couple of days, on the way back to home from office, I got into landmark to get those rechargeable cells. Bought a set of four uniross 2000mAh cells for 550 bucks. Reached home and hooked those cells in shashi's (actually tushar's) charger, plugged it in and waited eagerly for it to get charged. Next day after coming from office, the first thing was to put in those cells in my cam and get it working. But, it won't switch on. even after several tries the cam dint start. fuck man! the cells werent working. i tried to check them out on thiyagesh's cam and even that wont start. so, i confirmed that they really weren't working. I was sure for the charger as thiyagesh has been regularly using it for his uniross2000. i decided to throw them at the counter-waala.
Next day, i took them to landmark. Mayank was also with me. the guy at the counter took the cells for testing. And he did really get it working after a charging of just 10 mins.
so, now i knew that somehow the charger was the real culprit and i needed a new charger. therefore, on sun jan 1, we, sharaf and me decided to goto sp road and get everything. After around half an hour of searching on the net, especially on my fav mapmyindia.com about sp road we couldn't find it. But i knew that it's somewhere near the kr market area. so, we set on for that area. after circling thrice near the sp road we finally found it and to our surprise and amazement we could call it a road. majority of the road is 'khet' and it was difficult to even find a trace of tar on that so-called road. but we dared to move ahead on the road. but hey it was sunday and sp road is not supposed to be open on that day. we dint know it, but what we certainly knew was that we can't reach this place again. so i decided to check out national market as well.
so the next search target: national market. i had been there once but it's not enuf for me to be confident about the roads here in bangalore. but surprisingly, i reached there without enquiring even a single person :). ahh.. this one was open. entered the national market and went straight to the first good shop i found. got a sd card for rs 2800 and a set of four sanyo rechargeble cells alongwith a charger for rs 650.
this new charger worked for my both sets of batteries. and my digicam is now in a great mood. will definitely be putting up some pics here. and also a review.

My Birthday Bash


(left to right) Sumit, Sharaf, Eesh, me, Shashi, Thiyagesh

Labels: