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.