Wednesday, December 7, 2011

Git Simple commands

Like other repository managers CVS, git is a also a repository manager. Where we can commit our code, so that it can be updated in repository.

Branches : Whole repository can be managed using two branches : local  and remote branches. Master is the root of all branches where all builds from different branches are committed and are in production version. Local branches are the branches specific for particular project. Remote branches are the branches specific to particular project but not created by us.

Useful git commands :

#git push origin branch-name : push the code to specified branch
#git branch : will show your current branch
#git branch  -a :show list of all branches including remote and local and master branches
#git branch -r : show list of all remote branches.
#git stash : save your local changes into git pull or git svn (so that whenever you git pull --rebase changes will automatically comes in)
#git checkout <branch_name> : To switch to specified branch
#git pull --rebase : pull the updated build from current branch
#git logs : to check the last updates in repository
#gitk : is an Graphical interface to git.
#git status : How many local changes you have made.
#git diff <filename> : shows the differences of changes you have made in that file after last commit/update.
#git branch <branch_name> : create a new branch with <branch_name>

Note for more details refer link

Wednesday, November 30, 2011

String vs String Builder vs String Buffer

String : Immutable
String Builder : Mutable + Thread safe
String Buffer : Mutable + not Thread safe.


Performance wise : string is bad , as for every operation it creates new string object hence immutable. whereas String builder/ String Buffer doesn't create new object very time for string operations.

For ex :

String A = A + "BBC"
then for this a new "A" object will be created. So we are creating those many objects of string class.

When using String Builder/ String Buffer, then operations performed on same object and doesn't create new object of String Buffer/ Builder. Hence mutable.
Therefore performance is good.

##PS : For more refer mutable/immutable

Saturday, October 1, 2011

MySQL Reset Root Password

1> First, stop the database
sudo /etc/init.d/mysql stop

2> Start mysqld_safe [which starts the mysql server in safe option] LIke to restart server when some error occured. For more details click here.
Similarily we are using mysqld_safe for resetting lost/forgot password.

/usr/bin/mysqld_safe --skip-grant-tables &
You have to run above using root (sudo -i)
3> It shows mysql daemon started with databases in /var/lib/mysql
Since server is running with --skip-grant-tables flag, means you can access the database without password
Now write the command :
mysql --user=root mysql
Enter your root password
4> Now since we have to update our password in User table. Therefore 
We provide command :
Update user set Password=PASSWORD("Your New Password") Where User='root';
5> Flush Privileges :
Means clear and reload the priviledges.
So command will be 
flush privileges; More about flush option click here
 
6> Exit Mysql
7>Now You have to stop the Daemon Mysql server
It is a two step process :
  • Firstly bring the Background process to Foreground
    Command used for this is :
    fg
     
     
  • Kill the Foreground process
    Ctrl + c [But sometimes Ctrl +z]
8>Now start the mysql 
sudo /etc/init.d/mysql start
9>Now go to mysql
mysql --user=root --pass=newpassword

Monday, September 5, 2011

apt -get broken packages

1>
sudo apt-get clean
will clear your cache, afterwards try again to install the packages you want.
2>
sudo apt-get install -f

Monday, August 29, 2011

Some important commands in ubuntu

1> To remove an application already installed
sudo apt-get remove <app>

2> To remove application already installed with all config files.
sudo apt-get --purge remove <appn>

3>To list all installed packages
dpkg --list
 dpkg --list less
dpkg --list | grep -i 'app'




Sunday, August 28, 2011

How to make password protected folder in Ubuntu

Steps are :

## Install cfs using sudo apt-get install cfs

## Create the encrypted directory (let say lock)
$ cmkdir lock (It will ask for key i.e passwd for folder should not less than 16 chars)

## So encrypted directory lock is created, now we have to put our secret files, this is done by attaching another directory to lock ( let say directory is clock where we put our personal files)
$ cattach lock clock (again it will ask for key)

## You can look a new directory called /crypt is created  and clock folder is inside it where you put ur personal files. /crypt/clock

## Move ur personal stuff to clock
$ mv personal-files /crypt/clock

## Now, to close ~/lock so no one can get into it, we need to unattach the directory with the cdetach command

## $ cdetach clock 

NOTE : Next time if u want to acess ur personal stuff firstly u should start cfsd so, /etc/init.d/cfsd start and then reattach using cattach and then 
sudo umount -f /crypt/clock


Now u can acess ur files. 
After that u shud deattach using cdetach so that it become protected again.
 

Monday, August 22, 2011

Loading Servlet in Tomcat 5.5.29

1> After installing tomcat 5.5.29, CLASSPATH needs to be set for servlet-api.jar file (which is located in apache-tomcat (in my case it is tomcat0)/common/lib/servlet-api.jar). So CLASSPATH = $CLASSPATH:$CATALINA_HOME/common/lib/servlet-api.jar , where CATALINA_HOME=apache-tomcat folder.

export CLASSPATH

2>Create a directory where you compile all your servlet codes. Let say /usr/Servlet.
Also CLASSPATH needs to be set to this folder also.
i.e CLASSPATH=/usr/Servlet.
export CLASSPATH

3>Create your servlet code (let say example.java). Now compile it to create example.class.
sudo javac -classpath /opt/tomcat0/common/lib/servlet-api.jar HelloWorld.java
where path for servlet jar should be included. i.e

sudo javac -classpath <servlet-jar-path> <example.java>

4>Now goto CATALINA_HOME/webapps/ROOT/WEB-INF
--> Create a classes folder (if not present) and copy example.class file to classes folder.
--> Now in web.xml file add these lines
<servlet>
<servlet-name>example</servlet-name>
<servlet-class>example</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>example</servlet-name>
<url-pattern>/example</url-pattern>
</servlet-mapping>

Above entries to be created inside <web-app>...</web-app> tags available in web.xml file

5> Now stop and start the tomcat .
In my case :
Stop : sudo /etc/init.d/tomcat0 stop
Start : sudo /etc/init.d/tomcat0 start.

6> Goto to browser and type :
http://localhost:8080/example


Thats all