Random Thoughts

September 1, 2008

Freedom Writers

Filed under: General — indhubharathi @ 11:39 pm
Tags: , , ,

I maintain two blogs. One (this) to put in serious thoughts. Another to put in not-so-serious thoughts. I never thought I’ll be writing about a movie I saw tonight in this blog!

The movie was “Freedom Writers” (based on true story). I don’t even have a count of how many times tears rolled down my eyes as I watched the movie.

The movie is about a teacher. Not just a teacher. Someone who changed a classroom filled with violence, hatred and bloodshed into a class of lovable kids who came up with flying colors.

I don’t know what to appreciate. The care she had for her children? The passion she had towards teaching? The passion that drove her to even “takeup an extra job to pay for a job”?

It is wonderful to see how love can change anything. When you really care for the kids, why wouldn’t the kids recognize it? How many can really care the way she did? Work in a garment shop to raise money to buy books for the kids…. Revolutionize teaching to fit to her audience…. Place teaching even above her own personal life…

This is one dialogue for the movie which I really loved:

Kid: I’ve never had a hero before. But you are my hero.

Miep Gies: Oh, no. No, no, young man, no. I am not a hero. No. I did what I had to do, because it was the right thing to do. That is all. You know, we are all ordinary people. But even an ordinary secretary or a housewife or a teenager can, within their own small ways, turn on a small light in a dark room.

It is true. It is not the great politicians or the great businessmen who bring about great changes in society. It is just the ordinary people… could be a teacher… could be a software engineer from an xyz company… could be a vegetable vendor… anyone… anyone who wants to turn on a small light in a dark room.

I know, this blog doesn’t convey much. I’m not a great writer to make you feel what I felt watching the movie (I wish I was). I’m just trying to say “Here is a great movie and spare some time when you are free.”

:-)

P.S: To be a teacher has always been my dream. I feel, to really bring about changes in a society, you have to be a teacher. I wish I do one day! And that remind me of another dialog in the movie - “And I remember when I was watching the LA riots on TV, I was thinking of going to law school at the time. And I thought, ‘God, by the time you’re defending a kid in a courtroom, the battle’s already lost.’ I think the real fighting should happen here in the classroom.”

August 17, 2008

Listing all removable drives in Linux

It was required in a project I’m currently working on to list all removable drives (like floppy, cd rom, thumb drive etc) in Linux. Quick Googling didn’t help. It took a long time for me to evaluate various alternatives that were available (like parsing ‘df’, doing ls -l on device, using /proc/partitions, using dmesg, etc) and come up with a solution. I’m posting the solution here so that it might be useful for others.
What I wrote is a shell script that uses the HAL device database.

-bash-3.2$ cat ls_removable_storages1.sh
storages=`hal-find-by-capability --capability "storage"`
for storage in $storages; do
  isRemovable=`hal-get-property --udi ${storage} --key storage.removable`
  if [ $isRemovable = "true" ]; then
    product=`hal-get-property --udi ${storage} --key info.product`
    type=`hal-get-property --udi ${storage} --key storage.drive_type`
    device=`hal-get-property --udi ${storage} --key block.device`
    mount_dir=`cat /etc/mtab | grep ${device} | cut -d" " -f2`
    echo Product: ${product}
    echo Type: ${type}
    echo Mount Directory: ${mount_dir}
    echo
  fi
done

Hope the code is pretty self explanatory. Look at the following commands in Linux for more details:
1. lshal 2. hal-get-property 3. hal-find-by-property 4. hal-find-by-capability

This is the output of the script in my system:
-bash-3.2$ ./ls_removable_storages.sh
Product: iPod
Type: disk
Mount Directory: /media/ADMINISTRAT

Product: VMware IDE CDR10
Type: cdrom
Mount Directory: /media/Kubuntu408.04.140amd64

Product: PC Floppy Drive
Type: floppy
Mount Directory: /media/disk

:-)

July 13, 2008

Generate Combinations

Filed under: maths, programming — indhubharathi @ 2:25 pm
Tags: , , ,

While writing programs we frequently want to get all combinations of a set. It su@%s to code it every time we want it. Won’t it be good to a have a Class ‘CombinationGenerator’? And do operations like this:

CombinationGenerator cg = new CombinationGenerator(collection, 3);
/* where collection is something that implements ‘Collection’ and k – size of each combination */
while(cg.hasNext) {

process(cg.next());
}

This exactly is what the following class does:


import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

public class CombinationGenerator implements Iterator{

	Vector<Object> 	list 		= new Vector<Object>();
	Collection 		collection;
	Vector<Object> 	curComb;
	Vector<Integer> nextComb;
	int 			N, R;
	boolean 		hasNext;

	public CombinationGenerator(Collection argCollection, int argR) {
		this.collection = argCollection;
		this.R 			= argR;
		this.N 			= this.collection.size();
		this.hasNext 	= true;

		if(argCollection.size()<argR) throw new IllegalArgumentException();

		curComb 	= new Vector<Object>();
		nextComb 	= new Vector<Integer>();

		for(int i=0; i<R; i++)
			nextComb.add(i);

		for(Object obj : collection)
			list.add(obj);
	}

	public Object next() {
		fillComb();

		int i;
		int l = nextComb.size();

		for(i = l-1; i>=0; i--) {
			int el = nextComb.elementAt(i);
			if( el!=N-1 && ( i==l-1 || el+1!=nextComb.elementAt(i+1) ) ) {
				nextComb.set(i, el+1);
				break;
			}
		}

		if(i==-1) {
			hasNext=false;
		} else {
			for(int j=i+1; j<l; j++) {
				nextComb.set(j, nextComb.elementAt(j-1)+1);
			}
		}

		return curComb;
	}

	public boolean hasNext() {
		return this.hasNext;
	}

	private void fillComb() {
		curComb = new Vector<Object>();
		for(int i: nextComb) {
			curComb.add(list.elementAt(i));
		}
	}

	public void remove() {
		throw new UnsupportedOperationException();
	}
}

Here is a quick example on how to use it:


Vector<Integer> vect = new Vector<Integer> ();
for(int i=1; i<=3; i++) {
    vect.add(i);
}

CombinationGenerator cg = new CombinationGenerator(vect, 2);

while(cg.hasNext) {
    System.out.println(cg.next());
}

Output:

[1, 2]
[1, 3]
[2, 3]

:-)

July 4, 2008

Two interesting questions…

Filed under: maths — indhubharathi @ 9:20 pm
Tags: , , ,

For no great reasons these questions popped out of my mind…

1. Take two distinct numbers A,B. Let their gcd be G. Now let me make a statement – “Any number N that is less than G and divides both A and B must divide G also”. Can this statement be proved? Or is there any counter example?

2. Consider two numbers A and B. A is given to be a non-prime. Now will selecting B to be a prime decrease the number of common multiples for A and B?

Cheers

June 29, 2008

Why Programming Contests?

Filed under: programming — indhubharathi @ 8:20 pm
Tags: , ,

I love solving Topcoder problems. It always thrills me. The feeling it gives it like going on a roller-coaster ride.

But when I speak to people about programming contests, the most common response I get is “When I have real job to do, why should I solve unreal problems?” This post answers this question.

When we can face the big problems, the ‘real’ problems become trivial:

When we constantly keep solving problems that require complicated recursion or multi-dimensional dynamic programming or memoization or some graph theory to crack it, the regular real world problems that hardly require more than two levels of nested loop becomes trivial to solve. Real day-to-day problems won’t be problem anymore and they will turn out to be cake-walks!

Turning real world problems to cake-walk has lot of advantages. This gives more time to think on more important stuffs like “Can this problem be solved automatically? Can I write a tool that will help this kind of problems in future? What is the real problem faced my the user and can that be solved in a better way? Can we propose any feature enhancement? Etc…”

If I rest I rust:

This is one hard fact everyone has to digest. Thinking power doesn’t decrease as we grow old. But we grow old (mentally) because we stop thinking. I’m sure the last time more than 80% of people would have strained their grey cells would have been when they prepared for a college examination or to crack an interview. Once we enter a job we get into a comfort zone and stop using the grey cells.

Nature of job can also be blamed for this. Unfortunately not all jobs require people to think hard. There is ‘process’ to break the entire work into tiny parts and individual employee needs to take care of only a very small part of a big process. With time they become so familiar with their part in the process that they can do the work without much thinking. This explains why we see freshers performing better in aptitude/programming interviews compared to experienced people. What people unfortunately don’t understand is “The lesser I think, the more rusted my brain becomes!”

Programming contests like Topcoder gives us a chance to use the grey cells and keep it conditioned so that it doesn’t rust.

Confidence can go a long way:

Much has been written about confidence by many people. Having self-confidence can make us perform above our normal limit. At the same time, lacking confidence will make us perform worse than what we actually can. And acquiring self-confidence is not very easy. I’ve heard people say “Think you can; you can”. But the first part of the sentence is not easy to achieve. It is just not just ‘thinking’. It is instead making my brain believe that I can. And brain needs solid proof to believe anything. Cracking tough algorithmic problems will help you prove to yourself that you can!

Speaking out of my own personal experience, if I start my day solving a Topcoder 500 pointer, I can be sure I have a great day ahead. It gives a kind of confidence that is hard to explain with just words!

Creating better engineers:

I think of this quite often. Why is Indian IT industry not as good as the American IT industry? Why don’t we have techie companies like Google, Microsoft, Sun, IBM etc in India. Why don’t we see ambitious startups like ‘Facebook’ growing from India? Why is none of my text books written by Indian authors? What is wrong here?

The answer is pretty easy. To get the answer, we just have to compare an average Google employee and an average Infosys employee. The differentiating factor is nothing but ‘ALGORITHMS’. Google interviews tests nothing but candidate’s algorithmic skills. Technology doesn’t matter. Somebody who is good in algorithms will be able to learn technologies overnight. Algorithms are not a part of computer science. They are the very base of computer science. They are the key differentiating factor between a good programmer and an average programmer; between Google and Infosys; between USA and India!

 

So, How about a roller coaster ride now!

:-)

June 6, 2008

Either this or that, Not both!

Filed under: Philosophy — indhubharathi @ 5:30 pm
Tags: , ,

This is a continuation of one of my previous post (I always thought brain cause minds…).

At S7 Software, we were discussing this over lunch. I said I can prove easily that future can never be predicted. I gave a proof by contradiction. Assume our science and technology has advanced to great extent and future can now be predicted. Assume Karthik can predict future. I took two vicks from my pocket and kept on desk (one blue and other green). Now if Karthik can predict the future, he will be able to tell me which vicks I’m going to take now. But whatever he says, I can take the alternative one which will disprove his prediction. If his prediction still has to be true, the must be some mysterious force contradicting the laws of physics that must force me to take a particular vicks which is not possible. So, it becomes clear that future can never be predicted.

We argued for long over this. Finally Pankaj came up with an explanation which was satisfying. There is a flaw in your proof he said. I started listening with interest. When I said “Assume Karthik can predict the future”, I assumed predictability is possible. When I said “I can take the alternate vicks”, I assumed free choice was possible. Flaw is this: If I assume, future can be predicted then I don’t have free will; If I assume free will is present, then future cannot be predicted. I cannot assume both. That’s where I did the mistake in my proof.

It is simple and cool. You either have free-will or you have predictability. You cannot have both! But still the question remains… What is that we have now? Predictability or free-will?

:-)

Cheers, Indhu

Subjective Validation

Filed under: Psychology — indhubharathi @ 5:27 pm
Tags: ,

Do you believe in horoscopes? Yes? No? Have you ever checked your horoscope in some books or website? Did it seem so real? In 1948, psychologist Bertram R. Forer gave a personality test to his students, and then gave them a personality analysis supposedly based on the test’s results. He invited each of them to rate the analysis on a scale of 0 (very poor) to 5 (excellent) as it applied to them. The average was 4.26. He then revealed that each student had been given the same analysis.

This is called Subjective Validation. Go here to know more on Subjective Validation.

I always thought brain cause minds…

Filed under: Philosophy — indhubharathi @ 5:05 pm
Tags: , ,

But, something I read toady disturbed me a lot. For those who didn’t understand the subject, let me explain the problem:

The question is, “what is consciousness”. It is our own awareness of ourselves and the world; the mental processes that we can perceive; our thoughts and feelings. If we can successfully transfer consciousness our of our body to somewhere else, we have defeated death. Now the question is where does consciousness reside? There are two theories. Monist theory and dualist theory. Dualist theory claims that there are two distinct type of things - mind and body. It claims consciousness resides outside body and its presence cannot be experimentally verified. Monist theory states consciousness is nothing but state of brain. Feeling happy, feeling sad, feeling like going home - are brain states. This makes more sense (atleast to me) and I believe in it.

Now this is what disturbed me. “How can it be that a purely physical mind, whose every transformation is governed strictly by the laws of physics, still retains any freedom of choice? How can it have ‘free-will’?” If mind if purely physical and obeys the laws of physics, it means brain state (or mind) at any instance of time is predictable. If it is predictable, how on earth can anybody have free will? This sounds like a very sensible question.

Know what? I hate to think I’m not writing this post out of my own free will!

Confused, Indhu

The pleasure of not understanding!

Filed under: Philosophy — indhubharathi @ 5:03 pm
Tags: ,

I was hearing a Tamil song - ‘Netru Illadha Maatram Ennadhu’ from the movie ‘Pudiya Mugam’. One line from the song attracted me a lot. Here is the line:

“Kavidhai variyin suvai

Artham puriyum varai…”

It means “Lines of poem are beautiful only till you understand them!”

We desperately try to understand things without realizing that the moment it is understood, the charm is lost!

This is a dialogue from the movie ‘The Life of David Gale’ that speaks on the same subject:

Fantasies have to be unrealistic because the moment… the second…that you get what you seek you don’t you can’t want it anymore. In order to continue to exist desire must have its objects perpetually absent. It’s not the “it” that you want. It’s the fantasy of”it.”

This is what Pascal means when he says that we are only truly happy when daydreaming about future happiness. Or why we say the hunt is sweeter than the kill. Or be careful what you wish for, not because you’ll get it but because you’re doomed not to want it once you do.

Yes! Hunt is sweeter than the kill. Keep hunting!

Cheers, Indhu

Blog at WordPress.com.