Wednesday, May 21, 2008

C/C++ If statement

Lately, I was been reading C/C++ Coding Styles. It talks about parenthesis-ing, spacing, alignment, etc...

I also recommends some common software practices, such as putting the numerical constant first in the comparison statements like if, while, for and ?:

for example:


if (1000 < stack_size) {
...
}

while (10 != num) {
...
}


for (int i=0; 20 == value; ++i) {
...
}


Why does it emphasize this rule ? It will help you to avoid ambiguous assignments in the conditional statements.

A common mistake in for loop
=====================


for(int i=0;i < X; i++)

whenever we write "for" loop we are tend to use the post-fix operator ++ instead of pre-fix ++. First one need to understand what is the difference between i++ and ++i, and when to use what.

i++ is more complex and takes more clock cycles than ++i. So please make it a habit to use ++i instead of i++, this may make your code a little bit faster.

Monday, May 19, 2008

My Birthday and Pat & Stan

I have done my birthday shopping last weekend. Tomorrow (21-may) is my 30th birthday. hmm...

I feel good,

Miles to go before I sleep,
Miles to go before I sleep ....


My kid Rohan and myself love watching The Owl and Pat&Stan from JetX Channel. The imaginative work involved in these cartoons are very cool. I have a Pat&Stan singing "In the jungle" in my blog.

I'm making steady progress in my goals and objectives in my life. It is very slow, but very steady.

1. I'm doing meditation on the weekends
2. Solved 1 ACM (2062) last week
3. Reading The C++ Programming Language

Wednesday, May 14, 2008

Make "make" work for you

Make - tool to control the compilation and creation of executables. I was hacking into this tool for quite sometime. I feel "make" is good for all the linux/unix c/c++ programmers.

Here is a simple Tutorial of Make:

source file (helloworld.c)
========
#include ...
int main() {
using namespace std;

cout<<"hello world\n"; return 0;
}
simple makefile(gnumakefile/makefile)
===========
helloworld: helloworld.c
TAB g++ -o helloworld helloworld.c

TAB - is important, otherwise gnumake will prompt for error.

command
=======
make TARGET

make helloworld

Example 2
========

/* sum.c */

int sum(int a, int b) {
return a+b;
}

/* diff.c */

int diff(int a, int b) {
return a-b;
}

/* main.c */

int main() {
...
c=sum(20,30);
...
d=diff(30,23);
...
}

/* Make file */

CC = g++ /* which compiler*/
CFLAGS = -Wall -g -ansi /* compiler flags */

sum.o: sum.c
$(CC) $(CFLAGS) -c -o $@ $<
diff.o: diff.c
$(CC) $(CFLAGS) -c -o $@ $<
main: sum.o diff.o main.c
$(CC) $(CFLAGS) -o $@ $^
clean:
-rm core *.o main
Special Tags
=========
$@ -- current target name
$LT -- First name of the prerequisite
$^ -- List of all prerequisite
$* -- List of all prerequisite (without prefix)

So, dudes, start using make. It is cool, it makes life a lot easier for c/c++ programmers.

Monday, May 12, 2008

My Study on Virtue

We use some words without knowing what is the exact meaning of it. One such word is Virtue, What does it mean ?

Virtue - it stands for Moral Excellence of a person.

The four cardinal (hinge) virtues are
1. Justice
2. Courage
3. Wisdom
4. Moderation

The four classic Western cardinal virtues are:
1. Temperance - Self discipline
2. Prudence - Wisdom
3. Fortitude - Courage
4. Justice

Buddhist practice as outlined in the Noble Eightfold Path can be regarded as a progressive list of virtues.

1. Right Viewpoint - Realizing the Four Noble Truths
2. Right Values - Commitment to mental and ethical growth in moderation
3. Right Speech - One speaks in a non hurtful, not exaggerated, truthful way
4. Right Actions - Wholesome action, avoiding action that would do harm
5. Right Livelihood - One's job does not harm in any way oneself or others; directly or indirectly
6. Right Effort - One makes an effort to improve
7. Right Mindfulness - Mental ability to see things for what they are with clear consciousness
8. Right Meditation - State where one reaches enlightenment and the ego has disappeared

The Four Noble Truth:

1. The Nature of Suffering
2. Suffering's Origin
3. Suffering's Cessation
4. The Way Leading to the Cessation of Suffering - (It is the Noble Eightfold Path)

Capital Vices

1. Pride or Vanity — an excessive love of self
2. Avarice (covetousness, Greed) — a desire to possess more than one has need
3. Lust — excessive sexual desire. "lust detracts from true love".
4. Wrath or Anger — feelings of hatred, revenge or even denial, as well as punitive desires outside of justice
5. Gluttony — overindulgence in food, drink or intoxicants, or misplaced desire of food as a pleasure for its sensuality
6. Envy or jealousy - resentment of others for their possessions "Love of one's own good perverted to a desire to deprive other men of theirs")
7. Sloth or Laziness - idleness and wastefulness of time allotted. Laziness is condemned because others have to work harder and useful work can not get done.

----- Collected from Wiki ----

Wednesday, April 23, 2008

Breaking and Building

Again, It has happened, I have broken the trust of my wife. Why is it happening like this, my relationship with my wife is growing to heavens. But all of a sudden, it is broken. This is happening for the 3rd time in my marriage life.

Now, I have to start from the first. I have to start building my trust from the ground level. It is a Himalayan Task, it requires lot of Patience. Everything is because of my troubled Childhood.

But, whatever happens, her trust will return to me. Because "I Love Her" so much.

Monday, April 21, 2008

Good Quote

I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.

-- Stephen Hawking

Stephen Hawkings is one of the scientist I like to meet in my life time. Some of the Important Scientist whose writings I live to read:

1. Albert Einstein
2. Donald Knuth
3. Steven Pinker
4. Roger Penrose
5. Douglas P.Hofstadter
6. Richard P.Feynman
7. Oliver Sacks
9. Maryanne Wolf
10. Grady Booch

Thursday, April 17, 2008

Aathichuvadi

Do you remember Aathichuvadi ? If not please read it here.

Self-help - currently the western world is looking into it. I have read lot of self-help books, ranging from Robin Sharma to Tony Robbins. Tamil literature has also donated the world with its irreplaceable Thirukural written 2nd BC. It is also donated Aathichuvadi, written by Aavaiyyar (a female poet).

அறம் செய விரும்பு (Be desirous of doing virtue)
ஆறுவது சினம் (It is the nature of anger to temper in time)
இயல்வது கரவேல் (Do what "you can do") (Never stop learning)
ஈவது விலக்கேல் (Always be charitable) (Don't prevent charity)
உடையது விளம்பேல் (Don't advertise of your possessions)
ஊக்கமது கைவிடேல் (Don't give up perseverance)
எண் எழுத்து இகழேல் (Don't despise learning)
ஏற்பது இகழ்ச்சி (Acceptance (begging) is despicable)
ஐயமிட்டுண் (Eat after donating to the needy)
ஒப்புர வொழுகு (Act virtuously)
ஓதுவது ஒழியேல் (Don't give up reading)
ஒளவியம் பேசேல் (Don't carry tales)

Tuesday, April 15, 2008

ID, Purse and Mobile

"ID, Purse and Mobile" - I hear this phrase daily. My wife used to ask me everyday "Have you taken ID, Purse and Mobile ?". She knows I'm an absent-minded professional. But there is a philosophy behind it.. I'm not a philosopher or something like that, but it is just a metaphor.

ID (Identity Card), signifies your Identity in this world (Your Self). Purse, of course, is your financial status, how do you manage your money(mere earning is no enough, one should know how to manage it) . Mobile is the communication quality, how you communicate with the outside world.

Your world revolves around these 3 important things.

LOL...

Wednesday, April 09, 2008

A PSALM OF LIFE

A PSALM OF LIFE

WHAT THE HEART OF THE YOUNG MAN
SAID TO THE PSALMIST

TELL me not, in mournful numbers,
Life is but an empty dream ! —
For the soul is dead that slumbers,
And things are not what they seem.

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.

Not enjoyment, and not sorrow,
Is our destined end or way ;
But to act, that each to-morrow
Find us farther than to-day.

Art is long, and Time is fleeting,
And our hearts, though stout and brave,
Still, like muffled drums, are beating
Funeral marches to the grave.

In the world's broad field of battle,
In the bivouac of Life,
Be not like dumb, driven cattle !
Be a hero in the strife !

Trust no Future, howe'er pleasant !
Let the dead Past bury its dead !
Act,— act in the living Present !
Heart within, and God o'erhead !

Lives of great men all remind us
We can make our lives sublime,
And, departing, leave behind us
Footprints on the sands of time ;

Footprints, that perhaps another,
Sailing o'er life's solemn main,
A forlorn and shipwrecked brother,
Seeing, shall take heart again.

Let us, then, be up and doing,
With a heart for any fate ;
Still achieving, still pursuing,
Learn to labor and to wait.

Monday, April 07, 2008

Life is a Binary Search

“Life is a Binary Search” - Meaning you keep oscillating between extremes until you find your niche in life.

- Donald E.Knuth

Monday, March 31, 2008

"Auto" Expeience...

Today, while I'm coming to office, I saw a quote written on back on an Auto Rickshaw.

"Money, youthfulness, beauty ... are temporary things"

"Simplicity, patience, honesty ... will move you forward in life"


Great insight .....

Wednesday, March 26, 2008

My New Company ....

This is my first posting from My New Company. Everything looks cool and neat, I have to start from the Fundu.

I joined on 19-Mar-08. After 3 days of Introduction and Induction process, I've started reading manuals of WiMax (Wireless Broadband).

Monday, March 10, 2008

about gperf

gperf - generate a perfect hash function from a key set

>gperf
one
two
three
four
five
six
seven
eight
nine
ten
/* C code produced by gperf version 3.0.1 */
/* Command-line: gperf */
/* Computed positions: -k'3' */

#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
error "gperf generated tables don't work with this execution character set. Please report a bug to ."
#endif


#define TOTAL_KEYWORDS 10
#define MIN_WORD_LENGTH 3
#define MAX_WORD_LENGTH 5
#define MIN_HASH_VALUE 3
#define MAX_HASH_VALUE 18
/* maximum key range = 16, duplicates = 0 */

#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static unsigned int
hash (str, len)
register const char *str;
register unsigned int len;
{
static unsigned char asso_values[] =
{
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 15, 19, 10, 19, 19, 19, 19, 19, 19,
5, 10, 19, 19, 5, 19, 19, 10, 0, 19,
0, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19
};
return len + asso_values[(unsigned char)str[2]];
}

#ifdef __GNUC__
__inline
#endif
const char *
in_word_set (str, len)
register const char *str;
register unsigned int len;
{
static const char * wordlist[] =
{
"", "", "",
"six",
"five",
"seven",
"", "",
"ten",
"nine",
"three",
"", "",
"two",
"four",
"eight",
"", "",
"one"
};

if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);

if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key];

if (*str == *s && !strcmp (str + 1, s + 1))
return s;
}
}
return 0;
}

Sunday, March 09, 2008

Inspirational Websites & Links

Meditation Music:

http://www.esnips.com/web/arrtidpatel-Meditation/

Other Websites:

http://www.thewinningmovie.com

http://www.212movie.com

http://www.themythsmovie.com

http://www.natureofsuccessmovie.com

http://www.the-race-movie.com

http://www.lightmovie.com

http://www.innerguidancemovie.com

http://www.makeadifferencemovie.com

http://www.inspirationjunction.com/skyquestcom/community/ij/asp/ijmain.asp?root=&langid=2&txtPage=1

http://www.thedontquitpoem.com/

http://www.xehupatl.com/oldschool.htm

http://www.esnips.com/web/selfhelp2

http://www.esnips.com/web/Power123

http://www.esnips.com/web/suneil-spiritual

http://www.esnips.com/web/BrianTracy-PhoenixSeminar

www.positivepause.com

http://www.natureofsuccessmovie.com/

http://www.the-race-movie.com/

http://thegoodnessoflife.com/

http://awaken.greatday.com/

http://wonderofitall.com/

http://www.thethrivemovie.com

Friday, March 07, 2008

First Programmer of the World

I hear and I forget. I see and I remember. I do and I understand.

-- Confucius (Chinese Philosopher) 551-479 B.C.

Thursday, March 06, 2008

One Minute Manager

For the past few days, I'm reading "One Minute Manager balances Life & Work".

The four Parameters (Stress Moderators) are:

1. Autonomy : The availability of many choices that give good control in life
2. Connectedness : Strong positive relationship at home, at work and in the community
3. Perspective: The direction, purpose and passion about what one is doing.
4. Tone: The feeling about the body, energy level, physical well being and appearance.

If you lack in any one of these parameters, It will seriously affect the other parameters(domino effect).

Wednesday, March 05, 2008

Mind, Intellect & Ego

For the Past 2 Weeks, I'm taking Meditation Classes. These are some of the things which I learned from my Guru.

Introduction

In vedic times yogis investigated the deepest nature of human being. They developed a coherent filosophy on human extistence on the material, psychological and spiritual levels. The vedic model of human psychology consists of five concentric circles or koshas representing body, mind, ego, intellect, and self. The model introduces basic concepts for the understanding of human consciousness and various branches of yoga.

Body

The cerebrospinal system is the first part of the organism to be developed after conception. From it the entire bodily form comes out. This system is a great generator of electrical energy that is constantly supplied to the internal organs by a network of nerves that serve as connectors. All the cells in the body are kept alive by a flow of energy (prana). Nerves connect the brain and spine with the five sense organs (eyes, ears, nose, tongue, skin), and the five work organs (anus, genitals, legs, hands, vocal chords). The functiong of the entire human body is controlled by the cerebrospinal system, and the psychic centers are located in it.

Mind

The combination of brain, breath, nerves, sense organs, and work organs functions as a unit inside the body which is working with the mind. Mind is the tool of consciousness that enables perception through the senses. Mind uses brain to process the signals that are coming in through the senses, but mind is not a product from the brain. This is illustrated by organisms that have no real brain but still they have a mind that enables them to sense changes in the environment.

Mind is very active and associative, it can jump from present to past and from one situation to another. If you have tried to sit and remain silent inside you have experienced that many thoughts arose no matter how much you tried to be without them. These thoughts sprout from the activity of the mind. The activity of the mind is closely related with the pattern of breathing. The science of controlling breath is known as pranayama, a branch of Hatha Yoga. By practicing pranayama, the breath becomes calm, images do not disturb the mind, and the internal dialogue stops

Ego

Ego is the illusion that I exist as a separate individual being. Ego is the one which assumes the responsibility for the body and identifies with the body. When the body breathes, he says, "I am breathing". Ego takes a name, and becomes Mr. such and such and all social relations are acted out by ego. Whereas mind is very daring, ego is very much afraid for death. Whenever any problem comes to the body, ego becomes very alert and remains in the body. And the more there is danger of existence, the more strong the ego becomes. There are stories of children who were completely neglected and left behind. They developed into some kind of chivalrous fighting heroes, and they also became masters in certain subjects and people of great intelligence. Most of the time, only for survival of their ego, they had to struggle, and they learned from their struggle how to be strong. This way, ego is the one that creates strength. All strength that I have comes from my ego. This part of the ego which gives this strength is called will.

Modern school has become a training place for creating more and more ego, because there is competition all the time. Who does it first? Who is the best? Ego always tries to say, "I am better than you", "I am holier than you". In ancient days they had an education system that did not let the ego grow beyond a particular limit. The child had to go and live with the family of a teacher as a member of the family (gurukul). The wife of the teacher was responsible for providing all food, and nobody was allowed to bring other food. And parents were not allowed to bring gifts in order to treat all pupils equal, and make them feel that everyone is equal.

Intellect

Intellect is the tool of consciousness that contains knowledge that is accumulated in this live and in past life, and by seven previous generations as well. Intellect carries with it the past and the present, and also speculates about the future. Intellect helps ego with advice and information but the final decision comes from ego. Ego can say, "I like it" and although intellect may disapprove ego may decide "O.k., I don't believe that this is right, but I don´t want to follow all these rules and regulations, I'll break the law". If intellect is too much dominating then information in books is considered more important than own experience.

Mind and Intellect serve Ego

When ego is the king in the body, intellect is the prime-minister, and mind is the public relation officer, roaming here and there, making contacts, gathering information. Most of the time only mind is dominant. But sometimes ego is also very dominant. And intellect is only in the beginning, when you start, at that time it comes and tries to show you how you go. But after that, mostly it is the mind which takes the lead.

Self

There is a divine spark of consciousness in each of us, the innermost center of the 5 koshas. This divine spark or self is in bliss, untouched by any of the events that happening around. Animals, plants, and even objects, have such a spark in them. In deep sleep and in samadhi, mind, ego and intellect are inactive. Therefore, deep sleep and samadhi are very similar, however, in deep sleep we are not conscious of anything whereas in samadhi consciousness remains during the absence of mind, intellect and ego. The self likes to enjoy the drama of life. It is because of unfulfilled desires of ego that the combination of self, intellect, ego and mind incarnate over and over again, until the ultimate desire to merge with god is fulfilled. Then all individuality, including the individual self, is dissolved into the cosmic consciousness.

Courtesy: http://www.sanatansociety.org/yoga_and_meditation/ego_mind_intellect_yoga.htm

C++ Standard: C++0x

A talk on C++0x given by Bjarne Stroustrup at the University of Waterloo

Link: http://www.csclub.uwaterloo.ca/media/C++0x%20-%20An%20Overview.html

Tuesday, March 04, 2008

SuperbTips for an Exceptional & Powerful Life!

1.) Take a 10-30 minute walk every day. And while you walk, smile. It is the ultimate antidepressant.
2.) Sit in silence for at least 10 minutes each day. Buy a lock if you have to.
3.) Always pray and make time to exercise.
4.) Spend more time with people over the age of 70 And under the age of Six.
5.) Eat more foods that grow on trees and plants And eat less foods that are manufactured in Plants.
6.) Drink green tea and plenty of water. Eat broccoli, almonds & walnuts.
7.) Try to make at least three people smile each day.
8.) Clear your clutter from your house, car, desk and let new and flowing energy into your life.
9.) Don't waste your precious energy on gossip, issues of the past, negative thoughts or things you cannot control.
Instead, Invest your energy in the positive present moment.
10.) Realize that life is a school and you are here To learn. Problems are simply part of the curriculum
That appear and fade away like algebra class .......but the lessons you learn will last a lifetime.
11.) Eat breakfast like a king, lunch like a prince And dinner like a college kid with a maxed out charge Card.
12.) Life isn't fair, but it's still good.
13.) Life is too short to waste time hating anyone.
14.) Don't take yourself so seriously. No one else does.
15.) You don't have to win every argument. Agree to disagree.
16.) Make peace with your past so it won't screw up the present.
17.) Don't compare your life to others'. You have no Idea what their journey is all about.
19.) No one is in charge of your happiness except you.
20.) Frame every so-called disaster with these Words: 'In five years, will this matter?'
21.) Forgive everyone for everything.
22.) What other people think of you is none of your Business.
23.) Time heals almost everything. Give time, time!
24.) However good or bad a situation is, it will Change.

Courtesy: Orkut [Self-Help books & material Community]

Monday, March 03, 2008

Meditation Links

http://www.shanemagee.com/
http://www.srichinmoybio.co.uk/blog/