Wednesday, April 6, 2011

Anti-Indian-Cricket, not Anti-Indian

The word is moving around that I am an "Anti-Indian". This blog post is to clear my stance that I am an "Anti-Indian-Cricket"er, not an Anti-Indian. I would love to see a developed India which is the dream work place for people around the world. I would love to see an India which does not fund institutions just to create professionals for US, an India which does the best research in whatever field rather than simply buying stuff from outside, where you don't see cash given to vote being brought to the parliament, where the government doesn't play vote politics in the name of religion ...

Now back to the point, cricket. I have a lot of reasons why I hate cricket, particularly the way it is supported in India.
1. Prizes : Do these people really need them?
Most state governments have paid around Rs 1 crore to the players of that state. Are these government really so rich that they can afford to pay that much to these people who will already be among the richest in the state? Don't we have a long list of schemes which can't be properly implemented because of lack of funds? Many have been provided large villas around the country. Are these really the homeless people who need to be provided with a place to live?? The railway has announced free lifetime passes in the best class anywhere around the country for all the team members. I don't think any of these players are going to prefer rail over air, but can't the railway find better ways to spend their money?

OK... they became the world champions. How much support does the national game, hockey team get? How much felicitation do the Asian games/olympics medallists get? Wait, does India have a soccer team?? Aren't these sports?

2. Tax free income/tax waiver
Does the government have enough that it can say that it doesn't want more? The main idea behind taxes is to provide amenities to the general public by taking money from the rich. Looks like the Indian government doesn't know about it.

The ICC got a Rs 45 crore tax waiver to conduct the world cup. Really? Do you really think that the world cup is an event which needs a tax waiver??

3. Duration of the game
An ODI game goes on for atleast around 7 hours. A football match + a hockey match + a tennis match + a basket ball match together may not take that much!! This means that watching a cricket match will make sure that you don't do any work for almost half the day. Multiply that by the millions who watch the game!!

4. Advertisements
Suppose in a football match, Messi dribbles through 4 defenders and scores a spectacular shot. You get so excited that you want to see it again and again. If you are watching the match live, you can see it from various angles for atleast 4-5 times.

On the other hand, suppose someone takes a huge wicket in cricket with a spectacular diving catch. You see the players celebrating for a moment, the umpire lifts his hand and then ... ads! You see Shah Rukh Khan asking the match score, you see Katrina Kaif drinking some mango juice, you see Dhoni and his helicopter shot (which by the way would've looked really stupid had Dhoni not scored in the final)... hey! Wasn't there some brilliant cricket there? I want to see that again. Oh no, thanks, we have better things to show you, if you want to see that, then come back after 2 minutes!

If you watch 7 hours of cricket, I am sure you will watch more advertisements than the actual game itself, especially if you consider the idle time between balls. On the other hand, if you watch 1.5 hours of football, you actually see 1.5 hours of football completely. I think at the end of they day, whether you watch say 4-5 hours of cricket and a complete match of football, you finally end up watching the same amount of actual play.

Saturday, October 9, 2010

Valgrind for dummies to experts

Well... not really for experts; experts will know better than me.

Valgrind is a framework for dynamic analysis tools. As far as we are concerned, it is something that helps us remove those nasty segmentation faults and unnoticeable bugs.

If you believe that there is some wrong array indexing somewhere but can't find out where, then valgrind is the perfect tool for you.

The use of valgrind is simple.

1. Compile your code with the -g flag.
gcc abc.c -g -Wall
g++ abc.cpp -g -Wall

2. Run with valgrind
valgrind ./a.out
valgrind ./a.out <input

That's it.

Now what you need to know is how to understand the output.
The first few(around 5) lines are not interesting to us.

After that you will see the output of your code and the list of errors.
Most of the time, you should be looking for these lines :
1. Invalid write/read of size 4
It mostly means that you are accessing array index beyond the size of the array.

2. Conditional jump or move depends on uninitialised value(s)
It means you are having something like this :
int a;
if( a > 5 ) { // do stuff

You have not given any value to a.
If you try to print some uninitialized value, you will get this error message 4-5 times. You can identify it by seeing that there is a "printf" in each of these.

The most important part is the line just after the above messages. It looks something like this :

==8050== Invalid write of size 4
==8050== at 0x804841A: fun (val.c:5)
==8050== by 0x804844A: main (val.c:15)

It means that the error was at line 5 in the file abc.c, inside the function fun(), which was in turn called by main at line 15.

Valgrind is not perfect in finding array index overflows, especially when it comes to static arrays. Sometimes, running it with the following option may give better results :

valgrind ./a.out --tool=exp-ptrcheck

Wednesday, September 1, 2010

Some copying tips

So we all know how assignments are done. One guy faithfully does the whole thing and the rest copy it and change sentences of the form "Let X be a subset of Y" to "Let Y be a superset of X", etc. Now, very often, you will have to make the same kind of changes several times. Here are some tips on how you can do it efficiently using vim.

We'll deal with 2 examples, each of which use many useful commands.


Suppose I want to change (A) to (B)
printf("%s is a X\n");
printf("%s is a Y\n");
printf("%s is a Z\n");

printf("X : %s\n");
printf("Y : %s\n");
printf("Z : %s\n");

What we will do here is to make the changes in the first line and store it in something called a macro. Once you are done, just execute the macro in the other lines.

Steps :
Start in escape mode. You should be at the beginning of the first line when you start.
1. qa : q starts recording the macro. It takes an argument which is the register in which you have to store it. Here we're using 'a'. You can use any letter as the macro.
2. f% : f searches for a character in the same line, starting from the current position. Here we search for '%' to go to that position.
3. d4w : d stands for delete, w for word. Delete 4 words.
4. f\ : Move to the position \. (We want to start editing there).
5. Go to insert mode and start typing normally (add the " : %s"). The recording is still going on.
6. j0 : Move to the next line. 0 moves to the beginning of the line (we want this so that the search for % the next time works properly.)
7. q : Stop recording.

Now your macro is ready in the register a.
8. 2@a : Execute the macro 2 times.

There you go, (A) is changed to (B). Of course, this will be feasible only if you have a large number of lines to do this. The individual commands should be useful even otherwise.


Suppose you are editing an html file where you want to give a drop down box of 30 values as follows.

<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>

and so on until 30.

Steps :
Start in escape mode. Type the first line normally. You should be at the beginning of the first line when you start.
1. qa : start
2. yy : copy the entire line
3. p : paste the line
4. f" : move to "
5. l : move left once.
6. Ctrl-A : This increases the number under the cursor by 1.
7. f : move to the next space.
8. Ctrl-A
9. q

Now 28@a should fill everything upto 30.

Wednesday, August 25, 2010

Youtube downloader for linux

There are many softwares/sites out there that can download videos from youtube and other similar sites. However, here is a much simpler trick which works on most linux distributions.

Whenever you play a video on youtube, the flash file is stored in /tmp as something like Flashxxx.

So if you want to save some video, simply watch the whole video on youtube and do " ls /tmp/Fla* "
The most recent video will most probably be the video you want.

Tuesday, February 23, 2010

vim tips :wq

Note: The time taken in reading this post will be compensated if you practice it properly :)

Most of my friends use Vim as a text editor. However, I find it strange that even after using it for a year, they still use it like notepad! So if they want to delete the second half of line 23, they press 'i', press the down arrow key till it reaches line 23, press the right arrow key till they reach the half point, and then finally press the delete key till the whole line is deleted. One of my friends stopped using vim because he couldn't use his mouse!!

I wont blame them. The vimtutor is an interesting place to start learning vim. But beyond that, the next place that can help you learn further would be some large reference book. So this series of blog posts are intended to slowly get you started with vim.

Let's start with the basics.

1. dd - Delete the whole line.
Similarly, cc deletes the whole line and changes to insert mode. It's d for delete and c for change.

2. D - Delete the rest of the line (starting from the current position). C does the same, and puts you to insert mode.

3. dw - Delete word. cw is similar.

4. % - Move to the matching bracket of the bracket at the current position. d% will delete from the current bracket till it's matching bracket.

5. f - Find. So if you type fr, it will go to the next occurence of r in the current line. If the letter doesn't occur in the current line, nothing happens. F (capital f) will do the same, but find the previous occurence of the letter in the current line. f and F are most useful when you use it along with d. For example, if you want to delete till the next r in the line (including the r), all you have to do is "dfr"!! t and T also work in the same way except that dtr will delete till the r, but not the r. Using c instead of d will do the same, and also put you into insert mode.

6. . (dot) - Repeat the last editing command.

7. u - Undo

So next time you want to change

draw_dog(int tail) to draw_human(int brain), just go to the first d, type fdc%human.... .

More to come soon.

Tuesday, January 26, 2010

Hello World

Hello, World!\n

There have been times when I came across something interesting and wanted to record somewhere. And that's how this blog was born...

My main interests are algorithms and C++. I like learning about the latest technology, though I don't use any kind of fancy gadget.

I own a Fujitsu ESPRIMO v6545 laptop and use openSUSE 11.2 (No windows even through dual boot). That should be enough to show that I don't follow others blindly.

You can expect some interesting vim tricks here.