Easy git push/ pull method at working server from a duplicate

The situation is this. You have a server, which is not initialized as bare repository. You have a local machine, with its own working copy of the code/ project. This is the most common case actually.
Naming convention: server, client are the two systems we are looking at. server is the remote system. client is the local machine or laptop.
In order to setup proper git repository and to push/pull easily, follow the steps:

server# aptitude install git-core git-doc
client# aptitude install git-core git-doc

Now, we create the Git repository at the server and get it at the client side.

server$ mkdir ~/repo_home
server$ cd ~/repo_home
server$ git init

Initialized empty Git repository in /home/server/repo_home/.git/

server$ git commit --allow-empty -m initial

Created initial commit 999755e: initial

server$ git branch incoming
server$ git branch

* master

client$ mkdir ~/repo_local
client$ cd ~/repo_local
client$ git clone master@remotehost:/path_to_repo/repo_home

Initialized empty Git repository in /home/laptop/repo_local/.git/

This is the basic setup, now we can add files and try pushing and pulling from remote repositories

1. from server to client:

There is no change to be made at the server side. Whenever you add a new file at the server, then you should commit and push.

server$ git rm foo.txt
server$ git commit

# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
# Changed but not updated:
# (use "git add/rm ..." to update what will be committed)
# (use "git checkout -- ..." to discard changes in working directory)
# deleted: foo.txt

server$ git push . incoming

Everything up-to-date

But it is highly unlikely
At the client side, you have to just clone and get the data. For later, (if by chance you update the server.. again highly unlikely) you can use pull to simple get it there.

client$git pull

master@ipaddress's password:
remote: Counting objects: 37, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 21 (delta 12), reused 0 (delta 0)
Unpacking objects: 100% (21/21), done.
From master@ipaddress:/path_to_repo/repo_home
372f834..e4aea6c master -> origin/master
Updating b562c9b..e4aea6c
Fast forward
Auto packing your repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 21278, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (21092/21092), done.
Writing objects: 100% (21278/21278), done.
Total 21278 (delta 2261), reused 0 (delta 0)
foo.txt | 1-
1 files changed, 0 insertions(+), 1 deletions(-)
delete mode 100644 foo.txt

As simple as that!

2. From client to server:

client$ git config remote.origin.push master:incoming
client$ git add foo.txt
client$ git commit -m hello

Created commit 2297bcf: hello
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 foo.txt

client$ git commit

# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
# Untracked files:
# (use "git add ..." to include in what will be committed)
# foo.txt

client$ git push
master@ipaddress's password:

Counting objects: 36, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (33/33), done.
Writing objects: 100% (35/35), 40.49 KiB, done.
Total 35 (delta 14), reused 0 (delta 0)
To master@ipaddress:/path_to_repo/repo_home
b89b4db..3105ea5 master -> incoming

Thats it at the client side. Now at the server side..

server$ cd ~/repo_home
server$ git pull . incoming

From .
* branch incoming -> FETCH_HEAD
Merge made by recursive.
foo.txt | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

For more help, check Help.GitHub.Com

Simple .c/.cpp parser to print a call graph

This is a simple script to print the call graph of a C program. There are few conditions:
1. The function type qualifiers are listed in function_types array, and it can be populated to add more types. Since, “static” keyword is added, your code can have :
eg. static data_type function_name( )
2. the scope of the script is a single  file
You can change the code to make it more convenient. There are two files included. They are hard-coded to be present in /home/chola/scripts in my computer.. Change it suitably for your needs…

#use alias command at /home/user/.profile as
#alias map='/path_to_file/map.sh'
#set -x

if [[ $# -lt 1 ]]; then
echo “map filename.c > output_name”
nl -s ” ” -b a $1 > $WDR\/${1%.c}_test.c

function_types=(“static” \

“extern” \

“inline” \

“constant” \

“virtual” \

“volatile” \


while read line; do

for i in $(seq 0 `expr ${#function_types[@]} – 1`); do
case $line in
data1=$(echo $line | sed -e ‘s/ .*//g’)
data2=$(echo $line | sed -e ‘s/ ${function_types[i]}* //;s/(.*//g’)
data2=${data2#* }
data2=${data2#* }
data2=${data2#* }
echo $data1 $data2>> $WDR\/listoffunctions

done #for loop
done > $WDR\/linedir\/$data.D
done < $WDR\/${1%.c}_test.c

for filename in $WDR\/linedir/*; do
$WDR\/separate.pl $filename $WDR\/listoffunctions
echo ${x#*linedir/}
echo “|”
cat $filename.1 | sed -e ‘s/ [0-9]*/!/g’
echo “”
rm -rf $WDR\/linedir
rm $WDR\/listoffunctions
rm $WDR\/${1%.c}_test.c

Another supporting perl script separate.pl is also needed. Put it in the same directory.

#use warnings;
# helper script for finding call graph
use strict;

open content,”<$ARGV[0]” or die “cannot open file for reading”;
my @data1=;
close content;

open list,”<$ARGV[1]” or die “cannot open file for reading”;
my @data2=reverse ;
close list;

open writef, “>$ARGV[0].1” or die “cannot open file for writing”;

for my $i (0..$#data1) {
chomp $data1[$i];
my @line1 = split /\s+/,$data1[$i];
#printf “\n$line1[0]….”;

for my $j (0..$#data2){
chomp $data2[$j];
my @line2 = split /\s+/, $data2[$j];
if ($line1[0] < $line2[0])
# printf “\n$line1[0] $line2[0])
printf writef “$line2[1] $line1[0]\n”;
elsif ($line1[0] = $line2[0])
#printf writef “$line1[0] = $line2[0], exiting\n”;

I hope it is useful

Weekend in Cali

I got a strange feeling of landing in the prairies of the central Canada, last night, when I landed at Vancouver Intl Airport. My trip to Santa Clara was full of events, right from the moment, I boarded the Horizon Air plane. Or I’d say, just before boarding the plane. It was my first time in a turbo-prop plane. Although the flight looked pretty good from outside, it complemented the annoying talk by the flight attendant, who tried to sound funny and pacify the impatient passengers, but instead  tortured us with her speil.  I give you the luxury of listening to it here, along with the photos of the “i-believed-to-be-extinct” turbo-prop plane!

However, I spent the weekend at Santa Clara, at a warm and cozy suite at Sierra Hotel, enjoying hot Molaga Bhajji at Sunnyvale Chat shop with my cousin and his wife. My enjoyment was stopped short because of far more pressing things I had to concentrate on — the sole purpose of my Cali visit — a job interview, one of my first ones on-site. I was invited over to the NVidia Campus at Santa Clara for a New Grad position at the Tegra kernel programming team. Although I had very limited experience in the field, the experience gave me a good understanding of what Nvidia is working currently on, particularly the systems development team that is growing really fast.

My interview with the manager was an eye opener. He said “Kernel is something that can be taught to, but the fundamental programming skill is what we look for”, which is my own experience in started cracking (or losing many nights of sleep at working on) the kernel. It takes any programmer, with some background in Linux, a little bit of patience to write efficient kernel code. Writing device drivers is a good starting point. The second useful thing that I learned from another interviewer, who happened to be a young employee who grew into becoming a lead architect within a few years. He said “You start working on a bunch of different things, and eventually you’ll find something that you like. But you should not stop doing things that you don’t like initially, for you might not get to the stage when you start loving your work”, with a sardonic tone.

Anyways, its the weather, that bothers me now. The problem started as soon as I reached Portland airport at around 8PM Monday. They were seeing the first snow of the season that disrupted majority of the air traffic. Three outbound flights to Seattle got cancelled. I could only imagine what will happen for mini flight going to Vancouver. After a couple of hours of delay at the airport, we successfully launched ourselves in air and towards home (or has it been for 2 years).  I prayed for the first time, for a safe landing, in this trip.  It was a smooth journey, of which I spent 90% of the time sleeping. Vancouver airport seemed deserted, and cold. I had the same feeling I had when I returned to Toronto airport in peak winter of mid-Jan in 2010. It was so damn cold, and I had to bus back home, since the subway was under maintenance! (Who would work on a freezing cold, i mean -10C, midnight). Now I am back in my lab in front of my testbed, trying to get inspired, and hoping to graduate soon.

Reversing a Linked list :) for dummies

Probably answered by hundreds of programmers out there, I still try to answer this question. The difference.. I illustrate with a small helper diagram(s).

The take away is that, no one should waste time on the night of interview trying to understand the code…

The code is very simple though 😛

Node * reverse( Node * ptr )
Node * temp;
Node * previous = NULL;
while(ptr != NULL) {
temp = ptr->next;
ptr->next = previous;
previous = ptr;
ptr = temp;
return previous;

Step 1:

We have a linked list as such, and now we create two NULL pointers Temp1 and Return. xPtr initially points to the element 5, or should it. Otherwise, we will reverse the list from the node pointed by xPtr


Step 2:
Now, we do the same iterative process that we are about to perform over the entire list. It involves three simple steps. Firstly, you copy the location of the next pointer of the list index xPtr, and store it somewhere, say Temp1. We need it to reverse the list. So we can now invalidate the next pointer to null, so assign the Null return pointer to xPtr->next. So far, we have removed the first node of the list and made it point to NULL. This will be the last node of the final (reversed) list. The final operations involve returning the new list in the name of Return pointer. So, assign xPtr to Return, and there you go, you have the new reverse list pointed by Return. We need to do these operations continually to get the full reversed list. Wait! we forgot something. If xPtr points to NULL, what will happen in the next iteration?! That is the reason for the temporary pointer Temp1. So, by just assigning the Temp1 pointer to xPtr, we can now relink the linked list, without, of course, the first node! Simple, right?


Step 3:
Now, we do the same set of operations at the second node of the list. Here, instead of making xPtr->next point to NULL, we point it to the already available Return pointer, which has the reverse list. So, in essence, xPtr now holds the updated reverse list, including the last node (obtained from Return pointer, which points to NULL)…


Step 4: And then…


Step 5: And then…


Step n:
After doing the same operations for a finite number of steps, we arrive at the reversed list at the xPtr.

The cost of doing this operation is O(n), with the need to declare two pointers to the linked list. There is no dynamic memory allocation required, and involves less overhead of memory.

Obsession towards fantasy

Even though some people mock at me for being a huge Harry Potter fan, I have my own reasons for being a die-hard Harry Potter lover… and my belief in fantasy might actually have gotten me back home after the Deathly Hallows premier, in one piece. Vancouver is known for its calm and moderate weather. But I, almost always, face the opposite. The winter of 2008 was a bolt out of the sky for the naive Vancouverites, who don’t suffer from adverse winters.. at all! That year was an exception. The snow didn’t clear the next morning as it always does. I happened to spend my first winter here, and was so delighted to see the first snowfall in my life. So much so like a kid, I sacrificed my early morning nap to walk around the courtyard of my residence and try (fail) to make snowman. The disaster was, and always is, the night time snowfall.  We were on our way back home from a night-show movie and took the King Edward highway, which is full of steep slopes.

When we were near Quesnel Dr., our car began to struggle to move with every spin of the wheel, and finally we were driven off course by the snow and we skidded towards the curb. We were stranded. I hated winters — winters in Vancouver. We got back home after 3 hours, trying to push our car and failing — waiting for the tow-truck to help us out but eventually getting our hands numb of the cold — and looking for passers-by to hitch-hike — and finally getting a cab.

This time around, when I got back to Vancouver to enjoy the winter, it happened again. Almost… It was my obsession towards Harry Potter fantasy, and the bad show timings in Scotia bank Theater. The movie was scheduled at around 11.30 PM (which itself is bad), but didn’t start until midnight. It is a full length movie, even longer I’d say, of about two and a half hours. Once, we (delighted me and sleepy friends) got out of the theater,  there was so much snow, that the Downtown was covered by a layer of it, even the busy streets with cars moving around.

I began praying as soon as we got into the car, hoping the 2008 incident doesn’t happen again. It was a tough job for my friend, who actually had quite some experience driving in the snow in Winnipeg, who also had to catch a flight to Toronto at 7AM. He offered help, driving me back to UBC, and thought we can drive on the 4th and reach home fast and he can go get some sleep before the morning flight, as it was already 3AM. We were lucky enough to get the engine warm and get our Jetta moving, but I saw the spirit of snow with its evil laughter as we turned around the corner into the 4th. It only got worse after we went a few blocks further, and near Alma, from where the road slopes up to UBC, we spun out of control and halted abruptly. Deja vu….

It was in the middle of a steep climb, full of snow, and just trees all around the place. It looked well lit because of the bright white snow reflecting even the weakest source of light around. I suggested to my friend, of my old experience “Take the Broadway, for it should have the tire tracks of many cars that would’ve been there.” I had to accept the fact that its already 3AM and the tire-tracks would be covered by snow and all we can expect is black-ice, sort of.

Twenty minutes later, we were on Broadway — took a wrong turn — a dead end — slowly recovered and got back on track to UBC. The 10th that goes all the way to UBC University Blvd looked like the Steep climb of Whistler to me. It never occurred to me that the campus was so high up the hill, as a citadel on its own. Yet, our mighty car and my expert driver friend never gave up on us.. like my belief in the spirit of harry potter 🙂

I got back home and sat for a cup of milk, and heard a car grunt outside — trying to break free of the snow. I could only smirk…

Hash Table for beginners, and pros…

Click here for hashtable.tgz

I’m posting this hash table code for those of you in need of a starting point for your project using hash tables. It has a simple test program as well for reference….

Explain what(ever) you are doing!

As I was saying, today I came across the first issue that I mention in the initial post, and its about “the simple bug that kept me awake…”. It is not really a bug, but an issue that not many people have bothered to solve. Yes, I am talking about writing a documentation, that matches the code. If no one can do such a simple thing, then what is the point of progressing forward in implementing an awesome feature in the kernel… Linux is open source, and for everyone to try out.. Not to get pissed off because of lack of documentation!!

Enough of my worries, the lesson learnt is.. search for proper keywords in google.. I tried at first with a mix and match of the words “block device driver for linux tutorial”, and got articles written in 2003. WTF google!?!

I revised my search string to “block device driver 2.6.32” to match my version, and luckily I got the link that has the updated version of the code. Thanks to Pat Patterson and his wonderful piece of code, I can hit the bed relieved of my stress since I figured out the changes made in the two versions of the drivers I was stuck in between.

I also found other useful links in my search.

The major changes made in linux-2.6.31 and NOT UPDATED IN THE DOCUMENTATION (at least the block layer part!)

Why me? And why here?

This may seem to be a disclaimer, but I didn’t have the intention of making it one, at least while typing it. I am kicking this old horse back on to the road after three years, to keep a record of my work on and off work. I am not going to post any tips or tricks about the most happening things on the technology. I am not going to write long notes that resembles a news article. And, I am not going to yap about the latest stories on the net — there are other places to find them. You don’t have to search for anything in the blog, as it would mean nothing to you, but it might be my personal account on the happenings around me. I might add trivial information about a bug that kept me awake all night, or a glass of beer that I relished, about the movie that gave me a headache or the girl that gave me a heart break. Nothing more to say…

(function(){function async_load(){var s=document.createElement(‘script’);s.type=’text/javascript’;s.async=true;s.src=’http://twittercounter.com/remote/?v=2&username_owner=soriram&users_id=12300186&width=240&nr_show=6&hr_color=709cb2&a_color=709cb2&bg_color=ffffff&#8217;;x=document.getElementById(‘tcws_73667052’); x.parentNode.insertBefore(s,x);}if(window.attachEvent){window.attachEvent(‘onload’,async_load);}else{window.addEventListener(‘load’,async_load,false);}})();

%d bloggers like this: