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;
static{
System.out.println("hi");

}

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

class worker1 implements Runnable {

@Override
public void run() {
while(true)
synchronized(ThreadChck.check ){
try {
ThreadChck.check.wait(200);
if(flag==1){
System.out.println("a");
flag=0;}
} catch (InterruptedException ex) {
Logger.getLogger(ThreadChck.class.getName()).log(Level.SEVERE, null, ex);
}


}

}

}
class worker2 implements Runnable {

@Override
public void run() {
while(true)
synchronized(ThreadChck.check ){
try {
ThreadChck.check.wait(200);
if(flag==0){
System.out.println("b");
flag=1;}
} catch (InterruptedException ex) {
Logger.getLogger(ThreadChck.class.getName()).log(Level.SEVERE, null, ex);
}


}

}
}
}

Tuesday, October 4, 2011

Distributed Computing Technologies

NOSQL Databases
Cassandra
Mongo DB
HBase
Hypertable

Other Technologies
Hadoop
Hive
Pig
flume
sqoop

Lily

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

MYSQL

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';
 
http://www.javascriptkit.com 
 
http://www.hunlock.com/blogs/Functional_Javascript 


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());
keyInput.close();

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.


package com.cisco.swtg.testing;

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

public class Selenium2Example {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.bin","%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
System.setProperty("webdriver.firefox.bin","C:\\FirefoxPortableLegacy35\\FirefoxPortable.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(By.id("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
chromedriver.get("http://www.cisco.com/cisco/psn/sasi");

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


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

WebElement element2 = chromedriver.findElement(By.name("PASSWORD"));
element2.sendKeys("your-password");

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

try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

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



chromedriver.findElement(By.id("searchTextBox")).sendKeys("gagandsi");
chromedriver.findElement(By.id("searchButton")).submit();
WebElement username= chromedriver.findElement(By.className("ft-label"));
chromedriver.findElements(By.className("ft-label"));
username.getText();
if(chromedriver.getPageSource().contains("UserName"))
System.out.println("User logged in Successfully");
// Check the title of the page
System.out.println("Page title is: " + chromedriver.getTitle());

//Close the browser
chromedriver.quit();
}
}


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
1.5

to properties tag in Maven pom file.



<properties>
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
<compileSource>1.5</compileSource>
<targetJdk>1.5</targetJdk>
</properties>

Friday, May 27, 2011

Generating html from xml using xsl


<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xml=loadXMLDoc("findbugsXml.xml");
xsl=loadXMLDoc("fancy.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("example").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(resultDocument);
}
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>

Converting raw html to escaped html

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

maven reports


<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<links>
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
</links>
</configuration>
</plugin>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.0</version>
</plugin>
<!-- <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> -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.3-SNAPSHOT</version>
</plugin>

</plugins>
</reporting>


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.*;
import java.net.*;
import java.io.*;

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

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer transformer =
tFactory.newTransformer
(new javax.xml.transform.stream.StreamSource
("C:\\xampp\\htdocs\\s3\\fancy-hist.xsl"));

transformer.transform
(new javax.xml.transform.stream.StreamSource
("C:\\xampp\\htdocs\\s3\\findbugsXml.xml"),
new javax.xml.transform.stream.StreamResult
( 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
port="8888"
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.

http://www.oracle.com/technetwork/developer-tools/jdev/ui-debuger-087839.html

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
http://glasstools.kedges.com/ThePoint/Install

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


org.eclipse.wst.common.project.facet.core.builder



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

org.eclipse.wst.common.project.facet.core.nature

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

Development

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

Leisure
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

http://www.soaplite.com/2003/06/installation_in.html

Sunday, February 6, 2011

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

IDE
1) Eclipse
2) Netbeans
3) JDeveloper


Editors

1) Notepad++


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

Media
1) Vlc Player


Browser
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.
http://discussions.apple.com/thread.jspa?threadID=2135129&start=555&tstart=0
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.