Thursday, September 13, 2012

Excute/import a schema to DB on sqlite

Executing or importing a schema to DB on sqlite is really easy.

sqlite3.exe test.db < schema.sql

where test.db is the test database.

Saturday, November 12, 2011

Predefined variable __func__ in C++11

In C++11, every function has a local predefined variable __func__ that looks as follows:

static const char __func__[] = "function-name";
This variable can for example be used for logging purposes.

Range based for loop in C++11

Range based for loop allow easy iteration through list of elements. This type of loop will work for C-style arrays, initializer lists and any type that has a begin() and end() function that returns iterators.
In the below example, the range-based for loop will then iterate over every element in this list and increment its value by 2.
int arr[] = {1,2,3,5};
for(auto &i : arr) {
    i += 2;
} 

std::vector<int> myVector (arr, arr+4);
for (auto j: myVector)
   std::cout << j<< std::endl;
To support the range-for loop, the user defined types (classes) must have suitable begin() and end() functions.

Tuesday, November 8, 2011

Strongly typed enum in C++11

C++11 introduces the enum class which are strongly typed means, they are type-safe. Enum's are interpreted as integers and thus you can compare enumeration values from completely different enumeration types.

enum class MyEnum
{
VALUE1,
VALUE2 = 10,
VALUE3
};
So this is not legal in C++11:
if (MyEnum::VALUE3 == 11) {...}

By default, the underlying type of an enumeration value is an integer, but this can be changed as follows:


enum class MyEnumLong : unsigned long
{
LVALUE1,
LVALUE2 = 10,
LVALUE3
};
Enum class type is user defined so we can define operators. By default Enum class has only assignment, initialization, and comparisons operator.
enum class color { green, yellow, red };
color& operator++(color& t)
// prefix increment: ++
{
switch (t) {
case color::green: return t = color::yellow;
case color::yellow: return t = color::red;
case color::red: return t = color::green;
}
}
color next = ++light; // next becomes color::green

Saturday, November 5, 2011

Use of namespace in c++

From Professional C++ 2nd edition:
Namespaces address the problem of naming conflicts between different pieces of code.
#include "namespaces.h"
#include <iostream>
namespace mycode {
    void foo() {
        std::cout << "foo() called in the mycode namespace" << std::endl;
    }
}
To call the namespace-enabled version of foo(), prepend the namespace onto the function name by using :: also called the scope resolution operator as follows.
mycode::foo();    // Calls the "foo" function in the "mycode" namespace

You can also avoid prepending of namespaces with the using directive. This directive tells the compiler that the subsequent code is making use of names in the specified namespace.

A single source file can contain multiple using directives, but beware of overusing this shortcut. In the extreme case, if you declare that you’re using every namespace known to humanity, you’re effectively eliminating namespaces entirely!

The using directive can also be used to refer to a particular item within a namespace. For example, if the only part of the std namespace that you intend to use is cout, you can refer to it as follows:
using std::cout;

Subsequent code can refer to cout without prepending the namespace, but other items in the std namespace will still need to be explicit:
using std::cout;

cout << "Hello, World!" << std::endl;

Sunday, May 2, 2010

Friday, March 19, 2010

Team work and team building essentials

A team building success is when your team can accomplish something much bigger and work more effectively than a group of the same individuals working on their own. You have a strong synergy of individual contributions. But there are two critical factors in building a high performance team.

1. The first factor in team effectiveness is the diversity of skills and personalities. When people use their strengths in full, but can compensate for each other's weaknesses. When different personality types balance and complement each other.

2. The other critical element of team work success is that all the team efforts are directed towards the same clear goals, the team goals. This relies heavily on good communication in the team and the harmony in member relationships.

Problems of team work
----------------------------------

In real life, team work success rarely happens by itself, without focused team building efforts and activities. There is simply too much space for problems.

* For example, different personalities, instead of complementing and balancing each other, may build up conflicts.

* Or even worse, some people with similar personalities may start fighting for authority and dominance in certain areas of expertise.

* Even if the team goals are clear and accepted by everyone, there may be no team commitment to the group goals or no consensus on the means of achieving those goals: individuals in the team just follow their personal opinions and move in conflicting directions.

* There may be a lack of trust and openness that blocks the critical communication and leads to loss of coordination in the individual efforts.

Additional team building ideas, techniques, and tips you can try when managing teams in your situation.

  • Make sure that the team goals are totally clear and completely understood and accepted by each team member.
  • Make sure there is complete clarity in who is responsible for what and avoid overlapping authority. For example, if there is a risk that two team members will be competing for control in certain area, try to divide that area into two distinct parts and give each more complete control in one of those parts, according to those individual's strengths and personal inclinations.
  • Build trust with your team members by spending one-on-one time in an atmosphere of honesty and openness. Be loyal to your employees, if you expect the same.
  • For issues that rely heavily on the team consensus and commitment, try to involve the whole team in the decision making process. For example, via group goal setting or group sessions with collective discussions of possible decision options or solution ideas. What you want to achieve here is that each team member feels his or her ownership in the final decision, solution, or idea.
  • When managing teams, make sure there are no blocked lines of communications and you and your people are kept fully informed.
  • Don't miss opportunities to empower your employees. Say thank you or show appreciation of an individual team player's work.
  • Don't limit yourself to negative feedback. Be fare. Whenever there is an opportunity, give positive feedback as well.