Wednesday, May 09, 2012

Git Notes



GIT

Git is free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Commands References

GIT Init:
mkdir ${project_directory}
cd ${project_directory}
git init
Add files:
git add <filename>
git add .
Remove files:
git rm <filename>
Rename files:
git mv <old.filename> <new.filename>
Ignore files:
cat .gitignore
Commit Files:
git commit -m 'Initial commit'
Diff files:
git diff                 # changes between index and working files
git diff --staged        # changes between HEAD and index
git diff HEAD            # changes between HEAD and working files
Last commit:
git show                 # review last commit
git show --stat          # just the stats
git show --name-status
git show HEAD
git show HEAD^^
git show master~5
git show master@{june.23}
GIT clone:
git clone /home/guptav/workspace/myproject
GIT updates:
git fetch                # To get updates
git pull                 # To fetch and merge
Logs:
git log                  # See commit history
git log -- some/file     # Limit to specific path
git grep -e "pattern" --some/file
git log -p
git log --stat
git log -5 master@{yesterday}
git log --since="2 weeks ago"
git log --before="2 weeks ago"
git log --author="Vaibhav" --since="10 days ago"

git reflog
Branches:
git branch -l            # Local branches
git tag <tagname>
Git Format Patch:
git format-patch -1
Status:
git status
Configuration:
git config --global user.name "Vaibhav Gupta"
git config --global user.email "vaibhav.gupta@gmail.com"

Latest File at: 

https://github.com/guptav/zunkyard/blob/master/tips/source/git.rst

Project: dotfiles : sync dot files


Project : dotfiles

Installation

Creat links for dot files:
./install.sh link
Check links:
./install.sh check
Unlink dot files:
./install.sh unlink
If old files exists then backed up in ${HOME}/*.bak

Source Repo:
git clone https://github.com/guptav/dotfiles.git

Tuesday, November 04, 2008

How to : QEMU Networking

Well,
I have posted the original article here.

Copying it here for readers.
------------------------------------------------------
Hi All,
It has been ages since I have written anything over here. One of the main reason is that I have started posting mathematical post at my wordpress blog.

Anyways, Sameer and I were trying to get our hands dirty on Qemu networking. Although there is a fairly good description is given over here, I am trying to fill in here a few missing bits.

Okay, so here is the scenario we want to create.

On one machine ( say host-A ) we want to create many guest machines ( guestA1, guestA2 ) etc. Similarly, there is another machine ( host-B ) having many guest machines ( guestB1, guestB2 ). We want to make guestA* communicate with guestB*.

I am assuming that readers are aware of how to install a guest OS on a guest machine created by qemu.

First we need to configure a ipv4-over-ipv4 tunnel for the host machines.

--host-A configuration is as follows

ip : 172.27.16.1
netmask : 255.255.255.0
default gateway : 172.27.16.254

host-B configuration is
ip : 172.27.16.2

netmask and gateway is the same as above.

--In host-A ( as root ) do the following

root@hostA# ip tunnel add tunl1 mode ipip remote 172.27.16.2 dev eth0

-- this command essentially create one endpoint of the tunnel in host-A. It says that the other end of the tunnel lies at ip 172.27.16.2. Also, the tunnel device will use eth0 as its physical device.

root@hostA# ip link set tunl1 up

-- this command will bring up the tunnel interface

root@hostA#ifconfig tunl1 10.0.1.1 pointopoint 172.27.16.2

-- guestA network will be 10.0.1.0/24 network and tunnel device should be a part of it. This command gives the tunnel device an ip address and it says that other endpoint of the tunnel will be at 172.27.16.2

root@hostA# route

--this will show you the current configuration of routing table. There might be an entry in the routing table

172.27.16.2 * 255.255.255.255 U 0 0 tunl1

--you need to delete this entry using following command :

root@hostA# route del -net 172.27.16.2 netmask 255.255.255.255 dev tunl1

--Also you need to tell routing table that guestB network ( 10.0.2.0/24) should be routed through the tunnel

root@hostA# route add -net 10.0.2.0 netmask 255.255.255.0 dev tunl1

--You need to repeat the same procedure for hostB with suitable ips ( use 10.0.1.* instead of 10.0.2.* and vice versa , replace 172.27.16.1 with 172.27.16.2 and vice versa )

--By now, your tunnel should be working. To check, try

root@hostA# ping 10.0.2.1

root@hostB# ping 10.0.1.1

--If it does not ping, it might be the case that your firewall is coming into the way. If you are expert enough, modify your firewall rules with iptables. If not, lets first save your firewall rules

root@hostA# iptables-save | cat > iptablebackup.bak

--flush the firewall rules now

root@hostA# iptables -F
root@hostA# iptables -t nat -F

--Now, that firewall is completely disabled, the tunnel should work. (Of course, you need to disable your firewall at hostB as well! ) If it still does not work, then there might be some other problem or you might not have done things right.

-- you can restore your firewall ( later ) with

root@hostA# cat iptablebackup.bak | iptables-restore

--Okay, so the tunnel is working now!! Great news!! But what next??
Next we create a tapping device - a virtual network interface - which will be visible to the guest OSes.

root@hostA# tunctl -u username

-- provide a username here. This user will be able to use this tapping device while initializing qemu process. This command would have created a tapping device (tap0) in your system

--assign an ip address of guestA network to tapping device

root@hostA# ip addr add 10.0.1.2 dev tap0

-- bring the tapping device up

root@hostA# ip link set tap0 up

-- Also create a file /etc/qemu-ifup which can look like following :
#!/bin/bash
#echo "bringing up interface $1"

-- Now start the first guestOS

username@hostA$ qemu -net nic,macaddr=macaddr1 -net tap,ifname=tap0 -net socket,mcast=230.0.0.1:9999 ....

--second guestOS can be started with following
username@hostA$ qemu -net nic,macaddr=macaddr2 -net socket, mcast=230.0.0.1:9999 ...

-- multicast socket is needed for mchines in guestA network to talk to each other

--In the guestA1 do the following :

root@guestA1# ifconfig eth0 10.0.1.3 netmask 255.255.255.0
root@guestA1# route add default gw 10.0.1.2 dev eth0

-- Note that we have given the ip address of tapping device as the gateway fo guest OSes
-- second, third etc guest machines can be configured with different ip addresses for their eth0

-- Repeat this procedure on host-B as well with appropriate ip addresses.

-- Now, you should be able to ping machines from guestA network to guestB network and vice versa. However, this does not yet allow you to connect to host network. To do that, you need to enable ip forwardng

root@hostA# echo "1" > /proc/sys/net/ipv4/ip_forward

-- perform source NAT

root@hostA# iptables -t nat -I POSTROUTING 1 -o eth0 -j SNAT --to-source 172.27.16.1

--Now, from guestA network ( 10.0.1.0/24 ) you should be able to connect to ( 10.0.2.0/24 ) as well as host network ( 172.27.16.0/24 )

-- To delete the tunnel

root@hostA# ip link set tunl1 down
root@hostA# ip tunnel del tunl1

--To delte the tapping device

root@hostA# tunctl -d tap0

--Above mentioned setup is tested with host machines running fedora core 9 and guest machines running Arch Linux, Debian etc.

If you have any queries post it as comments, I will be willing to answer if I can.

Wednesday, June 25, 2008

goosh.org - the unofficial google shell.

<snip>
Goosh goosh.org 0.5.0-beta #1 Mon, 23 Jun 08 12:32:53 UTC Google/Ajax


Welcome to goosh.org - the unofficial google shell.

This google-interface behaves similar to a unix-shell.
You type commands and the results are shown on this page.

goosh is powered by google.

goosh is written by Stefan Grothkopp <grothkopp@gmail.com>
it is NOT an official google product!

Enter help or h for a list of commands.

Loading local settings...
guest@goosh.org:/web>
</snip>
Go to  http://goosh.org/

Vaibhav.

Wednesday, April 09, 2008

Duplex printing script

Well,
I don't want to write the same thing again. So please refer to this link to see what this article is about :-).
It is basically about a script for duplex printing.

--Saurabh

Saturday, February 09, 2008

Programming Challenges

Today, I had a chat with ali on different online programming challenges as IOPC is going on write now and ali has taken part in it. I was remembering my glorious days when I won a jacket in bitwise.

I am just going to enlist a few programming challenges. Obviously, the list is not exhaustive.

1) ACM ICPC : I believe it is one of the most prestigious programming challenges. It is an IBM sponsored annual event.

2) Top Coder : This too is one of the most prestigious programming challenges. General belief is that the emphasis is more on programming rather than algorithms.

3) IOCCC : Well, here one can find the weirdest C programs. Most of the time it will seem that the winning entry programs won't even compile. However, they do but it is difficult ( rather next to impossible ) to find out what they would do by merely reading the code. My favorite program is here. And yeah, it DOES compile and run.

4) Bitwise : One of the most prestigious INDIAN programming challenges. I used the word "Indian" because it is held by Indian Institute of Technology, Kharagpur. The challenge however is open internationally. It is really a pity to see that since the inception of the event, only once an Indian team could grab the first prize. Ameya Karkare ( aka crack-kare ) and Navneet Lohiwal ( aka lollu ) from Indian Institute of technology Bombay (my alma-matter :-) ) played with handle "AK47", undoubtedly shooting down all competing teams.

5) OPC : Held annually by Chennai Mathematical Institute. One of the toughest programming challenge I have ever faced.

6) CodeCraft : Held annually by International Institute of Information Technology, Hyderabad as part of their technology festival Felicity.

7) IOPC : Hosted by IIT Kanpur as part of its technology festival techkriti.

Friday, January 11, 2008

Pune Innovation 2008 : Ideas in Practice


Website: http://www.innovations-pune.com/
Government : www.dsir.gov.in [Click TePP]

1. Do the innovation. It should be unique. It can be simple and obvious too. Think Beyond Imagination.
2. Find out a pricing model / revenue model. Strategy/People.
3. Do the market analysis. Compare with other products. Pros/Cons of your and others products.
4. What are the pin points of your product?
5. Take care of customers and their expectations. Think as if you are one of them. User experience.
6. Think not only for early bird advantage but in long terms. Think Fast. Vision.
7. Do the Risks/Liabilities.
8. How do you do marketing? Promote. Om Shanti Om.
9. Always have the exit plan ready. (Just like in sysadgiri where you should always have the backup plan ready.)
10. Blank. (You have to fill this by yourself.)
 
Vaibhav.

ps: What your Dreams really mean!

My AJAX Notes.



My AJAX Notes.


Vaibhav.




Tuesday, September 25, 2007

Kool Linux Sites

http://www.slax.org/

: Get the Software

http://linuxhardware.org/ : Find about Hardware

http://www.linuxdevices.com/ : The Device part

http://tldp.org/LDP/sag/html/ : Do sysad

http://www.winehq.org/site/about : Want to plat games

http://newdata.box.sk/bx/hacker/ : Do something.

Vaibhav.

"When you guys actually learn something, come to me
and say, 'We learned something! We learned something!' and I'll
show you some cool stuff."

Wednesday, September 19, 2007

Tiddlywiki

http://www.tiddlywiki.com/

To set up:

wget http://www.tiddlywiki.com/empty.html
firefox file:///`pwd`/empty.html

Done.
<snip>
The easiest way to learn about TiddlyWiki is to use it! Try clicking
on various links and see what happens - you cannot damage
tiddlywiki.com or your browser.
</snip>

Thursday, July 26, 2007

VIM Tip

Convert any file to html file using vim from command prompt :
vim -c ":runtime! syntax/2html.vim | :wq | :q " <FILENAME>
File Created: <FILENAME>.html

Example:
vim -c ":runtime! syntax/2html.vim | :wq | :q " a.c

will create a file "a.c.html"

Friday, May 11, 2007

[Perl] Script to check stock

Script to check the stock and their graph :D
Uses finance.yahoo.com to get the graphs.

INPUT : stock.conf : contains stock symbol (one per line ) for each company.
You can find the symbols on http://finance.yahoo.com/lookup, if you don't know.

OUTPUT: Generates a html page that contains the information and graph for the given companies in stock.conf.

Requires: lynx
Usages: Put stocks.cgi and stock.conf in your cgi-bin directory. Open in firefox. Refresh to get latest info.
Note: you can also run the script from shell prompt and then redirect the output to a html file , then open this file in firefox :D But you need to run it every time you want the latest info.
# perl stock.cgi > mystocks.html
# firefox mystocks.html

Here are the files:

----- stocks.cgi ---
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
#Written by Vaibhav Gupta
################ Variables ######################
my $stockfile = "stock.conf";
my $tab_width = 3;
################################################

sub generatestockhtml () {
my @allfile = `cat $stockfile `;
my $toprint = "<table frame=box><tr>\n";
my $count=0;

foreach my $line (@allfile) {
chomp $line;
my ($firstchar) = ($line =~ /(.)/ );
my $stock=`lynx -source " http://finance.yahoo.com/d/quotes.csv?s=$line&amp;f=l1d1t1c6ohgn&e=.csv"` ;
my ($lasttrade,$lasttradedate,$lasttradetime,$change,$open,$dayhigh,$daylow,$name) = split(/,/,$stock);
#Not Printing lasttradetime
$toprint .="<td>
<b>$name</b> Trade Date = $lasttradedate <br>
Current: <font color=green>$lasttrade</font> Change:<font color=red> $change</font> <br>
Open: <font color=green>$open</font> High: <font color=green>$dayhigh</font> Low: <font color=green>$daylow</font>
<a href=\" http://ichart.yahoo.com/v?s=$line\">
<img src=\"http://chart.yahoo.com/c/0b/$firstchar/$line.gif\">
</a> <br>
<a href=\"http://finance.yahoo.com/q?s=$line&d=b\"> More Info</a>
</td>
\n";
$count++;
if($count % $tab_width == 0) {
$toprint .= "</tr><tr>";
}
}
$toprint .= "</tr></table>";
print $toprint;
}


print header("text/html"),
start_html("Vaibhav Gupta's Stock Page");
my $cur = CGI->new() ;
&generatestockhtml();
print end_html;

--- stock.conf --
goog
yhoo
msft
amzn
emc

Thursday, April 19, 2007

Trapping signals (^C and ^Z) in Bash

#!/bin/bash
#Script written by Vaibhav Gupta
#Trapping HUP TERM INT and ^Z in shell.

echo "Process ID = $$";
stty susp "" #Trapping CTRL-Z
trap 'echo "Trapping CTRL-C, TERM and HUP";' HUP TERM INT
echo

echo "Sleeping for some time"
for i in `seq 1 20`; do
    sleep 1
    echo -n "."
done
echo
stty susp "^Z"


Koool bash Functions


http://www.novell.com/coolsolutions/tools/18639.html

Tuesday, April 17, 2007

Script to exchange ssh keys

 1 #!/usr/bin/perl
2 use Expect;
3 #USAGE: ssh-key-exchange.pl <IP> <USERNAME> <PASSWORD>
4
5 my $ip = $ARGV[0];
6 my $login = $ARGV[ 1];
7 my $password = $ARGV[2 ];
8 my $private_key='/root/.ssh/id_rsa ';
9 my $public_key='/root/.ssh/id_rsa.pub ';
10 my $authorisedkeyfile='/root/.ssh/authorized_keys ';
11 my $timeout = 10;
12 my $aft = new Expect;
13
14 #Generate the public and private key on the local m/c A
15 if(!(( -e $public_key ) &&( -e $private_key ))) {
16 print "Generating the Public and Private Key:\n ";
17 @result=`ssh-keygen -t rsa -f /root/.ssh/id_rsa -P "" `;
18 #print @result;
19 }
20 #Copy the file to m/c B
21 print "Copying Public Key from A to B.\n ";
22 $aft->spawn("scp $public_key $login\@$ip:/tmp/");
23 $aft->expect($timeout,[ qr'\? $' , sub { my $fh=shift; $fh->send("yes\n"); exp_continue; } ],
24 [ 'Password: $',sub { my $fh=shift;$fh->send("$password \n");exp_continue;} ],
25 # '-re','\# $'
26 );
27 $aft->do_soft_close();
28
29
30 #Add Keys to authorised keys in B
31 print " Adding Keys to authorised key in B with IP=$ip,[ $login $password ] \n";
32 my $aft = new Expect;
33 $aft->log_file("/tmp/expect_log" ,"w");
34 $aft->spawn( "ssh $login\@$ip") or die "Cannot ssh to the machine \n";
35 $aft->expect($timeout,[ qr'\? $', sub { my $fh=shift;$fh ->send("yes\n"); exp_continue; } ],
36 [ 'Password: $',sub { my $fh=shift;$fh->send("$password\n ");exp_continue;} ],
37 '-re', '\# $'
38 );
39 $aft ->send("touch $authorisedkeyfile\n");
40 $aft->expect($timeout,'-re' ,'\# $');
41 $aft->send( "cat /tmp/id_rsa.pub >> $authorisedkeyfile\n");
42 $aft->expect($timeout,'-re', '\# $');
43 $aft->send(" exit\n");
44 $aft->do_soft_close();
45