Archive for the ‘Uncategorized’ category

TechMyWay – New Blog

April 28, 2013

TechMyWay – New Blog

Much has happened since I graduated and started working. Here is a link to my new blog, which I try my best to keep updated. Follow me up there for future posts 🙂

Git add remote branch

September 27, 2012

A quick post on git (might help some):

To create a branch: git checkout -b branchName
#this also switches you to the newly created branch

Now to upload it to your remote repository use:
git push origin branchName
# if the branch with that name already doesn’t exist then it would be updated (as tested on GitHub)

A major milestone : 5k views

April 23, 2012

To all,

Thanks a lot for your love. My blog has crossed 5000 views. 🙂 🙂

K distance nodes in a Binary tree

February 3, 2012

For a Given node of a binary tree, print the K distance nodes.

For the solution, you can also refer to stackoverflow. This also tells that only one ancestor can be at K distance from a given node.

Source code: (written in C)

void K_dist_children(node * nd, int K)
{
// Base case
// The Kth child found
if(K==0)
{
printf("%d\n", nd->val);
return;
}

// K distance node from nd are at
// K-1 distance from children of current node
K_dist_children(nd->left, K-1);
K_dist_children(nd->right, K-1);
}

int K_dist_ancestor(node * cur,    //curent node
node * search, //node being searched
int K)
{
// If the node is found, return back the result
if (cur == search)
{
return K-1;
}

int n1, n2;

// recursively search for the node in the tree
n1 = K_dist_ancestor(cur->left, search, K);
n2 = K_dist_ancestor(cur->right, search, K);

// PS: n1 & n2 can't be non-(-1) at the same time

// if node found in any of the sub trees
if((n1 == -1) && (n2 == -1))
return -1;

// node found in right subtree
if((n1 == -1))
{
// the current node is at distance K
if(n2 == 0)
printf("%d", cur->val);

// return back the distance
return (n2-1);
}

// node found in left subtree
if((n2 == -1))
{
// the current node is at distance K
if(n1 == 0)
printf("%d", cur->val);

// return back the distance
return (n1-1);
}
}

void print_K_distance_nodes(node * root, node * search, int K)
{
// The structure of node is:
// struct node{
// int val;
// node * left;
// node * right;
// }

// Print the ancestor at distance K
K_dist_ancestor(root, search, K);

// Print the children at distance K
K_dist_children(search, K);
}

Hootsuite is amazing..

August 27, 2011

Hootsuite is amazing..

Count number of records

July 13, 2011

A very common people might face:

Count the number of records they have in their csv, and to make it interesting, check it from shell of your server..

Since you are accessing your server through an ssh connection via shell, running spreadsheet programs wouldn’t be of any help.. 😛

Now, a CSV is created by separating the data in a record by commas (,) and putting each record in a new line. Thus you can see the number of records by simply counting the number of lines in your file.

A simple bash command for that is:

wc -l filename.csv

Not much to write in that command..

Removing negative sign from excel column

June 29, 2011

I was recently writing an excel document for generating reports, but somehow the application converted one whole column of my data to negative values. I tried searching on internet and found one good method I wanted to share.

  • Write -1 somewhere and copy it (using Ctrl+C)
  • Select the column (or select the particular boxes) you want to make changes to.
  • Go to paste menu and select “paste special”.
  • Select “All” and “multiply” and press OK.
  • Done, that’s it. 🙂

The columns selected will be multiplied with -1 and the values will be stored there.

MySQL for newbies and non-techies

June 28, 2011

Database analysis and management is a very huge branch of marketing. I recently met many such people. But I was amazed to see that they had no knowledge of what they were doing or how. They just knew what to do and could do that without any problem.

So, my first question fired on them was, which database are you using? He quickly replied: “MySQL”.

I quickly took a look on the persons desktop and came to know that unlike us, they had a GUI interface to access the database. My inquisitiveness lead me to learn about two very good and highly used applications:

1. Navicat

2. SQLyog

I went further to try SQLyog. It was freely available from Google code. I tried the community edition. But it ain’t free and keeps asking you to upgrade your application!

The one thing that was amazing was that the query results were not eating up your space like on command line, where a ” select * ” could supposedly hang my computer. Moreover, the query results could be converted to text easily (very easily). Just write a query, convert result to text and copy it to your favorite text editor, email it, or just play around.

The marketing people were using it usually in email (for building reports).

Convert mysql database to csv

June 27, 2011

Recently I was asked by my friend to convert his whole database table to a something, so that he could distribute it around easily. As usual I created a sql dump for him by:

mysqldump -u username -ppassword database_name >table_data.sql

(Read more complicate ways at mydigitallife, which I didn’t try) 😛

But this wasn’t easy. The Data base was too large. The sql dump formed was of size 84MB!! A general windows mysql on xampp limits the import sql file to 25 MB!! So, this wasn’t at all a solution for him..

Then I came across a very brilliant page. The bash command given there is really awesome in terms of what it does. It uses a general mysql login, a sql query and sed parsing to put all the data in a .csv file which can be easily opened with any spreadsheet application.

Give it a try whenever you want to give your database to someone who doesn’t understand mysql. 😉

I used the command :

mysql -u root -psqlisgood mca -B -e "select * from \`company\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > data.csv

mysql username: root

mysql password: sqlisgood

query used: “select * from company”

P.S. You can try different queries to extract data as you want.. 😉

This also happens..

April 8, 2011

A 75-year old woman recently killed the internet facility to two countries. You might be shocked as greatly as I am.!
On March 28, Georgia and Armenia did not receive any internet connection because a Georgian lady, by mistake :O, damaged the optical fiber running between the two countries, and took it thinking it to be something valuable. I can understand, optical fibers can look really fascinating, but please, don’t think them to be some souvenirs, please.
The full report can be dug up at http://techland.time.com/2011/04/07/how-an-elderly-woman-cut-off-the-internet-in-two-countries/ from where I got the information too.. 😉