Wednesday, November 27, 2013

My first ruby gem horoscope is live

I wanted to write a rubygem on my own for a long time. Never had the time really to write one. However, recently I had some spare time during which I wrote this gem called horoscope. This gem will help drafting the horoscope of a person given the birth date, time and the place. Source is hosted at Github. As with every other open source project out there, feel free to fork it and add more to your liking

Screenshot at Github


Proud to release this and I am planning to add more features to this. Also, planning to release different gems. If you want something particular or specific, don't be shy, add it in the comments section and I would be more than happy to contribute!

Cheers!
Bragboy

Friday, November 22, 2013

Creational Design Patterns

Creational Design Patterns abstracts the instantiation of the objects. A simple question may occur to you: Why can't I just create a new Object using the new keyword and be happy thereafter. The answer is Yes, you can create an object. But you need to ask a couple of important design questions before conclusively saying Yes.
  1. Is my design flexible?
  2. Will my design promote re-usability? 
More often than not, instantiating an object with a new keyword would not result in a good design. We need to see how we can design a system that is both flexible and that promotes reusability. There are totally five creational design patterns which we will see in details one by one. They are,
  1. Abstract Factory
  2. Builder
  3. Prototype
  4. Factory Method
  5. Singleton
More on each of them in the following posts.

Monday, November 18, 2013

Tree Traversal in C++

#include <iostream> 
#include <queue> 

using namespace std;

struct node 
{ 
    int data; 
    struct node* left; 
    struct node* right; 
}; 

typedef struct node* nodeptr;

void display_preorder(nodeptr root) 
{ 
    if(!root) return; 
    cout << root->data << " "; 
    display_preorder(root->left); 
    display_preorder(root->right); 
} 

void display_inorder(nodeptr root) 
{ 
    if(!root) return; 
    display_inorder(root->left); 
    cout << root->data << " "; 
    display_inorder(root->right); 
} 

void display_postorder(nodeptr root) 
{ 
    if(!root) return; 
    display_postorder(root->left); 
    display_postorder(root->right); 
    cout << root->data << " "; 
} 

void display_levelorder(nodeptr root) 
{ 
    if(!root) return; 

    queue<nodeptr> myq; 
    myq.push(root); 

    while(!myq.empty()) 
    { 
        nodeptr tmp = myq.front(); 
        myq.pop(); 
        cout << tmp->data << " "; 
        if(tmp->left) myq.push(tmp->left); 
        if(tmp->right) myq.push(tmp->right); 
    } 
    cout << endl; 
} 

int main() 
{ 
    node g = {7, NULL, NULL};
    node f = {5, NULL, NULL};
    node e = {3, NULL, NULL};
    node d = {1, NULL, NULL};
    node c = {6, &f, &g}; 
    node b = {2, &d, &e}; 
    node a = {4, &b, &c}; 

    cout << "pre order   :: "; display_preorder(&a);  cout << endl;
    cout << "in order    :: "; display_inorder(&a);   cout << endl;
    cout << "post order  :: "; display_postorder(&a); cout << endl;
    cout << "level order :: "; display_levelorder(&a); 

        return 0; 
}
 
pre order   :: 4 2 1 3 6 5 7
in order    :: 1 2 3 4 5 6 7
post order  :: 1 3 2 5 7 6 4
level order :: 4 2 6 1 3 5 7