Sunday, February 24, 2008

screen

Have you ever wondered, it you could shut down your machine and yet keep the remote sessions as it is. So if you have a process which takes 2-3 days to run and you cannot afford to shut down the machine. What do you try to do... Try to run the process in background. Or you are running a heavy process and after some time (cause you are in india), the net connection just snaps for 2 minutes. And lo your complete process has to happen again.

Well, the most frustrating is the point when your process is 99% over and it breaks along with the session.

"Screen" is something that could help you here. What is screen? Screen is described as a terminal multiplexer using which you can run any number of console based applications. The cool feature of screen is its ability to decouple the terminal emulator from the running programs. This means that you can use screen to keep programs running after you accidentally close the terminal emulator, or even after you log out, and later resume right where you were. It means that the idea of a "session" in which you are running a number of console programs is a free-floating entity that you can bind to any terminal anywhere.

Cool na. Ok, so how do we use it?

All you have got to remember is that the screen remains active until the machine on which it is running is still alive.

So, ssh to the remote machine and type "screen" on your console and you see - no change. You might see a splash page but then it looks like any other empty terminal. In reality, you are now inside a screen process and you can run any heavy process you want.

You can create new windows inside screen by pressing Ctrl+a+c. And then run another process in the window. You can use Ctrl+a+<space> to switch between the running windows inside screen.

So now, you have your processes running and you want to logout and shut down your computer and let the process run on the remote machine. Here is what you do.

Press Ctrl+a+d and you are detached from your screen. So your processes are still running inside the screen and you can logout and shut down your comp and maybe login again from home and check the status of the process. You dont believe me. I knew it...

So just do a Ctrl+a+r, and lo behold, you are back into your screen and you can switch between multiple windows and see the processes running. This should put your mind at rest.

You can get more information from
http://blogamundo.net/code/screen/ and
GNU Screen: an introduction and beginner's tutorial

Tuesday, February 19, 2008

cow

A cow is a completely automated milk-manufacturing machine. It is encased
in untanned leather and mounted on four vertical, movable supports, one at
each corner. The front end of the machine, or input, contains the cutting
and grinding mechanism, utilizing a unique feedback device. Here also are
the headlights, air inlet and exhaust, a bumper and a foghorn.

At the rear, the machine carries the milk-dispensing equipment as
well as a built-in flyswatter and insect repeller. The central portion
houses a hydro- chemical-conversion unit. Briefly, this consists of four
fermentation and storage tanks connected in series by an intricate network
of flexible plumbing. This assembly also contains the central heating plant
complete with automatic temperature controls, pumping station and main
ventilating system. The waste disposal apparatus is located to the rear of
this central section.

Cows are available fully-assembled in an assortment of sizes and
colors. Production output ranges from 2 to 20 tons of milk per year. In
brief, the main external visible features of the cow are: two lookers, two
hookers, four stander-uppers, four hanger-downers, and a swishy-wishy.

Monday, February 18, 2008

lucene search class diagram

Check out the UML diagram for lucene search & scoring i found on the net

Application flow:
1. create query
2. Pass to searcher
3. Searcher creates weight
4. Weight creates scorer
5. Searcher create collector and pass to scorer
6. scorer find matches.
7. scorer calculates scores.
8. Matches are written to collector

Wednesday, February 13, 2008

Comparing delhi to baroda

As soon as you step down from the train in vadodara, you find that the station is comparatively neat and clean. And there are lesser people on the station.

Step out from the station and you find an auto charging you only 25/- rs to take you home. Well, you think, in delhi, the autowala wont even look at me if i say 25/- rs to him.

The distance from station to home is almost traffic free - even during the peak hours. In fact, no one has heard of even a 10 minute traffic jam. There are no traffic jams. Wow you say. You roam around and you find that reaching any place in baroda is not a big job. Nothing is too far off. If you travel for an hour you can cover almost the whole of baroda. You save all the travel time. Going to nearby grocery store is 5 min job. Going to the nearby mall is 10 min job and going to the nearby movie hall is 15 min job and going to the nearby maruti service station is a 2 minute job. Your gym is nearby. And you also have a big swimming pool 5 minutes away. Much cleaner than those in delhi.

So what you would say. Delhi has big malls and reliance fresh, pvr. What? Havnt you heard about the pvr and inox in baroda. Or adlabs. They are all here. There are huge shopping malls here too. And you have the street market too which is damn cheap. In fact you would be shocked to see that the shopping malls in baroda provide such discounts that the price comes down to that of the street markets of delhi. Cool and most of the products are branded.

So, you save on your travelling time. The people are friendly - cause they have time. You get up at 8:30 and leave for office at 9:30 And you are in office by 9:45. There is no rush. For the price of a 2 bed room flat in remote location in delhi, you would get a 4 bedroom tennament with private lawn and parking in the best locality in baroda.

You leave office at 6:15 and are home by max 6:30. You have time to talk to your friends and relatives. You make social visits. If you fill up 1000/- worth of petrol in your car and use your car daily, your petrol would last for the whole of the month. Wow - great savings on petrol. There is traffic police in almost all the places. And if you talk to them, you would find that they are friendlier and a lot less corrupt. They would give you a receipt for a fine you pay. And they do not demand a bribe.

Then why am i in delhi? Cause i get paid well there. Well, maybe i could move to baroda if i get paid half of what i am getting paid in delhi.

Indian railways improved??

Well, today i am going to baroda. The train is at 7:30. I called for a cab. The distance from home to station is around 20-30 min.

The trick here is how do you decide at what time you should call the cab so that the cab drops you at the station on the right time - neither too late nor too early. So, what you do is take a buffer of 30 minutes for boarding the train and give the cab a buffer of 30 minutes. So in my case, i took the target to reach station at 07:00 (30 min buffer at my side). And called the cab at 06:00. Bingo, so now as per IST(Indian Stretchable Timings), the cab would turn up at 06:30 and drop you at station at 07:00. The problem here is that the cab does not give a damn whether you catch the train or not. So at 05:55, buzzed the cab driver and ask him when he is going to arrive. Basically, you are acting as a wake-up call for the cab driver. He is not supposed to catch the train, you are, so it is your responsibility to wake him up and remind him of his duties and ensure that he arrives on time to pick you up. Just hope that the cab driver is not some person who does 2-3 snoozes to his alarm before waking up. So buzzed him again in 10 min to ensure that he is up and in his cab and driving. Also it is necessary to control your anger in such situations, else you may burst everything up.

So the cab comes at 06:35. The driver is aware that he is late, and since you have told him that you need to be at station at 07:00 to catch the train at 07:10 (just make up some time and have at least 15 min buffer), he will surely break all speed limits to achieve his aim of dropping you at station at the right time. So strap your seat belts and put your life in the driver's hands and wait. I think, more accidents & traffic jams happen due to the fact that people dont take into account the time that would be required in travel. For them, if they are late in getting up, they would try to make up for the lost time during driving. So over speeding and driving in the wrong lanes - results in either accidents or traffic jams.

Well, so i am again at the famous Indian Railways Station. Its crowded with autos. My cab is stuck behind the autos and unable to move ahead. Why is there so much jam here? Oh, people have parked their cars on both sides of the road leaving only a small path for a single car to move ahead. And the autos are trying to move back looking at the jam ahead. So traffic is crawling and there is a jam.

To talk about jams, i remember a jam where i was at the heart of the jam. I was stuck in the jam for around 1 hour. It happened just near a crossroad with bright red lights and the traffic police trying to control the traffic. Cars on either side of the red light covered both the to and fro lanes. Cars which were going to come towards us had no where to go cause the way was jammed up with cars moving in the other direction. And we had no where to go cause the road ahead was blocked with cars facing me. And to add to it, the bus drivers and cab drivers try to squeeze out of whatever place is available. Making the jam more jammed.

Sorry, i wandered. well, so i am at the station finally, totally crowded. No place to move. Its dirty as always. The enquiry counter has a huge queue. If i get in the queue, i will surely miss my train - by the time my turn comes. Why do they have a single enquiry counter and a very arrogant person at the other side. Maybe that is the bussiness model to reduce requests - poor UI. The only good thing is that this time the train is on time (i am lucky).

So after being on the station for 10 minutes, the train is here. All the doors are locked. People are standing and waiting so that someone opens the doors. Some guy with no uniform opens the doors and people start rushing inside. Again there is a jam, if you stand aside and give way to someone, you will have to stand aside till the complete batch of people have crossed. Cause no one is going to give way to you.

The caterer comes for orders of breakfast. Options - the same as always - omlette or cutlate. I dont think, indian railways has chefs. I order an omlette. The order is delivered after an hour and the omlette tastes burned.

Yes, there has been some improvement, check out the new power-plugs at all places in the train. Cool... So now i can plug in my lappy and maybe do some productive work or play some games.

So this time, we saw some movies and i sat on my lappy throughout the train. Though there was a problem with the electricity. As soon as i put my lappy on charge, the mouse used to move around automatically. But anyways, linux and windowmaker are good. You dont need mouse to move, everything is possible using the keyboard.

And yes another improvement in the indian railways, the variety of junk food. Last time when i was travelling they were selling burgers and pizzas. I did not dare to try one. And everytime they sell samosas and everytime i try these samosas. I dont remember them being good even a single time. I dont know why i try them, when i am aware that they would be terrible. And the ketchup they give with the samosas are so thin that it seems they have converted a single bottle of ketchup into atleast 15 bottles and added sugar to it. This time they were selling chinese noodles. It was ok - just too much oily. I did not dare to try the onion pakodas or potato vadas.

Now i am waiting. The train is supposed to reach vadodara at 22:00. I hope it is on time, though the train has been making a lot of unscheduled stops.

We are on time. In-fact 5 minutes before time... That is an achievement...

Sunday, February 10, 2008

Silence

Have you ever heard silence? The statement does sound absurd, but, just for a moment, pause and think again. Have you ever heard silence? Any moment in your life when you were actually aware that there is no sound. No sound of wind, or of traffic. No dogs barking. No one sneezing or coughing. No one breathing. Nothing. Just dead silence.

It might sound scary. But believe me, few weeks ago, i had the opportunity of experiencing this moment. I drove back from a wedding. Parked my car. Turned off all the lights. Put on the hand brake and just sat for a moment to take a deep breath. And i suddenly became aware of the silence around. I held my breath for a moment and closed my eyes. Believe me, it was heaven. Nothing to hear.

It is a feeling that cannot be explained. It felt like a huge void. Physical emptiness beyond imagination. I felt so light, so completely lost in the void.

Our lives are so busy. We start our day with the alarm clock screaming. And then the sound of brushing our teeth. The sound of water while bathing. The sound of footsteps. The sound of vehicles while driving. The sound of people talking. The tap-tap of keys on your computer while working. The sound of vehicles while driving back. And the sound of eating food. The sound of bed sheet while you cover yourself during sleep. And finally the sound of breathing and rustling till you doze off.

It reminds me of my college days, when i used to be up till 3 in the morning studying. And before going to sleep, i would go to the balcony and stare into the black night. But i would hear the wind then and ofcourse the night watchman moving around.

Maybe, we should be having earlids in addition to eyelids. But maybe then, we might not realize or value the peace that "complete silence" gives.

Thursday, February 07, 2008

games

Remember the days when you used to play mario on your pc or pacman? You used to love it. Or maybe Quake, warcraft? What was the first game you ever played or which game did you like the most...

Well, i used to love playing quake-II, when i was in college. I could not afford a 3D graphics card and had a Pentium 166Mhz cpu with MMX technology. Quake-II used to run fine on it. So, i used to love it.

Recently, i got a XBOX-360. And i could see that games have moved a lot ahead of where it was then. It is not all about shooting or about role playing.

The first game i played on it was Halo-3. Supposed to be the top game on www.gamespot.com. And it was good. It was mostly about shooting - missions and how to accomplish them. The story was good and i did feel a part of the story. The main thing was that it made me feel different. The visuals were amazing.

Gaming has evolved to the next level. Where you have a character, you make decisions which affect your gameplay. You have power. And gaming online has its own benefits. You can form a group and pursue the same target, or fight against each other.

Recently, i got Mass Effect, another cool game. Where you talk to people, discover their secrets. You can be rude if you want to be or passionate. People smile and react to your actions. The decisions you make changes the path of the game.

Another game, for which i am looking forward is Bioshock. People who have played it say that they felt scared and confused. It is supposed to be the best game in terms of story line, music and weapons.

And ofcourse, racing games like burnout paradise make you put all your daily traffic frustrations in the game and calm down. You can run over people, bang cars and blow cars.

It is just that the games currently are very expensive. It should get more and more cheaper...

Saturday, February 02, 2008

mysql stored procedures & dynamic tables

So you write mysql stored procedures.
Oh, and you have tables t1, t2 ... tn having almost the same structure and you wish to perform the same queries on all the tables.
So how do you go about it ?
Mysql does not allow you to change the table names dynamically.

So if you want to add index on field "F1" in all tables, then you cannot make the following piece of code working


my_loop: LOOP
select concat('t',table_no) into tablename;
alter table tablename add index idx_f1(`F1`);
set table_no = table_no+1;
if table_no>3 then
leave my_loop;
end if;
end loop my_loop;


Na-Na, the code wont work. cause you cannot have a dynamic variable for table name or field name in the sql query inside a stored procedure.

Then...

Just copy paste the following code...


my_loop: LOOP
select concat('t',table_no) into tablename;
set @sql = concat("alter table ",tablename," add index idx_f1(`F1`)");
prepare stmt from @sql;
execute stmt;
set table_no = table_no+1;
if table_no>3 then
leave my_loop;
end if;
end loop my_loop;


And bingo, the code works.
So what have we done here? We have created a sql query by concatenating different strings and variables and prepared a sql statement out of it.
And then we are executing the query.

Monday, January 14, 2008

Auli

Another dream comes true...
I dreamed that one day i would wake up and open the window and see the whole world covered in snow. And lo, it just came true...

Yes, i am talking about auli.

Auli is around 500-550 kms from New delhi. The way is from delhi to rishikesh via NH58, and from there to rudraprayag and to joshimath and from there to Auli. The way from delhi to rishikesh is around 200 kms and is plains - and the way ahead of rishikesh is all mountains.

We were 5 people in an innova and the driver was good at driving in hills. so we took around 12-14 hours for the drive. We started around 10 in the night on friday after diner. Actually we wanted to start early around 6, but we got the information that at 8 pm, the road ahead of rishikesh is closed and it is opened at around 5 am. Since the way from here to rishikesh is around 5-6 hours, we decided to start late and reach the road block at rishikesh at around 4 am. We had a halt at devprayag, half way from delhi to joshimath. But it was not required. Well, joshimath is a good place - small town with beautiful rivers flowing. It is the point of origin of The Ganga. Two rivers alaknanda and bhagirathi meet there and The Ganga is born. A very small town in the valley.

From devprayag around 2 hrs ahead is shrinagar a beautiful valley between all the hills. And before shrinagar is a very nice hotel to stay in - riverside. It is around 1 km from devprayag. We spent some time over there and moved ahead. By 7 in the evening, we reached joshimath the road from rudraprayag to joshimath is very bad - terrible seems a better word.



We spent the night in joshimath. And next morning we went to auli via cable car. The first cable car goes as early as 9:30 am. And if you miss it, you will have to wait untill there are atleast 15 person to travel in the cable car. Well, we missed the cable car and had to wait. You could hire gum boots from the same place at 50Rs/day.

The ride in the cable car was terrible. It was very crowded. I had the notion that since the requirement is minimum 15 people, it would be big, but it is a tiny place and if you have luggage - be prepared for some shoving and scolding. The cable car charges 400/- per person for to and fro. You can also take the road and it would be a better option if it is not snowing.



If you are travelling in cable-car, you would need to get down at tower no 8. And from there, you can either trek down or catch the chair car to gmvnl guest house. There are only 2 places to stay in auli, the gmvnl and the clifftop hotel. Clifftop is costly and the service is not that great. gmvnl is very good. Cheap and affordable. A ride in chair car is 200/- per person to and fro.



Clifftop hotel is very near to the tower no 8 of cable car. GMVNL has ski courses which is a 7 day course. And people from over the world come over here to learn to ski. Food was great. Avoid non-veg. They take too much time to cook non-veg and it is not that great - just ok. We used to be terribly hungry - maybe due to the cold and we used to eat a lot.

The cottages at gmvnl are either huts of deluxe cottages. Huts are very small and do not have central heating. Whereas the deluxe cottages are too good with central heating and all.

The good thing that happened is that it was snowing heavily when we reached Auli. For the first time in my life we saw snow.

All we did over there was play in the snow. It became terribly cold in the night. Even after central heating it was 7-8 degrees inside the room. Outside the temperature must have been -5 degrees or so.



Next morning was bright and clear. We enjoyed the sun and the snow and the clear skies. The people over there would try to make you ski - telling you that it is easy and you would learn in an hour. But dont fall for that. They would charge 200-300 rs/day for the ski and equipment. And you would say - thats great for 300 i can ski for the whole day.

But it is not possible to learn to ski in just 2-3 hours. You would need atleast 2 day practice to start skiing. And the ski equipment is very heavy. You would get tired in 1 hour max.

Return was ok. We felt we should have stayed for a day more. The driver drove at 60-70 kmph on the mountains and we were back in delhi at 2:30 in the morning.

Check out the pics at http://picasaweb.google.com/jayant7k/AuliJan08

Wednesday, January 02, 2008

play movies on xbox 360

So, you have got a Xbox 360. And you are tired of playing games on it. You would also like to use it as a Video and Audio player. Hmmm... Audio player is cool. Just plug in a USB pen drive with your favourite songs and playlist and play them out...

But what about video. Every Time you want to play a video, you have to "rent/buy/borrow" a DVD and play it. Do you have movies (DIVX/Avi) on your laptop and you wish you could play those movies on the XBox and enjoy the movie on your home theater.

Here is the ultimate solution.

The recipe requires you to have a linux (i am using ubuntu here. But you can use any flavour of linux) loaded pc with a net connection. A USB mass storage drive (pen drive or hdd). And an Xbox 360 - ofcourse.

The commands here are for ubuntu gusty. If you are not using ubuntu, then you will have to get the source and compile the files for yourself.

The magic software over here, which does our work is ffmpeg.

So what do you do???

  • download ffmpeg.
    svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

  • Get the required libraries
    sudo apt-get install libfaad2-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libdts-dev liblame-dev lame
    In case you are running something other than ubuntu, then please google for the libraries and install them from source.

  • compile
    cd ffmpeg
    ./configure --enable-gpl --enable-pp --enable-libvorbis --enable-liba52 --disable-debug --enable-libmp3lame --enable-libfaad --enable-libfaac --enable-libxvid
    make
    sudo make install

  • choose the movie you want to convert into Xbox - playable format
    cd I.Am.Legend

  • convert the movie to wmv format
    ffmpeg -i I.Am.Legend.XviD.avi -vcodec wmv1 -acodec wmav2 IAmLegend.wmv
    This will take some time

  • Copy the movie into the USB device

  • Plug the USB drive into your Xbox 360.

  • Play the movie and enjoy



But, you would say, the picture quality is not that good. What happened to the picture quality and the sound. It was better on the lappy.

check out this information:

jayant@jayantbox:~/movies/I.Am.Legend$ ffmpeg -i I.Am.Legend.DVDSCR.XviD-THS.avi -vcodec wmv1 -acodec wmav2 IAmLegend_bad.wmv
FFmpeg version SVN-r11364, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-pp --enable-libvorbis --enable-liba52 --disable-debug --enable-libmp3lame --enable-libfaad --enable-libfaac --enable-libxvid
libavutil version: 49.6.0
libavcodec version: 51.49.0
libavformat version: 52.3.0
built on Jan 1 2008 22:13:58, gcc: 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)

Seems stream 0 codec frame rate differs from container frame rate: 23.98 (65535/2733) -> 23.98 (24000/1001)
Input #0, avi, from 'I.Am.Legend.DVDSCR.XviD-THS.avi':
Duration: 01:41:23.5, start: 0.000000, bitrate: 966 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 640x272 [PAR 1:1 DAR 40:17], 23.98 tb(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s
Output #0, asf, to 'IAmLegend_bad.wmv':
Stream #0.0: Video: wmv1, yuv420p, 640x272 [PAR 1:1 DAR 40:17], q=2-31, 200 kb/s, 23.98 tb(c)
Stream #0.1: Audio: wmav2, 48000 Hz, stereo, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 3473 fps=274 q=10.0 Lsize= 5014kB time=144.9 bitrate= 283.6kbits/s


Here, you could see that the audio and video bitrate has been reduced from 128kb/s to 64kb/s and 966 kb/s to 283.6kb/s respectively.

To get the same quality, all you have got to do is match the output bitrate with the input bitrate. So when we convert the movie from avi/divx to wmv, we need to pass arguments so that the bitrate for audio and video remain the same. So lets do that.

ffmpeg -i I.Am.Legend.XviD.avi -vcodec wmv1 -acodec wmav2 -b 989184 -ab 131072 IAmLegend_gud.wmv

Remember: the bitrate is put here in bytes so 989184b/s = 989184/1024 = 966kb/s. And 131072 b/s = 131072/1024 = 128kb/s.

To identify the source bitrates, just do:

jayant@jayantbox:~/movies/I.Am.Legend$ ffmpeg -i I.Am.Legend.DVDSCR.XviD-THS.avi
FFmpeg version SVN-r11364, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-pp --enable-libvorbis --enable-liba52 --disable-debug --enable-libmp3lame --enable-libfaad --enable-libfaac --enable-libxvid
libavutil version: 49.6.0
libavcodec version: 51.49.0
libavformat version: 52.3.0
built on Jan 1 2008 22:13:58, gcc: 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)

Seems stream 0 codec frame rate differs from container frame rate: 23.98 (65535/2733) -> 23.98 (24000/1001)
Input #0, avi, from 'I.Am.Legend.DVDSCR.XviD-THS.avi':
Duration: 01:41:23.5, start: 0.000000, bitrate: 966 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 640x272 [PAR 1:1 DAR 40:17], 23.98 tb(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s
Must supply at least one output file


So, now relax. No need to go to the nearby DVD rental shop. No need to purchase DVDs. If you have got a good quality movie on your computer, you can play the movie on your large screen TV and home theater and enjoy...