Garbage Bag

All my Garbage talks and junk codes

Month: May, 2010

GIT – a widely used version control system

git is a widely used version control system with its flexibility and rich command sets .

Here covers three most basic and important functionalities in GIT .

i) Creating a new repository and committing

ii) working with branches

iii) Cloning and distributed working

Creating a new repository and committing

This is a basic operation in any version control system. Assume a scenario  where you are creating a maths software using C .

now each project should have a name ( I will be speaking package , software, project and repo interchangeably )

let it be myCproject . now to create a new repo the steps are :

step 1)

create a new directory of that project name

>> mkdir  myCproject

step 2)

get into the project and intialis it for git database

>>cd myCproject

>>git init-db

now your project is initialized and ready to accept files .

step 3)

start coding some files and place it myCproject directory . eg ) add.c,mul.c,sub.c,div.c

now this files wont get added to git unless you add into it

>> git add .

>>git commit -a -m ” Your first commit “

step 4)

now your first version of the software should be commited and you can check it by

>>  git status

or

>>  git whatchanged

step 5)

whenever you perform more than one commit then use

>> git diff

to get the changes from first and second commits .

Sample window :

Working with branches :

now placing all files under single category may be tiresome . So we can group similiar files under a branch .

branch is something like a sub-repo

step 1)

first create a new branch under which you are going to work

let us say math software needs a gui

>> git branch gui

this will create a branch named gui .. to see the list of branches in project you can use

>> git branch

step 2)

by default git will be in branch named master .

to switch over to gui  branch use

>> git checkout gui

now your workings will be placed under gui branch after changed dont forgot to commit

>> git commit -a -m ” commit from gui branch “

step 3)

now to switch back to master branch use

>> git checkout master

step  4)

to merge all the changes done by the branch gui to master use

>> git merge gui

and after merging if the branch is no more needed then delete it

>> git branch -d  gui

to get a graphical view of branches and files use gitk

Cloning and distributed working :

step 1)

whenever more than one user works with a project then sharing should take place . say two user alice and bob .

bob wants the myCproject from alice . then bob should issue

>>git clone /home/alice/myCproject

now bob will get a copy of alice in his current directory

step 2)

similiarly commit and add are done as

>> git add sub1.c

>> git commit -a -m ” commit from BOB “

step 3)

to get the changes made by bob alice will pull bob and get the changes by

>> git pull /home/bob/myCprojects


Commands overview :


git init-db     = initialsises the repository

git add file1 file2 file3   = adds the files to git repository

git commit -a = commits with the next version

git status = current status of files and branch name

git whatchanged = history of all versions

git diff = difference between previous and next version

git branch branch-name = creates a new branch

git branch = lists the all available branches

git checkout branch-name = switches to particular branch

git merge branch-name = merges with other branch

git branch -d branch-name = deletes unwanted branch

git clone repo-url = clones a existing project from other url

git pull repo-url = gets the changes from other repo

jGateway – My simple remote shell using twitter API

Requirments :

i) Any operating system ( Linux is preferable )

ii) Java Runtime Environment

ii) Two twitter accounts

Setting up:

Step 1:

Create two twitter accounts one for SERVER and one which acts as CLIENT here :

jGateway account acts as server ( runs on the host machine )  and

karthikselva account acts as client ( RemoteAdmin for the system )

Step 2:

Download my jGateway file from here

always copy execid file along with jGateway.jar

Step 3 :

open a terminal and run the file as  java -jar  jGateway.jar

if you also need to run admin commands run sudo java -jar jGateway

enter the server username and password of twitter account

Start Server

this will listen to incoming commands

Step 4:

now to send a shell command to server from any machine just login into your twitter account

and send a direct message to the server account from your account

Send command from client

note : remember both of the accounts are following each other

Step 5:

After the command has been read by the server it will execute  the command in same java window .

After Execution in server

if the command is valid and has executed succesffully then the server will tweet as <COMMAND_NAME> <SUCCESS>

tweet by server

else the command have failed it will display as <COMMAND_NAME> <FAILED>

Disclaimer :

I have tested my code in Ubuntu 10.04 and its working . If you get any twitterException while running then either your account must be blocked by twitter.com or  Check your internet connection before running.

Follow

Get every new post delivered to your Inbox.