Tuesday, October 29, 2013

Convert mercurial (hg) to git repository for bitbucket

To convert hg repository on bitbucket to git repository follow below steps.

  • Create new repository with Repository Type selected as Git
  • follow below commands with the assumption that you already have hg repository cloned on your system. If not then you first need to clone existing hg repository.

1:  $ git clone git://repo.or.cz/fast-export.git  
2:  $ mkdir <new git repo>  
3:  $ cd <new git repo>  
4:  $ git init  
5:  $ ../fast-export/hg-fast-export.sh -r <path to hg local repository>  
6:  $ git checkout HEAD  
7:  $ git remote add origin https://<username>@bitbucket.org/<username>/<new git repo>.git  
8:  or if you are going to use ssh authentication to push   
9:  $ git remote add origin [email protected]:<username>/<new git repo>.git  
10:  $ git push origin master  

This will convert your hg repository to git repository and it also maintains the commit history inside git repository.

Sunday, October 27, 2013

Install and run memcached on OS-X


One need to have gcc installed for that you need to install xcode along with command line tools. To install the same one can refer to this link for xcode 5.0.1.  Libevent is required to be installed for memcached so you need to first install libevent, if it is already installed on your machine you can skip this step.

Create temp directory and change directory to that location and execute following commands.


 $ curl -O http://www.monkey.org/~provos/libevent-1.4.14-stable.tar.gz  
 $ tar xzvf libevent-1.4.14-stable.tar.gz  
 $ cd libevent-1.4.14-stable  
 $ ./configure   
 $ make  
 $ sudo make install   

now install memcached

 $ curl -O http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz  
 $ tar -zxvf memcached-1.4.15.tar.gz  
 $ cd memcached-1.4.15  
 $ ./configure  
 $ make  
 $ sudo make install  

Above steps will install the memcached on your OS-X. Once it is done you can start it

 $ memcached -d -p 11211  


Saturday, October 26, 2013

Access file (JAVA)


Access resource / file packaged inside a jar or a located on classpath.

Two ways to access the file located inside jar or located on classpath. 


  1. Use getResourceAsStream("filename") on ClassLoader, one can retrieve the class loader instance from class instance of any class or Thread.currentThread().getClassLoader(). When you try to load the file using class loader, file will be always searched inside root folder on classpath. e.g
    Thread.currentThread().getClassLoader().getResourceAsStream("config.properties") and Thread.currentThread().getClassLoader().getResourceAsStream("/config.properties") either way class loader will try to search file from root folder which is on class path or from root folder inside jar.
  2. User getResourceAsStream("filename") on Class instance of a class. One can retrieve the class instance using ClassName.class or this.getClass(). When you try to load the file using class, file search will depend on how do you specify the file name. When you specify file "config.properties" this.getClass().getResourceAsStream("config.properties"), file will be searched inside same package as that of given class on which you are calling getResourceAsStream(). When you specify file like "/config.properties" given file will be searched from root folder which is on class path or from root folder inside jar.
Access resource / file from file location

  To access file form given path outside the class path, one need to make use of java.io.File .

File file = new File("filename with absolute path");
FileInputStream fStream = new FileInputStream(file); 
  

Friday, October 18, 2013

maven properties not being substituted inside resources


You need to add following configuration which indicates those resources need to be processed and property values will be replaced. By default Maven resources plug-in will not do property value substitution (filtering), so it will need to be enabled within the <build> section of the pom.xml file. Filtering value true will enable the resources processing and substitute property values. In addition to that one can include / exclude the resources


 <build>  
           .....  
         .....  
           <resources>  
                <resource>  
                     <directory>src/main/resources</directory>  
                     <filtering>true</filtering>  
                </resource>  
           </resources>  
           .....  
         .....  
 </build>