Posts

Fast Git clone using shallow cloning

If you want to get a read only copy of a Git repository quickly you can do a shallow clone. To make a shallow clone use argument --depth 1 along with git command line version.     git clone https://code.google.com/p/selenium/  --depth 1     When doing a shallow clone with depth of 1, it tells Git to fetch only latest revision of a repository. Normal clone fetches entire history of a Git repository. As per Git documentation, you cannot clone or fetch from it, nor push from nor into it. Shallow clone is useful when you have a slow network connection or you want to save on the network usage.

Viewing Google Code Git repository versions in plain text

Google provides plain text version of Git repository at different URL. This URL is in the format of projectname.googlecode.com/git . This gives latest version of Git repository. To view history of a particular version use URL pattern projectname.googlecode.com/git-history/versionnumber . Using this we can see a particular tagged version or a particular commit version files. For eg. Selenium version 2.28 can be viewed using https://selenium.googlecode.com/git-history/6322c139ceec Version number can be obtained using Browse option in the source menu of main project which can be accessed using URL pattern code.google.com/p/projectname/source/browse/

Downloading source code from SVN/Git repository over HTTP

    Sites hosting open source projects provides an online viewer for browsing source code without actually checking out source code using SVN/Git clients. Checking out entire repository will take long time. Also with Git there is no straight forward way to checkout only a particular directory. Cloning Git repos takes long time as Git downloads entire repository to local machine. Even with sparse checkout, Git downloads entire repository. When bandwidth is a concern, one cannot checkout entire repository.     One can use GNU Wget to recursively download files from online code repositories. For windows this can be downloaded from http://users.ugent.be/~bpuype/wget/     Command to download a directory and its child directories and all files in it recursively excluding index.html is below. This will not download parent directories and files from external sites. wget --cut-dirs=2 --level=15 --include-directories=src/main/java --recursive --n...

java.io.Console broken in Eclipse

Today I discovered that java.io.Console doesn't work when running application inside Eclipse. I was writing a trivial application that accepts some configuration from console. On trying to run this in Eclipse I was getting NullPointerException.as the Console object was null. I used Eclipse Indigo(3.6) version. On Googling found that there is an open bug and is not fixed. Looks like nobody ever planned to fix it.See bug 122429 for detail. User XIMES commented a workaround solution in the bug. It is to use BufferedReader by passing System.in as the input stream. Also to write one can use PrintWriter by passing System.out as the output stream. Downside to this workaround is that it cannot mast passwords which can be done by java.io.Console. Alternatively one can also look at using java.util.Scanner. One issue I found with Scanner is that pressing enter key is not considered as input and had to enter some value other than carriage return key. Sample usage public static void m...

Suppressing JExcel warnings

JExcelAPI(Jxl) which is a Java library for parsing Excel files does not have any configuration to use a custom logger at deployment time. JExcel decides logger class at build time and to use any other logger like Log4J, one must build Jxl jar file after configuring JExcel build.properties to use a custom logger. This is not a practical solution for many as they have to go through the hassles of building a custom jar with every new release of JExcel. It is common that parsing an Excel file will have many warnings and one will not be interested in seeing those. Also this invokes curiousity of testers and they will create bug for the warning. One such warning is Warning:  Cannot read name ranges for GROUP5 - setting to empty To suppress such warnings, JExcel provides a system property jxl.nowarnings which can be set to disable warnings. This can be passed as a startup argument to JVM or can be set in a class. To pass it as argument to JVM add -Djxl.nowarnings=true This wil...

Handy collection of SQL's for Oracle

This is a collection of Oracle SQL’s that will come handy when you are in trouble. This includes finding who locked a record, finding SQL which is still executing, getting full SQL executed by application, find long running jobs, get time when the table was created, finding uptime of database. This is gathered from various blogs and stackoverflow.com answers. All these SQL uses V$ views and one will need SELECT_CATALOG_ROLE role to run these queries. Find sessions that blocks each other Find locks on records that are caused by two update operations on same record in different sessions. This often happens when one person updates a record using a SQL client and does not commit the change and the application/batch job tries to updates the same record. Then the second application waits forever hoping to acquire the lock. select s1.username || '@' || s1.machine     || ' ( SID=' || s1.sid || ' )   is blocking '     || s2.usernam...

How to find actual Tomcat instance in a cluster

It is common that in a cluster we have to find out which Tomcat instance is used so that we can monitor the log files of that particular server only. When Tomcat is used as the application server, normally load balancing is done using Apache JK connector (mod_jk). JK connector adds name of actual instance to JSESSIONID cookie so that the connector can know how to route the request to the server which created the session. This works only when sticky session is used. When sticky session is not used, name of actual server is not appended to cookie and request is send to a server picked based on the load on each server. In this case, it is very difficult to identify actual Tomcat server. When sticky session is not used, the solution I can think of is to use a filter that will set a cookie with a value that identifies unique name of the Tomcat instance. This filter should have configuration option to disable enable this cookie based on a configuration. Any changes to the configurati...