Saturday, November 26, 2011

Yes this works

* To change this template, choose Tools | Templates
* and open the template in the editor.
package com.check;

import java.util.logging.Level;
import java.util.logging.Logger;

* @author gagandsi
public class ThreadChck {

public static Object check = new Object();
public static volatile int flag= 0;


public static void main(String args[]){
ThreadChck obj= new ThreadChck();
new Thread( worker1()).start();
new Thread( worker2()).start();

class worker1 implements Runnable {

public void run() {
synchronized(ThreadChck.check ){
try {
} catch (InterruptedException ex) {
Logger.getLogger(ThreadChck.class.getName()).log(Level.SEVERE, null, ex);



class worker2 implements Runnable {

public void run() {
synchronized(ThreadChck.check ){
try {
} catch (InterruptedException ex) {
Logger.getLogger(ThreadChck.class.getName()).log(Level.SEVERE, null, ex);



Tuesday, October 4, 2011

Distributed Computing Technologies

NOSQL Databases
Mongo DB

Other Technologies


Monday, September 26, 2011

Replacing space with underscore in Javascript

I tried providing a title for a custom javascript dojo component but it took only the first word i guess this was because space was not being handled properly so i searche dfor javascript code to replace space with &nbsp. Following is the code

.split(' ').join('_')

Wednesday, September 21, 2011


Changing root password for MySQL : Change root password for MySQL
Command to import an sql dump file : mysql -u username -p password database_name < filename.sql  
MySQL employees database link :MySQL Employees Database Link

Sunday, September 11, 2011

CSS Related

// Entry for style for all elements having an id myid
#myid {
             width:550px; some-other-attribute: some-value;
// Entry for style for all elements having class myclass
.myclass {
width:550px; some-other-attribute: some-value;
// Entry for style for a tag in html body
body {
width:550px; some-other-attribute: some-value;
You can use divs with the float: left; attribute which will make them appear horizontally next to each other, but then you may need to use clearing on the following elements to make sure they don't overlap.  Adding Options to Select Element in Html

Adding inner html to an element in Html
document.getElementById('boldStuff').innerHTML = 'Fred Flinstone'; 

Friday, August 26, 2011

Maven Vanilla Stuff

If you have a simple java project which is made up of only one module, using eclipse is very simple. To generate the eclipse project files from your POM you execute the following command:

mvn eclipse:eclipse

Eclipse needs to know the path to the local maven repository. Therefore the classpath variable M2_REPO has to be set. Execute the following command:

mvn -Declipse.workspace= eclipse:add-maven-repo
From Here

Thursday, August 4, 2011

df not showing correct free size after deleting a file

Some times when you delete a file df does not show the true file size (i.e. it does not consider the deleted file size ). This is due to the fact that some processes still have a handle on the file i.e. they might still be using the file. This can be confirmed by the following command

as root run "lsof -n | grep file

to see the list of processes still having a handle on file.

You may kill the processes or restart the system to fix this.

Saturday, July 23, 2011

My Experiments with Dojo

I was trying out a simple example with dojo and was trying to use dojo's event api.
I created a button my button and created a sample function foo.

I did dojo.connect(dojo.byId('mysamplebutton'),'onclick', foo);
to my amazement dojo connected the all the click in the windows to foo and not just for this button. I later discovered that this is a mistake as i should use dojo.ready or dojo.addOnLoad to do this otherwise dojo.byId returns null which makes this event connect to the whole window.

More on this here.
Dojo connects all onclik

Tuesday, June 21, 2011

Khayyam On God and Torment

Thou hast said that Thou wilt torment me,
But I shall fear not such a warning.
For where Thou art, there can be no torment,
And where Thou art not, how can such a place exist?

Friday, June 10, 2011

Syntax highlighter script Syntax

Syntax Highlighter

Configuring sonar

I thought i would configure Sonar for my project, which is a Maven archetype Portal Project. Following details the process followed.
1) Download Sonar 2.8 ( Earlier i downloaded sonar 2.7 and got lot of errors due to some bugs not yet fixed in 2.7 , so i recommend sonar).
2) Went into the windows 32 x86 dir and ran startSolar.bat
3) Ran

mvn -X -e clean install sonar:sonar -Dmaven.test.failure.ignore=true

I prefer -X -e because it gives a detailed list of what is going on.

Tuesday, June 7, 2011

Client cert authentication with java

Taken from here

private SSLSocketFactory getFactory( File pKeyFile, String pKeyPassword ) throws ... {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509);
KeyStore keyStore = KeyStore.getInstance("PKCS12");

InputStream keyInput = new FileInputStream(pKeyFile);
keyStore.load(keyInput, pKeyPassword.toCharArray());

keyManagerFactory.init(keyStore, pKeyPassword.toCharArray());

SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());

return context.getSocketFactory();

URL url = new URL("https://someurl");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(getFactory(new File("file.p12"), "secret"));

Sunday, June 5, 2011

Simple code for Unit Test using WebDriver / Selenium 2

Following is a simple java test to do some testing using Selenium 2 in java.


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class Selenium2Example {
public static void main(String[] args) {
System.setProperty("","%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe");
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver chromedriver=null;
WebDriver driver = new ChromeDriver();//new InternetExplorerDriver();// new HtmlUnitDriver();// FirefoxDriver();ChromeDriver
if (driver instanceof ChromeDriver){
chromedriver = (ChromeDriver)driver;

//chromedriver.findElement("Enter id here"));
}else {
if (driver instanceof FirefoxDriver)
chromedriver= (FirefoxDriver)driver;
else {
if (driver instanceof HtmlUnitDriver)
chromedriver= (HtmlUnitDriver)driver;
// And now use this to visit Google

// Find the text input element by its name
WebElement element = chromedriver.findElement("userInput"));
// FirefoxWebElement ele=(FirefoxWebElement) driver.findElement("USER"));;

// Enter something to search for
element.sendKeys("your - username");

WebElement element2 = chromedriver.findElement("PASSWORD"));

WebElement element3 = chromedriver.findElement("login-button"));

try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block

// Now submit the form. WebDriver will find the form for us from the element
// element.submit();
try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block

WebElement username= chromedriver.findElement(By.className("ft-label"));
System.out.println("User logged in Successfully");
// Check the title of the page
System.out.println("Page title is: " + chromedriver.getTitle());

//Close the browser

What i am up to

Attended Certified ScrumMaster Training by Pete Deemer. Loved it.
Have to give a session on Automated Functional UI Testing using Selenium, so preparing for the same.Discovered that it is still in it's nascent stage. Evaluating Selenium 2 WebDriver. Also have a Dojo training to attend on 9th and 10th of this month. Also have to work on connecting to a website using client certificate authorization.
Prepare for the SCRUM test.

Saturday, May 28, 2011

PMD Maven problem

Can't use generics unless running in JDK 1.5 mode!
Can't use annotations when running in JDK 1.4 mode!

Just add

to properties tag in Maven pom file.


Friday, May 27, 2011

Generating html from xml using xsl

function loadXMLDoc(dname)
if (window.XMLHttpRequest)
xhttp=new XMLHttpRequest();
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
return xhttp.responseXML;

function displayResult()
// code for IE
if (window.ActiveXObject)
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
xsltProcessor=new XSLTProcessor();
resultDocument = xsltProcessor.transformToFragment(xml,document);
<body onload="displayResult()">
<div id="example" />

Converting raw html to escaped html

Converting raw html to escaped html
Add formatting to code in blogger

maven reports

<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version> <reportSets> <reportSet> <reports> <report>dependencies</report>
<report>project-team</report> <report>mailing-list</report> <report>cim</report>
<report>issue-tracking</report> <report>license</report> <report>scm</report>
</reports> </reportSet> </reportSets> </plugin> -->


Maven Build targets
mvn findbugs:findbugs
mvn jxr:test-jxr
mvn jxr:jxr
mvn surefire-report:report
mvn surefire:tests
mvn checkstyle:checkstyle
mvn project-info-reports:dependencies
mvn project-info-reports:cim
mvn project-info-reports:index
mvn javadoc:javadoc
mvn site:run
mvn help:effective-pom

java code to transform xml to html using xsl

package com.trans;

import javax.xml.transform.*;

public class HowToXSLT {
public static void main(String[] args) {
try {

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer transformer =

( new FileOutputStream("C:\\howto.html")));
catch (Exception e) {
e.printStackTrace( );

Friday, April 29, 2011

View PID along with port in netstat on Windows

netstat -ano

Adding Windows Environment Variables

Adding environment variable to windows at command line :
set ORACLE_HOME=C:\oc4j

Remember no space between = on either side. Also avoid names with spaces or use "" to habdle spaces.

Default Port for OC4j 8888

Hi the default port for OC4j is 8888 and can be found at oc4j\j2ee\home\config\default-web-site.xml
display-name="OC4J 10g (10.1.3) Default Web Site"

Sunday, April 24, 2011

Debugging Swing Applications

A cool trick to debug Swing Application. Often when debugging swing applications we require to know where the code for a particular textbox or drop down or any other swing component is. If this is a huge legacy application chances of finding the code easily are slim. This is where i would recommend you check out JDeveloper. Jdeveloper has this cool feature that when you launch a swing application in UI debug mode , you can click on the swing component in the running application and directly go to its code.

Also if the whole application root panel is getting selected try changing your desktop resolution and relauch the application . It worked for me ;-).

Also check out

Saturday, March 26, 2011

Java tzmappings error

I used props.put("java.home", "C:\\Program Files\\Java\\jdk1.6.0_24");
to set my java home in my java program which gave me a can't open C:\Program Files\Java\jdk1.6.0_24\lib\tzmappings error. This error can e removed by copying tzmappings file from your JRE lib directory which in my case is
C:\Program Files\Java\jre6

Thursday, March 10, 2011

Convert Java Project to Web Project in Eclipse

1) Create a empty dynamic web project and click on the .project file
2) Copy “web project” facet buildCommand and paste within “java project” .project buildSpec tag


3)Copy “web project” facet nature and paste within “java project” .project natures tag


P.S Be careful of the .project xml tag, make sure you paste into a correct location.

4) Save it.

5) Right click on Java Project, click properties.

6) Select Project Facets and click modify project button.

7) Click Dynamic Web Module and Java check box.

Sunday, February 20, 2011

Stuff to install on new Laptop

Get Windows Xp instead of Seven


1) Netbeans 7
2) Notepad++
3) Putty
4) Winscp
5) Eclipse Classic
6) MyEclipse from DFT
7) Maven
8) Jetspeed 2

1) VLC
2) IView
3) Consolas Font from Microsoft
4) ALT + TAB utitlity
5) CCleaner
6) Firefox
-- Xmarks
-- FireBug
7)Clear Type Tuning Utility
8) Command Prompt Here

Tuesday, February 8, 2011

SOAP::Lite for Perl

Sunday, February 6, 2011

Stuff I install after a new Windows Installation (Developer Machine)

1) Eclipse
2) Netbeans
3) JDeveloper


1) Notepad++

1) Putty and Putty reg
2) Winscp
3) Kdiff / Winmerge (Beyond Compare )
4) 7 Zip

1) Vlc Player

1) Firefox (Xmarks plugin)

Saturday, January 22, 2011

Learning Mac 2

In order to delete files on Mac just drag them into the trash and they get un-installed. This is quite different from windows. Mac generally stores all the files required by an application in its folder, I think this is kind of like portable apps.

Also was disappointed with Mac finder which keeps throwing
The application finder cannot be opened error
what is more disappointing is the fact that this issue has been around a long time and has not been fixed.
Also sucks that you can't use NTFS on Mac i mean you can read NTFS but can't write on it.

Some apple tricks
Then on boot up, booted into UNIX by holding down command 'S' until the screen goes black and white text appears.
fsck -fy

To perform a Safe Boot, hold the Shift key as your Mac starts up.

Key to hide all other open windows and simply show the desktop

Try FN F11
If you have a Magic Trackpad you can also do this with a 4 finger swipe up.

Tuesday, January 18, 2011

Learning MAC 1

In order to use function keys for Debugging in Eclipse in MAC one needs to use a combination of fn key and the function key.

Got a new MAC

Got a new MAC . Just trying to figure out how to use it. Will use this blog to track all i learn.