Garbage Bag

All my Garbage talks and junk codes

Category: Projects

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

Building your fax machine with nothing :)

Now you can build your own fax machine with your linux box

Requitements :

i) Linux OS

ii) GSM mobile

iii) A basic printer device

Softwares:

i) Gnokii-smsd

ii) Mysql

if you have any problem in configuring your mobile and your linux you can refer to this article

Now assume your sms daemon is up and running and you have all your messages in INBOX table of SMSGW database

with simple steps you can make your own fax machine

step 1)

configure your printer and check wheteher a test page is being printed . Else install appropriate driver first from hplip

step 2)

then as in dicitionary server connect to mysql database  and  just add an if  condition

the core part is

if(word.startswith(“fax:”)):
up=” echo \”"+str(word.replace(“fax:”,”"))+”\” > print.txt”;
low=” cat print.txt | lpr -P HP_LaserJet_1020″

then just execute the both as

import os

os.system(up)

os.system(low)


step 3)

Here , after lpr -P < your printer name > for me it is HP_LaserJet_1020

then  mention the mobile number as the fax number of your company  and you will start receiving faxes in papers instead of text messages :)

step 4)

Then let the mobile you attached to PC be +xxxxxx

now people who fax you will send a message like

fax:< Their message here >

step 5)

you can add an authentication  module in between receiving and printing the message

Enjoy :)

lock and unlock gnome with gsm

tested with :

i) ubuntu 8.10

ii)gnokii

iii) mysql 5

iv) lg kp 199

functionalities :

i) just message “lock” to your server mobile to lock the screen

ii)   “unlock” to release the screen

iii) you can even change the pidgin status by messaging “status:your status here

iv )  execute any shell commands that take return value  below 160  characters

procedure:

step 1)

set the memory for sms to sim and run the smsd daemon as

sudoo /usr/sbin/smsd -u root -d smsgw -c localhost -m mysql -u root –password=password -b SM -f /var/log/smsdaemon.log

step 2)

run this python script  and minimize the shell

#!/usr/bin/python

#    before running this program you must configured gnokii-smsd and it must be up and running
#     @Author:    Karthik selvakumar
#    Name :     Dictionary Server

# install python-MySQLdb  before importing this module

import MySQLdb

# imported inorder to perform shell operations

import os

processed=1;
# run as a daemon and never exit this thread

while(True):

#defines the database parameter change according to your configuration

host=”localhost”

user=”root”

passwd=”123456″

db=”smsgw”

# Optionally get input from user

#    print ” Enter Host :”

#    host=raw_input()

#    print ” Enter Password :”

#    passwd=raw_input()

#    print ” Enter database :”

#    db=raw_input()

#creates a database object for corresponding config

db=MySQLdb.connect(host,user,passwd,db)

cursor=db.cursor()

#performs pruning of inbox table which may contain null entities

cursor.execute(“delete from inbox where text=\”\”")

#gets the latest entered SMS from Mysql server

cursor.execute(” select number,text,id,processed from inbox where id=(select max(id) from inbox)”)

record=cursor.fetchall()

for result in record:

# gets the word to find meaning

word=result[1]

# get the number bcoz u have to reply the meaning to this number later ;)

number=result[0]

row=result[2]

processed=result[3]

if(processed==0):

# script to get meaning of a word from google server
if(word==”lock”):
up=”gnome-screensaver-command –lock”;
elif(word==”unlock”):
up=”xset dpms force on && gnome-screensaver-command -d”;

elif(word.startswith(“status:”)):
up=” purple-remote \”setstatus?status=available&message=”+str(word.replace(“status:”,”"))+”\”";

else:
up=word+” >meaning.txt”;

print up;

#set the entity to be processed when taken out

cursor.execute(” update inbox  set processed=1 where id=”+str(row));

# run the command in shell and write it to file named meaning.txt

os.system(up)

# open the file in read only mode

filehandle=open(‘meaning.txt’,'r’)

# load the meaning in the string text

text=filehandle.read()

print ” text is “+text;

# we no more need this

filehandle.close()

if(text!=”"):
cursor.execute(“insert into outbox(number,text) values(%s,%s)”,(number,text))

# close all active connections :)

cursor.close()

db.close()

#thank you !

step 3)

your done with now message to the mobile you have connected like lock or unlock or status:status to see the magic happen :)

Running SMS Dictionary server in your Home

Do you want to run a dictionary server that messages you the actual meaning

Requirments :

i)  A GSM mobile phone

ii)  Linux  with python

iii) Mysql Database

iv)  Gnokii-SMSD

You must be sure that gnokii-smsd is up and running and database is available

if not refer to my previous post here

Code :

This code simply connects to dictionary.org and gets the meaning for the word that is latest in INBOX table and writes the meaning to OUTBOX table which will be sent to user later .May have bugs in it please report me at earliest :)

copy and paste the code to a file . let it be dict_server.py . code is below :

#!/usr/bin/python

#    before running this program you must configured gnokii-smsd and it must be up and running
#     @Author:    Karthik selvakumar
#    Name :     Dictionary Server

# install python-MySQLdb  before importing this module

import MySQLdb

# imported inorder to perform shell operations

import os

# run as a daemon and never exit this thread

while(True):

#defines the database parameter change according to your configuration

host=”localhost”

user=”root”

passwd=”password”

db=”smsgw”

#creates a database object for corresponding config

db=MySQLdb.connect(host,user,passwd,db)

cursor=db.cursor()

#performs pruning of inbox table which may contain null entities

cursor.execute(“delete from inbox where text=\”\”")

#gets the latest entered SMS from Mysql server

cursor.execute(” select number,text,id from inbox where id=(select max(id) from inbox)”);

record=cursor.fetchall()

for result in record:

# gets the word to find meaning

word=result[1]

# get the number bcoz u have to reply the meaning to this number later ;)

number=result[0]

row=result[2]

# script to get meaning of a word from google server

up=’/usr/bin/curl -s -A \’Mozilla/4.0\’ \’http://www.google.com/search?q=define%3A\”

low=’| html2text -ascii -nobs -style compact -width 500 | grep “*” | head -n 1 -q | tail -n 1 > meaning.txt’

# run the command in shell and write it to file named meaning.txt

os.system(up+word+low)

# open the file in read only mode

filehandle=open(‘meaning.txt’,'r’)

# load the meaning in the string text

text=filehandle.read()

# we no more need this

filehandle.close()

# insert into outbox table which will send the meaning of the word to the phone number later

cursor.execute(“insert into outbox(number,text) values(%s,%s)”,(number,text))

# close all active connections :)

cursor.close()

db.close()

#thank you !

now run the dictionary daemon by running python dict_server.py in terminal

whenever a message is received to your mobile it will be read by dict_server.py and meaning of that word will be in outbox table

to see run select * from outbox ; in mysql console

Enjoy :)

Cursor Play With your neigbour System

If you have more than one system and need to acces all with a single mouse ?

Wanna hack your neigbour node and drive him mad?


you can use this code to move the cursor

and with little modification you can emulate a whole mouse and keyboard functionalities too …

Download My code from here


To Do :


step i) run the server.class first in machine u want to control say A

java server <port_numbr 1000-65535>


step ii) run the client.class in second machine u have the mouse say B

java client <ip of machine say 10.2.3.1 > <port_number_server 1000-65535>


step iii) move  mouse in machine B so that it moves on machine A

Algorithm behind :

i)  get the mouse position from master machine

ii) send the position in a ‘encrypt‘ string with X and Y positions merged

as encrypt=X*10000+Y ( I use 10000  here assuming your screen resolution is not more than 10000X10000 :D )

iii) send the string to slave node using Socket output stream

iv) get the encrypt string and extract x and Y position  by

X=encrypt/10000;

y=encrypt – X;


v) Now move the position of slave machine by mousemove(X,Y) method

vi) You can add leftclick , right click and keyboard keys too as above  :)

Keyboard as Network Packet Monitor

You can transform Your NUM lock and SCROLL lock led’s to monitor packets send and receive :)

Follow the simple steps below :

i) Installation:

Install tleds package  bye sudo apt-get install tleds

ii) Configure :

now configure the interface you use

say for ethernet  run tleds eth0

and for wirless  run tleds wlan0

Perform a restart :)

iii) Customize :

Now you can adjust the delay to very quick response to low response rate by adjusting -d paramter in tleds

for very quick run tleds  eth0 -d 1

for low speed run tleds eth0 -d 200

now you have  tranformed your keyboard to packet monitoring system as below :


enjoy :)

Simple chess

Is it too boring ..?
Then try my web chess , a simple php and mysql based application with simple GUI .
(guess you Know we need two people to play chess )
Try the link from anywhere around the world and choose opponent’s from every where .
Have Fun :)

Remote car on ‘C’

remote car on c

/** This is a basic hardware program in c interfacing a remote car
here consider a basic table

lpt port has pin 2-9 for data we can send data to it by calling

here we use only data pins 2,3,4,5 only

syntax : outport(port_address,number);

port address is 0×378 for lpt 2 and 0×3bc for lpt 1

well now move towards the code concentrate on lowest 4 bits

number data operation

1 0001 right steer
2 0010 left steer
4 0100 forward
8 1000 backward
5 0101 right steering + forward (right turn forward)
10 1010 left steering + backward (left turn backward)
6 0110 right steering + backward (right turn back)
9 1001 left steering + forward(left turn front)

this is the logic of code
*/

#include
#include
#include
#include

void circle() //to move in circular path
{int i=0;
while(!getch())
{
outport(0×3bc,5); // 5 = 0101 means on the right and on the forward

}
}

void rectangle()
{
int i=0;
coutl;cin>>b;
while(!getch())
{
outport(0×3bc,4); // forward
i++;
delay(1000*b);
outport(0×3bc,5); // right steer
delay(1000);
outport(0×3bc,4); // forward
delay(1000*l);
}
}

void zigzag()
{
while(!getch())
{
outport(0×3bc,5); //right forward
delay(3000);
outport(0×3bc,9); // left forward
delay(3000);

}
}

void manual()

{char c=’a’;
while(c!=’x’)
{
clear();
cout<<endl<<endl<<" use move keys for direction 'x' to exit";
c=getch();
if(c=='^[[A')
{
outportb(0x3bc,1);
delay(1000);
}
else if(c=='^[[B')
{
outport(0x3bc,4);
}
else if(c=='^[[C')
{
outportb(0x3bc,2);
delay(1000);
}
else if(c=='^[[D')
{
outportb(0x3bc,8);
delay(1000);
}
}
}

void manual(char choice, int time) // oveloaded fn for creative
{char c;
c=choice;
while(c!='x')
{
clear();

if(c=='^[[A')
{
outportb(0x3bc,1);
delay(time*1000);
}
else if(c=='^[[B')
{
outport(0x3bc,4);
delay(time*1000);
}
else if(c=='^[[C')
{
outportb(0x3bc,2);
delay(time*1000);
}
else if(c=='^[[D')
{
outportb(0x3bc,8);
delay(time*1000);
}
}
}
void creative()
{
char str[20];
int i=0,n[20];
while(str[i]!='x')
{
coutstr[i];
coutn[i];
i++;
}
i=0;
while(str[i]!=’x’)
{
manual(str[i],n[i]);
}
}

void automatic()
{
clear(); int g,h;
cout<<" enter 1 to circle "<<endl<<" 2 to rectangle move"g;

if(g==1)
{
circle();
}
else if(g==2)
{
rectangle();
}
else if(g==3)
{
zigzag();
}
else if(g==4)
{
creative();
}
}

void clear()
{
int n=0;
while(n<300)
{
cout<<endl;
n++;
}
}

void menu()
{
clear(); int ch;
cout<<" 1 for manual"<<endl<<" 2 for automatic "ch;
if(ch==1)
{
manual();
}
else if(ch==2)
{
automatic();
}
}
/* now its time to open your car’s remote
step 1: find the wires which goes for right ,left forward backward
step 2: attach lpt ports pin 2 to right 3 to left 4 to forward 5 to backward and ground to pin 23
warning ! remove external batteries from remote which may leak at times
step 3: run this code and enjoy racing !

thank you !
by karthik selvakumar B

mail bugs to karthikselvakumar@tce.edu
*/

Eye cursor

Eye Cursor is a mobility-aided device for persons with
moderate/severe physical disabilities or chronic diseases as well as
the elderly
.
Mouse is one of the traditional method of controling a
computer. But handicap are not suitable for using mouse. Hence as a
replacement of mouse for them and easify us too in controlling our pc
we can have another method of controlling it. That is using eye’s
(pupil) motion to move cursor on screen and right and left eye wink to
make clicks around the pc’s . The plan is to make a cheaper
replacemnt of mouse hence every one gets benefited .
Main hardware parts needed are a vga camera with light
and a accelerometer , ir sensor all comes around a price of 2000 and
even gets decreased when fabricated into single hardware.
Java is used as software driver which works on set of
fractionally captured images and performs movemnet on screen
relative to pupil. And the add on features like retinal encryption is
implemented if user wants secure mode of transaction.
You can download the paper by clicking here

Follow

Get every new post delivered to your Inbox.