Sunday, February 4, 2007

Enterprise 1.0 vs. Enterprise 2.0

From The Software Abstractions Blog..
What exactly is "Enterprise 2.0"? The main themes that are emerging, seem to be products/technologies that:
  1. facilitate better communication
  2. harness collective intelligence and innovation
  3. enable user-generated applications (enterprise mashups !)
The communication aspects present the most powerful paradigm-shift.





(Courtesy: Software Abstractions blog)

Source: click here

59 years ago on a day like today

In 1948, on a day like today, with the participation of representatives from many countries, the Lion flag was hoisted high in the blue skies proudly marking the symbolic gesture of independence.

The Lion Flag:


More Details:
About Sri Lanka
About Sri Lankan history

Saturday, February 3, 2007

5 Ways to spot a liar!

Little white lies of all sorts are tossed our way daily. These may not matter a whole lot, but real whoppers do. Sometime back, I read an article on RD regarding how to spot a liar. I know I am not very good at spotting those. Here are the five tips from experts from that article :)

1. Hear the Voices
- Voice (pitch) changes may well indicate deceit.
- And so does change in speech rate, breathing pattern, etc.

2. Watch Those Words
- how do we spot lies in written material, letters, resumes, etc. ??
- Believe it or not, people have developed software to spot deception in written content. One example is LIWC (Linguistic Inquiry and Word Count) by some people at the University of Texas.
- Some tips.
-- liars tend to use fewer first person pronouns
-- liars tend to use fewer exclusionary words - but, nor, except, whereas (they have trouble with complex thinking)

3. Look Past Shifty Eyes
- If people look away while answering something that should be easy to answer, that may be an indication (this may not be always true)...watch out for eye gaze

4. Bet Better at Body Language
-Observe the total person and compare it with his/her usual body language
--ex: a quiet person who talks a lot or a person who talks a lot who is now quiet

5. Check for Emotional "Leaks"
-The micro-expressions that flit across people's faces often expose what they're truly feeling or thinking as opposed to what they'd like us to believe. It isn't the frequency of a smile that matters, but the type of smile!

Professionals trained in the art of lie detection use all these techniques.

Can you spot a liar? Take the quiz!

Friday, February 2, 2007

Introduction to C++ Programming [Part 4]

Previous Related Posts: Part1 Part2 Part3

Operators

An operator is a symbol that causes the compiler to take an action. Operators act on one or more operands. There are several types of operators.

· Arithmetic operators

· Assignment operators

· Relational operators

· Logical operators

Arithmetic operators

Operator

Description

Example

+

Addition

3 + 20 evaluates to 23

-

Subscription

10 – 4 evaluates to 6

*

Multiplication

2 * 13 evaluates to 26

/

Division

15 / 2 evaluates to 7

%

Modulus

17 % 3 evaluates to 2

++

Increment

i++ is equivalent to i = i + 1

--

decrement

i-- is equivalent to i = i - 1

++ and -- are unary operators, meaning that they operate on a single operand. Each of these operators has two versions, post and pre. Let’s try to understand this by the following example.

e.g.:

//post increment
x = 10;
y = 20;
z = (x++) + y; //z evaluates to 30
a = x + y; // a evaluates to 31

//pre increment
x = 10;
y = 20;
z = (++x) + y; //z evaluates to 31
a = x + y; // a evaluates to 31

Operator precedence

Precedence is the order in which a program performs the operations in a formula. Each operator has a precedence value. These precedence values are used to evaluate expressions. If one operator has precedence over another operator, it is evaluated first. The following table shows the operator precedence in the decreasing order.


( )

Prefix ++ --

* / %

+ -

< <= > >=

== !=

||

&&


e.g.:

z = 2 + 5 * 3; //17
z = (2 + 5) * 3; //21

Assignment operators

Operator

Example

=

a = 5;

*=

a *= 5; //equivalent to a = a * 5;

+=

a += 5; //equivalent to a = a + 5;

-=

a -= 5; //equivalent to a = a - 5;

/=

a /= 5; //equivalent to a = a / 5;

%=

a %= 5; //equivalent to a = a % 5;

Relational operators

Operator

Description

==

Equal to

<=

Less than or equal to

>=

Greater than or equal to

<

Less than

>

Greater than

!=

Not equal to

Logical operators

Operator

Equivalent to

Example

&&

AND

(x > 5 ) && (x <>

||

OR

(x <> 25) //x is less than 5 or greater than 25

!

NOT

!(x > 5) //equivalent to (x <= 5)


Escape Characters

The C++ compiler recognizes some special characters for formatting. The following table shows the most common ones. You put these into your code by typing the backslash (called the escape character), followed by the character.

Character

Description

\n

new line

\t

tab

\b

backspace

\"

double quote

\'

single quote

\?

question mark

\\

backslash

\a

alert

e.g.:

cout << “This is a test. \n”;
cout << “Now alarm \a will ring\n.”;

Control Structures

If Statement

If statement is used to execute a certain set of statements based on an expression. There are several forms of if statement. Most commonly used forms are listed below. You don’t need to use braces if there is only one statement.

if (expression)
{
//statements
}

if (expression)
{
//statements
}
else
{
//statements
}

if (expression)
{
//statements

}
else if (expression2)
{
//statements

}

e.g.:

if (x != 0)
{
cout <<”x is not equal to zero\n”;
}
else
{
cout <<”x is equal to zero\n”;
}

Conditional (Ternary) operator:

The conditional operator (?:) is C++'s only ternary operator; that is, it is the only operator to take three terms. The conditional operator takes three expressions and returns a value.

Syntax:

(expression1) ? (expression2) : (expression3)

This line is read as "If expression1 is true, return the value of expression2; otherwise, return the value of expression3." Typically, this value would be assigned to a variable.

e.g.:

int x = 5;
int y = 10;
int z = (x > y) ? y : x; //since x > y is false, value of x is assigned to z.

While loop

A condition is tested, and if it is true, the body of the while loop is executed. When the conditional statement fails, the entire body of the while loop is skipped. It is possible that the body of a while loop will never execute. The while statement checks its condition before executing any of its statements, and if the condition evaluates false, the entire body of the while loop is skipped.

Syntax:

while (condition)
{
//statements
}

e.g.:

int iCount = 0;
while (iCount < 2)
{
cout << “Count is “ << iCount <<"\n";

iCount++;
}

Output:

Count is 0
Count is 1
continue
and break statements:

Usually break statement is used to break out of any loop based on a certain condition and continue statement is used to skip the current iteration based on a certain condition.

e.g1. (break):

int iCount = 0;
while (iCount < 2)
{
cout << “Count is “ << iCount <<"\n";
if ( iCount == 0)
{
cout <<”Breaking out of the loop\n”;
break;
}
iCount++;
}

Output:

Count is 0
Breaking out of the loop

e.g2. (continue):

int iCount = 0;
while (iCount < 3)
{
cout << “Count is “ << iCount <<"\n";
iCount++;
if ( iCount == 1)
{
cout <<”Continue with next loop\n”;
continue;
}

cout << ”Next count is “ <<iCount << "\n";

}

Output:

Count is 0

Continue with next loop
Count is 1
Next count is 2
Count is 2
Next count is 3

Do-While Loop

The do-while loop executes the body of the loop before its condition is tested and ensures that the body always executes at least once.

Syntax:

do
{
//statements
}
while (condition);

e.g.:

int iCount = 0;
do
{
cout << “Count is “ << iCount << "\n";

iCount--;
}
while (iCount > 0);

Output:

Count is 0

for Loop

You'll often find yourself setting up a starting condition, testing to see if the condition is true, and incrementing or otherwise changing a variable each time through the loop. In such situations, for loops are more convenient way to iterate. A for loop combines the three steps into one statement. The three steps are initialization, test, and increment.

Syntax:

for (initialization; test; increment/decrement)

{

//statements

}

e.g.:

for (int iCount = 0; iCount < 2; iCount++)

{

cout << “Count is “ << iCount <<"\n";

}


Output:
Count is 0
Count is 1

switch Statement

switch statement is a more convenient way of branching than if statement, when you want to branch to a set of statements based on several possible values.

Syntax:

switch (expression)
{
case value1:
//
statements
break;
case value2:
//statements
break;

default:
//statements
}


Expression is any legal C++ expression. If one of the case values matches the expression, execution jumps to those statements and continues to the end of the switch block, unless a break statement is encountered. If nothing matches, execution branches to the optional default statement. It is important to note that if there is no break statement at the end of a case statement, execution will fall through to the next case statement. This is sometimes necessary, but usually is an error.

e.g.:

int iScore; //assume iScore is assigned a value through cin

cout << “Score is “ << endl;

switch (iScore)

{

case 5:

cout << “Performance is average” << endl;

break;

case 10:

cout << “Performance is good” << endl;

break;

default:

cout << “Invalid Score” < < endl;

}

Thursday, February 1, 2007

A simple way to download videos from sites like YouTube

There's a really simple way to download videos from sites like YouTube. This's what you need to do:
1. Copy the URL that appear in the address bar and paste it here.
2. Rename the file to have .flv extension.
3. View it in a flash video viewer[Example: FLV Player 1.3]!

All time favorites..

All time favorites at Piled Higher and Deeper .. :)

Motivation graph
Work output graph

Function Pointers and Functors in C++ [in 5 minutes]

Function pointers are very useful technique to provide late binding, to prevent switching and to implement callbacks in C/C++. Here are some example cases of C/C++ function pointers and C++ functors which can be used to eliminate switches inside your code. (Remember the design principle? The code should be closed to modification but open to extension!)

Here's the C style of doing it:


#include <stdio.h>

/* calculate2, calcualte2, etc are functions
with the same prototype */
int calculate1(int val)
{
return val*val;
}

int calculate2(int val)
{
return val+val;
}

/* passing a function pointer */
int useCalculate(int (*fnPtr)(int), int someVal)
{
return fnPtr(someVal);
}

/* using the function which takes a function pointer */
int main()
{
printf("Using calculate1 = %d\n",
useCalculate(calculate1, 10));
printf("Using calculate2 = %d\n",
useCalculate(calculate2, 10));
return 0;
}


Here's the C++ style of doing it (with method pointers):

#include <iostream>

using namespace std;

//calcualte1, calculate2 are methods with the same prototype
class Util
{
public:
int calculate1(int val)
{
return val*val;
}
int calculate2(int val)
{
return val+val;
}
};

//the above prototype is taken as a formal argument here
class UseUtil
{
Util utilObj;

public:
int useCalculate(int (Util::*methodPtr)(int), int someVal)
{
return (utilObj.*methodPtr)(someVal);
}

};

//using the method with method pointer argument
int main()
{
UseUtil useUtilObj;
cout << "Using Calculate1 = " <<
useUtilObj.useCalculate(&Util::calculate1, 10) << "\n";
cout << "Using Calculate2 = " <<
useUtilObj.useCalculate(&Util::calculate2, 10) << "\n";
return 0;
}


Here's the C++ style of doing it again (but with functors!):

#include <iostream>
using namespace std;

//it takes a "stateless functor class"
template
class UseUtil
{
public:
int useCalculate(UtilFunctor calculate, int someVal)
{
return calculate.operator()(someVal);
}

};

//out of line way
//int UseUtil::useCalculate(
// UtilFunctor calculate, int someVal)
//{
// return calculate(someVal);
//}

//first functor class
class Cal1
{
public:
int operator()(int val)
{
return val*val;
};
};

//second functor class
class Cal2
{
public:
int operator()(int val)
{
return val+val;
}
};

int main()
{
UseUtil useUtilObj1;
Cal1 calObj1;
cout << "Using Cal1 = " <<
useUtilObj1.useCalculate(calObj1, 10) << "\n";
UseUtil useUtilObj2;
Cal2 calObj2;
cout << "Using Cal2 = " <<
useUtilObj2.useCalculate(calObj2, 10) << "\n";
return 0;
}