Thursday, February 25, 2010

Controlling setup order for Spring DM applications

A quick and easy way to control the order in which Spring DM applications come up is using cardinality property in service imports.

Assume we have two applications app1 and app2 running in a single OSGi container and using Spring DM. Suppose we want app2 wait till app1 is initialized by Spring DM, we could do the following.
i) Export a service with appropriate interfaces / filters from app1.
For example:-
<osgi:service id="dependencyOSGi" ref="applicationDependency" interface="com.test.ApplicationDependency">
<osgi:service-properties><<entry key="application" value="app1-"/></osgi:service-properties>

ii) Imported the above service in app2 with a cardinality 1..1. The cardinality marks the service dependency as mandatory and causes Spring DM to delay the setup of app2 till the dependency is met (i.e. app1 is up an running).

<osgi:reference id="dependencyApp1OSGi" interface="com.test.ApplicationDependency" filter="(application=app1-" cardinality="1..1"/>

"Hello World" in different languages

An interesting collection of the standard "Hello World" program in a number of languages.

A life after CARGO

In his brilliant book (and the subsequent documentary) Guns, Germs and Steel; Jared Diamond recalls the question asked to him by one of the natives of Papua New Guinea. A person named Yali whom Diamond met on a New Guinean beach. Perplexed by the huge economic inequality between the white Europeans the the local New Guineans, Yali asks Diamond an interesting question, "Why you white man has so much CARGO, and we New Guineans have so little?".

CARGO was Yali's simple way of identifying all material goods that the Europeans possessed and brought with them.

Jared Diamond's answer to that question required many years of research and came out in the form of the masterpiece book "Guns, Germs, and Steel".

The perplexing question that Yali asked was relevant to the gross inequality between nations, races & communities, and particulary the Old World (Much of Europe and Asia) and the New World (Americas, Papua New Guinea, Aborginal Australia, most of Africa, etc.). But the same would apply between we individuals in our daily lives.

When bogged down by the problems of life and seeing many other around us who don't have such problems, most of us ask ourselves the basic question.

"Why is his/her life so easy and my life so tough (or screwed up)?"

The reason could be many; accidents of birth, random events of life, luck, our own abilities and disabilities, etc. But whatever the exact reason be, gross inequality between people remains one of the hard facts of life. And that inequality need not be just on a material or monetary basis.

For the vast majority us, its "a life after CARGO", and the perpetual rat-race to have the CARGO we lack, or lament about the CARGO that we may never have. And perplexed at the ever present inequality, we keep on repeating Yali's question.

Bit manipulation techniques

Some simple bit manipulation techniques
Set a bit: x |= (1 << position);
Clear a bit: x &= ~(1 << position);
Toggle a bit: x ^= (1 << position);
Test a bit: ((x >> position) & 1) != 0)
Test if power of two: ((x & (x - 1)) == 0)
Divide 'x' by 2 'n' times: x = x >> n;
Multiple 'x' by 2 'n' times: x = x << n;
Swap two numbers:
void swap(int& a, int& b)
a ^= b;
b ^= a;
a ^= b;

Fundamentals of Marxism

Marxism (however right or wrong its basic assumptions are) is a huge and multifarious system that is worth understanding. Though mostly connected with "Political Economy", Marxism is not limited to that but offers a full philosophical system and world view of its own.

To understand the environment under which Marxism was formed, it helps to have a glimpse of the trends in 17th to 19th century European intellectual circles in general and trends political intelligentsia in particular. Also important is the "post French revolution" decline of Monarchy/Feudalism (the land owners) and rise of the Capitalists (the one who controls the Capital, often called the Bourgeoisie).

Socialist and communist ideas in Europe were an inevitable consequence of the social changes brought in by the industrial revolution and the rise of Capitalism. The tilt in the balance of political power in favor of the merchant class, the emergence of the Proletariat (factory worker) as a major social group, gave rise to a new set of socio-political problems.

Practical attempts to solve socio-political problems through socialism started with Robert Owen (1771-1858) in England. Most of his ideas were Utopian in nature and thus failed inevitably. Socialist ideas slowly emerged as a major feature in European intellectual circles, and gradually gave rise to a group of socialist thinkers and system builders (mostly Utopian). Some of the notable names among them are Pierre Proudhun of France; Alexander Herzen, Mikhail Bakunin of Russia,; Eugen Karl Duhring of Germany ...

Pre-Marxist socialism was mostly Utopian and impractical. Inspired by the philosophy of Willhem Hegel & Ludwig Feurbach and influenced by the emerging materialist world view of the mid 19th century (thanks to Darwin and the rise of naturalism) and backed by a rigorous analysis of history, philosophy and political economy; Marx turned the Utopian socialist ideas of his predecessors into a workable system.

If at all we can single out one principle that is most important to Marxism it is Materialism. And the two fundamental theories of Marxist ideology ends with the word "materialism":

1. Dialectical Materialism:-

Marx gave great significance to the fact that the world is always in motion and is always changing. Taking note that change is the force that drives development and progress in all spheres, and applying it specifically to the social sphere, Marx borrowed Wilhelm Hegel's (1770-1831) metaphysical concept of dialectics and gave it a materialistic interpretation

Marx agreed with Hegel on the triad of dialectical development namely thesis, anti-thesis and synthesis. A thesis is an intellectual proposition/idea/concept, will inherently imply or cause its own negation or very opposite the anti-thesis; whereas the synthesis solves the conflict/contradiction between the thesis and anti-thesis by reconciling their common truths, thus forming a new proposition. The synthesis once a proposition forms a new thesis, which in turn creates its own anti-thesis and synthesis, and so on.

Each cycle of thesis, anti-thesis, synthesis marks progresses, but the shape of the progress is never linear (always improvement) nor circular (always coming back to the starting point) but is spiral in nature. This is called "Law of negation of negation". This implies that though history does repeat itself in some way or the other, history can never be a perfect repetition and there is always some new ground be broken and real progress being made.

Marx disagree with Hegel on a vital aspect. For Hegel the driving force for progress was always ideas, whereas for Marx its the Material (particularly the means of economic production) that determines the progress.

2. Historical Materialism:-

This principle could be considered as the core of Marxist ideology. The main points are as follows:
  • The "means of production" or the way humans work on nature to make their subsistence is the basis of human society and social relations.
  • Labor is the force that enables humans to exploit nature for subsistence.
  • Under favorable circumstances, property ownership and division of labor allows some people in society to live on the labor of others.
  • The level of development of the productive forces determines the "mode of production".
  • For a given mode of production based on what factors of production are dominant, there will be a dominant class who will control and exploit other classes in society.
  • Society progresses dialectically in stages wherein each dominant class is replaced by another in successive epochs based on the mode of production. The "mode of production" which determines the dominant class is the basis /foundation of human society. The basis in turn gives rise to superstructures like religion, culture, arts, etc. Both the basis and superstructure in a given epoch in history, reflects the interests of the dominant class of that period.
  • Class divisions and domination of a particular class, inevitably leads to class struggles.
  • Every dominant class has a tendency to bring in its own downfall partially due to its own inner contradictions, and mainly due to the changing "modes of production"
  • When the domination class becomes sufficiently weak, a new class overthrows it and makes self the new dominant class.
  • Any society with class divisions inevitably leads to class conflicts and is unstable. So was the case for feudalism & monarchy; and so will be the case for capitalism which manufactures own contradiction by creating a large working class population (proletariat) whose interests are in conflict with that of the capitalists.
  • Scientific socialism/communism being classless (only workers) is the only stable social structure. All social systems will inevitably lead to a classless society and communism.

Marx's Analysis of Capital:

"Dialectical Materialism" and "Historical Materialism" forms the intellectual and philosophical basis of Marxism. But the well known work of Marx Das Capital, has very less to do with philosophy but deals more with a rigorous analysis of Capital and its consequences, and is an economic theory based on Marxist philosophical ideas.

Marx starts Capital with an analysis of "Commodity Production and Consumption", which is the cheif economic activity in a capitalist society. Following earlier economists, Marx introduces two concepts "Use Value" and "Exchange Value". "Use Value" determines the usefulness of an item to a person or group, whereas "Exchange Value" determines the price a person or group is willing to pay for an item/commodity. The "Use Value" for breathing air is infinite for human beings, but its "Exchange Value" is zero, as its freely available for everyone. Similarly, the "Use Value" of diamonds for humans is negligible but their "Exchange Value" is high due to their scarcity.

Commodities are produced under capitalism using the "basic factors of production" namely Land, Labor, Capital, and Organization/Management. Profit is the driving factor for capitalist production. In a typical capitalist production process, factors of production having a monetary value of M1 undergoes production process to produce a commodity having a monetary value of M2. And under normal conditions of profit M2 - M1 > zero = surplus value / profit.

Borrowing Labor Theory of Value (LTV) of earlier economists, Marx agrees that the source of surplus value or profit is nothing but human labor. But Marx differs from most of his predecessors in claiming that the surplus value is not due to some creative power of labor but due to the fact that labor is underpaid by the capitalist. The capitalist never pays the laborer in full. In short, the exploitation of the laborer is the source of the capitalist's profit. And the capitalist is able to exploit the laborer because the capitalist through his control of Capital controls/owns the "means of production" that includes the raw materials, factory, machinery, control of management, etc.

Under capitalist system, private ownership of property inevitably leads to the control of Capital by a minority, which in turn leads to the exploitation of the working class. Hence, Marx concludes that "private property" the the main evil in Capitalism.

Law of diminishing profits
Critics of Marx

Wednesday, February 24, 2010



Man's mind, stretched to a new idea, never goes back to its original dimension.
-Oliver Wendell Holmes

Once you label me, you negate me.
-Soren Kierkegaard

I saw all things I feared, and which feared me had nothing good or bad in them save insofar as the mind was affected by them.

People and things do not upset us, rather we upset ourselves by believing that they can upset us.
-Albert Ellis

Nothing is more powerful than an idea whose time has come.
-Victor Hugo

Our truest life is when we are in our dreams awake.
-Henry David Thoreau

For all your days prepare,
And meet them ever alike.
When you are the anvil, bear-
When you are the hammer, strike.
-Edwin Markham

Most of the shadows of this life are caused by standing in one's own sunshine.
-Ralph Waldo Emerson

Not for one single day
Can I discern the way,
But this I surely know-
Who gives the day
Will surely show the way,
So I securely go.
-John Oxenham

The night and storm look as if they would last forever; but the calm and the morning cannot be stayed; the storm in its very nature is transient. The effort of nature, as that of the human heart, ever is to return to its repose, for God is peace.
-George MacDonald

When you fill a swamp with stones, a hundred loads may disappear under the water before a stone appears on the surface, but all of them are necessary.
-Frank C. Laubach

Finish everyday and be done with it. You have done what you could.
-Ralph Waldo Emerson

Everyday is the best of all.One of the illusions of life is that the present hour is not the critical, decisive hour. Write it on your heart that everyday is the best day of the year.
-Ralph Waldo Emerson

Death is not extinguishing the light; it is only putting out the lamp because the Dawn has come.
-Rabindranath Tagore

Only that day dawns to which we are awake.
-Henry David Thoreau

Love everyday. Each one is so short and they are so few.
-John Burroughs

Keep yours fears to yourself, but share your courage with others.
-Robert Louis Stevenson

He is the happiest man who thinks the most interesting thoughts.
-William Lyon Phelps

Do not take life too seriously, you will never get out of it alive.
-Elbert Hubbard

It is better to rise from life as from a banquet, neither thirsty nor drunken.

Without theory, practice is but routine born of habit.
-Louis Pasteur

Service increases our power as it lessens our pride.
-Christian Bernard

Mishaps are like knifes, that either serve us or cut us, as we grasp them by the blade or the handle.
-James Russell Lowell

Silence is the element in which great things fashion themselves.
-Thomas Carlyle

To maintain a fault known is a double fault.
-John Jewel

A failure establishes only this, that our determination to succeed was not strong enough.

Perhaps the greatest comfort in this world is "I am not alone". When you know this for yourself, your fears will lose their hold upon you.
-Norman Vincent Peale

Nurture your mind with great thoughts for you will never go any higher than you think.
-Benjamin Disraeli

Difficulty attracts the man of character because it is in embracing it that he realizes himself
-Charles de Gaulle

The deepest drive in human nature is the desire to be appreciated.
-William James

Your best friend is he who brings out the best that is within you.
-Henry Ford

A man is what he thinks about all day long.
-Ralph Waldo Emerson

Man is a piece of the universe made alive.
-Ralph Waldo Emerson

Every man is a volume, if you know how to read him.
-William Ellery Channing

We lie loudest when we lie to ourselves.
-Eric Hoffer

To know that we know what we know, and that we do not know what we do not know, that is true knowledge.
-Henry David Thoreau

Know thyself.

I am not ashamed to confess that I am ignorant of that I do not know.

Everybody lives and acts partly according to his own, partly according to other people's ideas.
-Leo Tolstoy

The best way out of a difficulty is through it.

Society prepares the crime; the criminal commits it.

The greatest remedy for anger is delay.

How is it possible to expect that mankind will take advise, when they will not so much as take warning?
-Jonathan Swift

He who has confidence in him will lead the rest.

Whenever you see a successful business, someone once made a courageous decision.
-Peter F. Drucker

You cannot run away from a weakness; you must sometime fight it out or perish. And if that be so, why not now, and where you stand.
-Robert Louis Stevenson

Never answer a critic, unless he's right.
-Bernard M. Baruch

We only acknowledge small faults in order to make it appear that we are free from great ones.
-Francois de La Rochefoucauld

No man really becomes a fool until he stops asking questions.
-Charles P. Steinmetz

Nothing will ever be attempted, if all possible objections must be first overcome.
-Samuel Johnson

Success is failure kicked to pieces by hard work.
-Jimmy Lyons

Perhaps the most valuable result of all education is the ability to make yourself to do the thing you have to do, when it ought to be done, whether you like it or not.
-Thomas Henry Huxley

There is only one real failure in life that is possible, and that is, not to be true to the best one knows.

There is nothing so useless as doing efficiently that which should not be done at all.
-Peter F. Drucker

People hate those who make them feel their own inferiority.
-Lord Chesterfield

Like the greatest virtue and the worst dogs, the fiercest hatred is silent.

If things go wrong don't go with them.
-Roger W. Barson

Fame has also this great drawback, that if we pursue it we must direct lives in such a way as to please the fancy of men, avoiding what they dislike and seeking what is pleasing to them.
-Baruch Spinoza

Do not wait for the last judgement, it takes place everyday.
-Albert Camus

It is necessary to be a fox to recognize the snares, and a lion to terrorize the wolves.
-Niccolo Machiavelli

There is only one success - to be able to spend your life in your own way.
-Christopher Morley

Something attempted, something done, Has earned a night's repose:
-Henry Wadsworth Longfellow

What deep wounds ever closed without a scar
-Lord Byron

When a man's knowledge is not in order, the more of it he has the greater will be his confusion.
-Herbert Spencer

I attribute the little I know to my not been ashamed to ask for information and to my rule of conversing with all descriptions of men on those topics that form their own peculiar professions and pursuits.
-John Locke

It is no use saying, "we are doing our best." You have got to succeed in doing what is necessary.
-Winston Churchill

There are only two classes - first class and no class.
-David O. Selznick

Be pleasant until ten o' clock in the morning and the rest of the day will take care of itself.
-Elbert Hubbard

It is never too late to be what you might have been.
-George Eliot

A man watches his pear tree day after day, impatient for the ripening of the fruit. Let him attempt to force the process, and he may spoil both fruit and tree. But let him patiently wait, and the ripe fruit at length falls into his lap.
-Abraham Lincoln

A man can do his best only by confidently seeking (and perpetually missing) an unattainable perfection.
-Ralph Barton Perry

Do what you can, with what you have, where you are.
-Theodore Roosevelt

He that has truth in his heart need never fear the want of persuasion on his tongue.
-John Ruskin

I do not know what I may appear to the world, but to myself I seem to have been only like a boy playing on the seashore, and diverting myself in now and then finding a smoother pebble or a prettier shell than ordinary, whilst the great ocean of truth lay all undiscovered before me.
-Isaac Newton

If all the year were playing holidays, To sport would be as tedious as to work.

Only he deserves power who everyday justifies it.
-Dag Hammarskjold

O, it is excellent
To have a giant's strength, but it is tyrannous
To use it like a giant.

Praise, like gold and diamonds, owes its value to its scarcity.
-Samuel Johnson

He who praises you for what you lack wishes to take from you what you have.
-Juan Manuel

People ask you for criticism but they only want praise.
-Somerset Maugham

Men take only their needs into considerations - never their abilities.
-Napoleon Bonaparte

Some people will never learn anything, for this reason, because they understand too soon.
-Alexander Pope

Slumber not in the tents of your fathers. The world is advancing. Advance with it.
-Giuseppe Mazzini

Fortune does not change men; it unmasks them.
-Mme Necker

If I take care of my character, my reputation will take care of itself.
-D. L. Moody

If A equals success, then the formula is A equals X plus Y plus Z. X is work. Y is play. Z is keep your mouth shut.
-Albert Einstein

The secret of success is this: there is no secret of success.
-Elbert Hubbard

The life of every man is a diary in which he means to write one story, and writes another, and his humblest hour is when he compares the volume as it is with what he vowed to make it.
-J. M. Barrie

All men are ordinary men; the extraordinary men are those who know it.
-G. K. Chesterton

Win hearts, and you have all men's hands and purses.
-William Cecil Burliegh

Good is not good, where better is expected.
-Thomas Fuller

He that talketh what he knoweth will also talk what he knoweth not.
-Francis Bacon

Some men succeed by what they know; some by what they do; and a few by what they are.
-Elbert Hubbard

Where all men think alike, no one thinks very much.
-Walter Lippmann

The most fluent talkers or the most plausible reasoners are not always the justest thinkers.
-William Hazzlit

He who will not reason, is a bigot; he who cannot is a fool; and he who dares not is a slave.
-Sir William Drummond

Few people think more than two or three times a year. I have made an international reputation for myself by thinking only once or twice a week.
-George Bernard Shaw

If any man wishes to write a clear style, let him first be clear in his thoughts.
-Johann W. von Goethe

Mark this well, ye proud men of action! Ye are, after all, nothing but unconscious instruments of the men of thought.
-Heinrich Heine

Whoever is in a hurry shows that the thing he is about is too big for him.
-Lord Chesterfield

Lost, somewhere between sunrise and sunset, sixty golden minutes. Each set with sixty diamond seconds. No reward is offered, for they are gone forever.
-Horace Mann

When we do not find peace of mind in ourselves it is useless to look for it elsewhere.
-La Rochefoucauld

Our hope of immortality does not come from any religion, but nearly all religions come from that hope.

It is not selfish to think for oneself. A man who does not think for himself does not think at all.
-Oscar Wilde

Most men are like eggs, too full of themselves to hold anything else.
-Josh Billing

Make the most of your regrets. To regret deeply is to live afresh.
-Henry David Thoreau

A man is rich in proportion to the number of things he can afford to let alone.
-Henry David Thoreau

Nothing is so hard for those who abound in riches as to conceive how others can be in want.
-Jonathan Swift

It will never rain roses; when we want. To have more roses we must plant more trees.
-George Eliot

The secret of the man who is universally interesting is that he is universally interested.
-William Dean Howells

The same people who can deny others everything are famous for refusing themselves nothing.
-Leigh Hunt

No man, would listen to you talk if he didn't know it was his turn next.
-E. W. Hosea

A teacher affects eternity, he can never tell where his influence stops.
-Henry Adams

Time goes, you say? Ah no!
Alas, time stays, we go.
-Austin Dobson

A man can succeed at almost anything for which he has unlimited enthusiasm.
-Charles Schwab

Nothing in the world will take the place of 'persistence'. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination alone are omnipotent. The slogan 'Press on!' has solved and always will solve the problems of the human race.
-Calvin Coolidge

Teach me neither to cry for the moon nor over spilt milk.

Take care to get what you like or you will be forced to like what you get.
-George Bernard Shaw

An angry man is always full of poison.

The best way to prepare for tomorrow is to concentrate with all your intelligence, all your enthusiasm, on doing today's work superbly today.
-Sir William Ostler

A man's life is what his thoughts make of it.
-Marcus Aurelius

Be willing to have it so. Acceptance of what has happened is the first step to overcoming the consequence of any misfortune.
-William James

Vulgar people take huge delight in the faults and follies of great men.

Do the very best you can: and then put up your old umbrella and keep the rain of criticism from running down the back of your neck.
-Dale Carnegie

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.
-Robert Frost

You can fool all the people some of the time, and some of the people all the time, but you cannot fool all the people all the time.
-Abraham Lincoln

Let no man pull him so low as to make you hate him.
-Booker T. Washington

The shape of the world today does not permit us the luxury of soft-mindedness. Tough-mindedness without tender-heartedness is cold and detached, leaving one's life in a perpetual winter devoid of the warmth of spring and the gentle-heart of summer.
-Martin Luther King

If a man can write a better book, preach a better sermon, or make a better mouse-trap than his neighbor, though he build his house in the woods, the world will make a beaten path to his door.
-Ralph Waldo Emerson

How strange it is, our little procession of life! The child says 'When I am a big boy.' But what is that? The big boy says: 'When I grow up.' And then, grown up he says: 'When I get married', what is it after all? The thought changes to 'When I'm able to retire.' And then, when retirement comes, he looks back over the landscape traversed; a cold wind seems to sweep over it; somehow he has missed it all; and it is gone. Life, we learn too late, is in the living, in the tissue of every day and hour.
-Stephen Leacock

Reading maketh a full man; conference a ready man; and writing an exact man.
-Francis Bacon

All the world is a stage,
And all the men and women merely players.

Man is born free and everywhere he is in chains.
-Jean Jacques Rousseau

The trouble with the world is that the stupid are cocksure and the intelligent full of doubt.
-Bertrand Russell

Superstition is the religion of feeble minds.
-Edmund Burke

Cowards die many times before their death;
The valiant never taste death but once.

There is only one way to happiness and that is to cease worrying about things which are beyond the power of our will.

God grant me the serenity,
To accept the things I cannot change,
The courage to change the things I can,
And the wisdom to know the difference.
-Dr. Reinhold Niebuhr

You and I will last longer, and enjoy smoother riding, if we learn to absorb the shocks and jolts along the rocky road of life.
-Dale Carnegie

When I can't handle events, I let them handle themselves.
-Henry Ford

Nobody ever mastered any skill except through intensive, persistent and intelligent practice.
-Norman Vincent Peale

Throw your heart over the bar, and your body will follow.

Obviously, circumstances alone do not make us happy or unhappy. It is the way we react to circumstances that determines our feelings.
-Dale Carnegie

The most important thing in life is not to capitalize on your gains. Any fool can do that. The really important thing is to profit from your losses. That requires intelligence; and it makes the difference between a man of sense and a fool.
-William Bolitho

Genius is one percent inspiration and ninety-nine percent perspiration.
-Thomas Alva Edison

The true art of memory is the art of attention.
-Samuel Johnson

Great things are accomplished not by strength, speed or physical dexterity but by ... force of character, will and judgement.

True eloquence comprises saying all that needs to be said, and only that.
-La Rouchefoucauld

Where there is no will there is no way.
-George Bernard Shaw

Our bodies are our gardens to which our minds and wills are gardeners; ... either to have it sterile or manured with industry.

Difficulties are things that show what men are.

The winds and waves are always on the side of the ablest navigators.
-E. Gibbon

Knowledge may give weight, but accomplishments give lustre and many more people see than weigh.
-Lord Chesterfield

The descent into hell is easy, but to recall your steps, And to re-ascend to the upper air, this is labour, this is work.

If we are too weak to accomplish our goals we are still strong enough to work on it as best we can.
-Romain Rolland

Anyone can become angry - that is easy. But to be angry with the right person, to the right degree, at the right time, for the right purpose, and in the right way - that is not easy.

Life is a narrow vale between the cold and barren peaks of two eternities. We strive in vain to look beyond the heights. We cry aloud, and the only answer is the echo of our wailing cry. From the voiceless lips of the dead there comes no word; but in the night of death hope sees a star, and listening love can hear the rustle of a wing.
-Robert Greene Ingersoll

I have but one lamp by which my feet are guided; and that is the lamp of experience. I know of no way of judging the future but by the past.
-Patrick Henry

Two men looked through prison bars-
One saw mud, the other stars.

O Lord, thou givest us everything, at the price of an effort.
-Leonardo da Vinci

It is a shameful thing for the soul to faint while the body still perseveres.
-Marcus Aurelius

I cannot say, and I will not say
That he is dead. He is just away.
-James Whitcomb Riley

The best preparation for the night is to work diligently while the day lasts. The best preparation for death is life.
-George Macdonald

He who has a thousand friends has not a friend to spare, he who has one enemy shall meet him everywhere.
-Ali Ben Abu Taleb

Very little is needed to make a happy life. It is all within yourself, in your way of thinking.
-Marcus Aurelius

Life is real! Life is earnest!
And the grave is not its goal;
Dust thou art, to dust returnest,
Was not spoken of the soul.
-Henry Wadsworth Longfellow

Anyone can carry his burden, however hard, until nightfall. Anyone can do his work, however hard, for one day. Anyone can live sweetly, patiently, lovingly, purely, till the sun goes down. And this is all that life really means
-Robert Louis Stevenson

Happy the man, and happy he alone,
He, who can call today his own,
He who, secure within, can say:
"Tomorrow, do thy worst, for I have lived today."
-Horace (Roman poet)

Gratitude is a fruit of great cultivation. You do not find it among gross people.
-Samuel Johnson

Quarrel not at all. No man resolved to make the most of himself can spare time for personal contention. Still less he can afford to take all the consequences, including vitiating of his temper and loss of self-control.
-Abraham Lincoln

The secret of being miserable is to have the leisure to bother about whether you are happy or not.
-George Bernard Shaw

I live everyday as if it is the first day I had ever seen and the last I was going to see.
-William Lyon Phelps

We ourselves feel that what we are doing is just a drop in the ocean. But if that drop was not in the ocean, I think the ocean will be less because of that missing drop.
-Mother Teresa

Progress is the law of life.
-Robert Browning

All achievements, all earned riches, have their beginning in an idea.
-Andrew Carnegie

I am the master of my fate,
I am the captain of my soul.

The people who really do great things in this world, are those who drive past the first layer of fatigue.
-William James

Take care of your thoughts. You can do what you will with them.

Whenever I hear anyone arguing for slavery, I feel a strong impulse to see it tried on him personally.
-Abraham Lincoln

The law cannot make an employer love me, but it can keep him from refusing to hire me because of the color of my skin.
-Martin Luther King

Bravery is a volcano; the seed of wavering does not grow on its crater.
-Kahlil Gibran

Shut the iron doors on the past and future. Live in day-tight compartments.
-Sir William Ostler

What is in a name? That which we call a rose
By any other name would smell as sweet.

We shall not cease from exploration, and the end of our exploring will be to arrive where we started, and know the place for the first time
- T. S. Eliot

A bad beginning makes a bad ending.

A bad workman always blames his tools.

A body seriously out of equilibrium, either with itself or with its environment, perishes outright. Not so a mind. Madness and suffering can set themselves no limit.
-George Santayana

A critic is a man who knows the way but can't drive the car.
-Kenneth Tynan

Laws are like cobwebs, which may catch small flies, but let wasps and hornets break through.
-Jonathan Swift

A cynic is a man who, when he smells flowers, looks around for a coffin.
- L. Mencken

It is only the poor who pay cash, and that not from virtue, but because they are refused credit.
-Anatole France

A desperate disease requires a dangerous remedy.
-Guy Fawkes

A friendship founded on business is better than a business founded on friendship.
-John D. Rockefeller

My candle burns at both ends;
It will not last the night;
But ah, my foes, and oh, my friends—
It gives a lovely light!
-Edna St. Vincent Millay

He has an oar in every man's boat, and a finger in every pie.
-Miguel de Cervantes

The future is like heaven—everyone exalts it but no one wants to go there now.
-James Baldwin

But there comes a moment in everybody's life when he must decide whether he'll live among human beings or not—a fool among fools or a fool alone.
-Thornton Wilder

I must begin with a good body of facts and not from a principle (in which I always suspect some fallacy) and then as much deduction as you please.
-Charles Robert Darwin

How far that little candle throws his beams!
So shines a good deed in a naughty world.
-William Shakespeare

A good memory is needed after one has lied.
-Pierre Corneille

A good novel tells us the truth about its hero; but a bad novel tells us the truth about its author.
-G. K. Chesterton

I am about to take my last voyage, a great leap in the dark.
-Thomas Hobbes 1679. Last words.

A hen is only an egg's way of making another egg.
-Samuel Butler

Man is not a solitary animal, and so long as social life survives, self-realization cannot be the supreme principle of ethics.
-Bertrand Russell

A hungry stomach has no ears.
-Jean de La Fontaine

With malice toward none; with charity for all; with firmness in the right, as God gives us to see the right, let us strive on to finish the work we are in: to bind up the nation's wounds; to care for him who shall have borne the battle, and for his widow and his orphan, to do all which may achieve and cherish a just and lasting peace among ourselves, and with all nations.
-Abraham Lincoln

Of two evils, the lesser is always to be chosen.
-Thomas à Kempis

A king is a thing men have made for their own sakes, for quietness' sake. Just as if in a family one man is appointed to buy the meat.
-John Selden

The human face is indeed, like the face of the God of some Oriental theogony, a whole cluster of faces, crowded together but on different surfaces so that one does not see them all at once.
-Marcel Proust

The chess-board is the world; the pieces are the phenomena of the universe; the rules of the game are what we call the laws of Nature. The player on the other side is hidden from us. We know that his play is always fair, just, and patient. But also we know, to our cost, that he never overlooks a mistake, or makes the smallest allowance for ignorance.
-T. H. Huxley

That a lie which is all a lie may be met and fought with outright,
But a lie which is part a truth is a harder matter to fight.
-Alfred Lord Tennyson

A little learning is a dangerous thing;
Drink deep, or taste not the Pierian spring:
There shallow draughts intoxicate the brain,
And drinking largely sobers us again.
-Alexander Pope

If a little knowledge is dangerous, where is the man who has so much as to be out of danger?
-T. H. Huxley

A little neglect may breed mischief,...for want of a nail, the shoe was lost; for want of a shoe the horse was lost; and for want of a horse the rider was lost.
-Benjamin Franklin

A man's respect for law and order exists in precise relationship to the size of his paycheck.
-Adam Clayton Powell, Jr.

Like as the waves make towards the pebbled shore,
So do our minutes hasten to their end.
-William Shakespeare

So little done, so much to do.
-Cecil Rhodes

Television is an invention that permits you to be entertained in your living room by people you wouldn't have in your home.
-David Frost

If God hadn't rested on Sunday, He would have had time to finish the world.
-Gabriel García Márquez

First you take a drink, then the drink takes a drink, then the drink takes you.
-Attributed to: F. Scott Fitzgerald

My work is done. Why wait?
-George Eastman, Suicide note (1932).

Even in the valley of the shadow of death, two and two do not make six.
- Leo Tolstoy (1828–1910), Russian writer. Refusing to reconcile himself with the Russian Orthodox Church as he lay dying. (November 1910).

The problem is not that there are problems. The problem is expecting otherwise
and thinking that having problems is a problem.
- Theodore Rubin

Ideas that enter the mind under fire remain there securely and for ever.
- Leon Trotsky

If we had had more time for discussion we should probably have made a great many more mistakes.
- Leon Trotsky

Life is not an easy matter... You cannot live through it without falling into frustration and cynicism unless you have before you a great idea which raises you above personal misery, above weakness, above all kinds of perfidy and baseness.
- Leon Trotsky

The end may justify the means as long as there is something that justifies the end.
- Leon Trotsky

It is better to die on your feet than to live on your knees.
- Emiliano Zapata

Every man dies. Not every man really lives.
- William Wallace

My country, right or wrong; if right, to be kept right; and if wrong, to be set right.
- Carl Schurz

Is life so dear or peace so sweet as to be purchased at the price of chains and slavery? Forbid it, Almighty God! I know not what course others may take, but as for me, give me liberty, or give me death!
- Patrick Henry

People go to church for the same reasons they go to a tavern: to stupefy themselves, to forget their misery, to imagine themselves, for a few minutes anyway, free and happy.
- Mikhail Bakunin

The first revolt is against the supreme tyranny of theology, of the phantom of God. As long as we have a master in heaven, we will be slaves on earth.
- Mikhail Bakunin

Where the state begins, individual liberty ceases, and vice versa.
- Mikhail Bakunin

A Boss in Heaven is the best excuse for a boss on earth, therefore If God did exist, he would have to be abolished.
- Mikhail Bakunin

By striving to do the impossible, man has always achieved what is possible. Those who have cautiously done no more than they believed possible have never taken a single step forward.
- Mikhail Bakunin

Freedom, morality, and the human dignity of the individual consists precisely in this; that he does good not because he is forced to do so, but because he freely conceives it, wants it, and loves it.
- Mikhail Bakunin

From each according to his faculties; to each according to his needs.
- Mikhail Bakunin

From the naturalistic point of view, all men are equal. There are only two exceptions to this rule of naturalistic equality: geniuses and idiots.
- Mikhail Bakunin

Judgement comes from experience, and experience comes from bad judgement.
- Simon Bolivar

Whenever death may surprise us, let it be welcome if our battle cry has reached even one receptive ear and another hand reaches out to take up our arms.
- Che Guevara

I don't care if I fall as long as someone else picks up my gun and keeps on shooting.
- Che Guevara

When the pain is great enough, we will let anyone be doctor.
- Mignon McLaughlin, The Neurotic's Notebook, 1960

A thousand men can't undress a naked man.
- Greek Proverb

Our greatest pretenses are built up not to hide the evil and the ugly in us, but our emptiness.  The hardest thing to hide is something that is not there.
- Eric Hoffer, Passionate State of Mind, 1955

Who is more foolish, the child afraid of the dark or the man afraid of the light?
- Maurice Freehill

Because they know the name of what I am looking for, they think they know what I am looking for!
- Antonio Porchia

The charm of history and its enigmatic lesson consist in the fact that, from age to age, nothing changes and yet everything is completely different.
- Aldous Huxley

Will localizes us; thought universalizes us.
- Henri Frederic Amiel

Genuine tragedies in the world are not conflicts between right and wrong.  They are conflicts between two rights.
- Georg Hegel

In this, the late afternoon of my life, I wonder: am I casting a longer shadow or is my shadow casting a shorter me?
- Robert Brault

In general people experience their present naively, as it were, without being able to form an estimate of its contents; they have first to put themselves at a distance from it - the present, that is to say, must have become the past - before it can yield points of vantage from which to judge the future.
- Sigmund Freud, The Future of an Illusion

The only Zen you can find on the tops of mountains is the Zen you bring up there.
- Robert M. Pirsig

When you look into an abyss, the abyss also looks into you.
- Friedrich Nietzche

What you discover in a democracy is that it is difficult to build a house when each nail has an opinion.
- Robert Brault

I am a part of all that I have met.
- Alfred Lord Tennyson

We are all but recent leaves on the same old tree of life and if this life has adapted itself to new functions and conditions, it uses the same old basic principles over and over again.  There is no real difference between the grass and the man who mows it.
- Albert Szent-Györgyi

Oh, Heaven, it is mysterious, it is awful to consider that we not only carry a future Ghost within us; but are, in very deed, Ghosts!
- Thomas Carlyle

It requires a great deal of faith for a man to be cured by his own placebos.
- John L. McClenahan

Philosophy is life's dry-nurse, who can take care of us - but not suckle us.
- Soren Kierkegaard

Alice came to a fork in the road.  "Which road do I take?" she asked.
"Where do you want to go?" responded the Cheshire cat.
"I don't know," Alice answered.
"Then," said the cat, "it doesn't matter."
- Lewis Carroll, Alice in Wonderland

Each forward step we take we leave some phantom of ourselves behind.
- John Lancaster Spalding

The map is not the territory.
- Alfred Korzybski

No matter where you go or what you do, you live your entire life within the confines of your head.
- Terry Josephson

If you chase two rabbits, you will not catch either one.
- Russian Proverb

The observer, when he seems to himself to be observing a stone, is really, if physics is to be believed, observing the effects of the stone upon himself.
- Bertrand Russell

Among creatures born into chaos, a majority will imagine an order, a minority will question the order, and the rest will be pronounced insane.
- Robert Brault

You can't reason someone out of a position they didn't reason themselves into.
- Anonymous

Man is the only animal who enjoys the consolation of believing in a next life; all other animals enjoy the consolation of not worrying about it.
- Robert Brault

Talk sense to a fool and he calls you foolish

It is, I think, particularly in periods of acknowledged crisis that scientists have turned to philosophical analysis as a device for unlocking the riddles of their field. Scientists have not generally needed or wanted to be philosophers.
- Thomas Kuhn

The safest general characterization of the European philosophical tradition is that it consists of a series of footnotes to Plato.
- Alfred North Whitehead

There is but one truly serious philosophical problem and that is suicide.
- Albert Camus

Historical Validity of the Bible As God's Word

The inerrancy and perfectness of the Bible has been a central aspect of faith for most Christian sects. And this has been the cause (atleast indirectly) of some major tussles between the medieval church and science. But whether we like it or not there are many parts of the Bible which doesn't agree perfectly with known scientific, historic and logical facts.

I feel, its totally unecessary for Christians to claim that every book, verse, word in the Bible is perfect. The simple reason being, we have a lot of contrary evidence.

Also for the believer, Christianity need not stand or fall on the reliability of the Bible. The following are a few notable points.
1) The Bible was written by human beings.
2) Unlike Quran, we don't have any documentary evidence of God or any other divine source dictating the contents of what is to be the Bible. There are no such claims in the Bible itself.
3) The exact choice of the Books to be in the Bible was decided by councils and synods and not by God or angels.

The history of early Christianity is also the story of a number of various heresies and doctrinal differences. The choice of the contents of the Bible would have been definitely influenced by the numerous councils and synods in early Christian period, which were setup to reconcile the differences. A few notable ones being,
-> Council of Jerusalem 50 AD
-> The First Council of Niceae 325 AD
-> The Synod of Laodicea 364 AD
-> The Council of Constantinople 381 AD
-> The Synod of Hippo 393 AD

The role of politics and power too cannot be overridden.

The point is that, if we check history, we see that what is to be the Bible was not given apriori. Early Christianity didn't spring up from an entirely Biblical source. Its more like the Bible evolved over a few centuries during the early Christian period to be what it is now. i.e. The Bible as we know today didn't exist until atleast Christianity reached a certain level. The Bible was not the single source that created early Christianity, rather it evolved with it.

The real "Alcoholics Anonymous"

Most of us know "Alcoholics Anonymous" as an organization helping people to stay away from alcohol.

But isn't the name a misnomer?

The name would be more appropriate to describe the ones who consume alcohol anonymously or secretly; without the knowledge of their families in particular. There is no scarcity of such people around us, and many of us ourselves are part of the group.

May be they are the real "Alcoholics Anonymous".

Customozing Spring's Routing Datasource

Changing the data source of your application dynamically at runtime is a very desirable feature for complex enterprise applications and frameworks. If you are using Spring, one of the viable options is Spring's AbstractRoutingDataSource, which allows dynamic data sources based on a lookup key. It uses the well known Decorator pattern to provide a javax.sql.DataSource instance dynamically.

The following article by Mark Fisher from Spring team clearly explains how to go about it:

The default usage of Spring's AbstractRoutingDataSource is something as follows:
i) You have a set of data sources among which you want to switch dynamically.
ii) You have a well known dynamic key that can pick the right data source for you.

But what if you want to change the set of data sources themselves dynamically? The default usage of AbstractRoutingDataSource won't allow this. After digging into Spring code for some time I found that the following piece of code can do the job.

public class RoutingDataSource extends AbstractRoutingDataSource {
private Map targetDataSources = new HashMap();
public void setTargetDataSources(Map targetDataSources) {
this.targetDataSources = targetDataSources;

protected DataSource determineTargetDataSource() {
Object lookupKey = determineCurrentLookupKey();
DataSource dataSource = (DataSource)this.targetDataSources.get(lookupKey);
if (dataSource == null) {
throw new IllegalStateException("Cannot determine target DataSource for lookup key [" + lookupKey + "]");
return dataSource;

protected Object determineCurrentLookupKey() {
return /*a lookup key that can pick the actual datasource from the Map*/;

public void afterPropertiesSet() {
// do nothing
// overridden to avoid datasource validation error by Spring

Sunday, February 21, 2010

Some JavaScript utility functions

* Trim a string
function trim(str) {
str = str + '';
return str.replace(/^\s+|\s+$/g, '');

* Merge two JSONs, with controllable overwrite.
function mergeJson(target, source, overwrite) {
for (var item in source) {
if (target[item] && typeof source[item] === 'object') {
this.mergeJson(target[item], source[item]);
} else if (!target[item] || overwrite === true) {
target[item] = source[item];
return target;

* Check if an array contains a given elements.
function arrayContainsElement(arr, ele) {
var contains = false;
if (arr) {
for (var i = 0; i < arr.length; i++) {
if (this.trim(arr[i]) === this.trim(ele)) {
contains = true;
return contains;