Friday, April 9, 2010

J2EE

Core Java

1) Read From File, JDBC Querry, write to a output File
2) List all Files in a Directory

Shell Script

Thursday, March 11, 2010

List all directories under a path and Print current directory through JAVA code

Below is source code for the same:


import java.io.File;

import java.io.FileFilter;

import java.io.IOException;



public class direcotryName {

public static void main(String[] args){

File dir=new File("/Users/admin");

File[] subDirs = dir.listFiles(new FileFilter() {

public boolean accept(File pathname) {

return pathname.isDirectory();

}

});

for (File subDir : subDirs) {

System.out.println("path :"+subDir.getPath());

}

//print current working directory...

File f = new java.io.File(".");

try {

System.out.println(f.getCanonicalPath() );

} catch (IOException e) {

e.printStackTrace();

}

}

}



Wednesday, December 9, 2009

Namespace approach to call a javascript method

html snippet:

javascript snippet: index.js
myApp = new Object();

myApp.fun=function(method1){
alert('inside overidden method');
if(arguments.length == 1)
window[method1]();
else if(arguments.length == 2)
window[method1](arguments[1]);
else if(arguments.length == 3)
window[method1](arguments[1], arguments[2]);
else if(arguments.length == 4)
window[method1](arguments[1], arguments[2], arguments[3]);
else if(arguments.length == 5)
window[method1](arguments[1], arguments[2], arguments[3], arguments[4]);
};
function invokerMethod(method){
if(typeof myApp != "undefined"){
myApp.fun(method);
}
else{
alert('namespace is not created for this release');
fun(method);
}
}

Actual method: test.js
function one(){
alert('actual method....');
}

Monday, November 23, 2009

Shell script: check for a exact pattern in a file


-----------------------------------------
#!/bin/sh
#bash
#generatehtml.sh

if [ -f output ]
then rm output
fi

if [ -f discussionJumpPage.html ]
then rm discussionJumpPage.html
fi

echo 'http://blind.apple.com/featured/featuredlist.php' >> output

baseUrl='http://blind.com/featured/featuredlist.php?limit=500&skip='
flag=1
skip=500

while [ $flag -eq 1 ]
do
url=$baseUrl$skip
echo $url >> output
if curl -l $url | grep -o '>next 500<'
then
skip=`expr $skip + 500`
echo "skip = "$skip
else
flag=`expr $flag - 1`
fi


Shell script to read lines from a file

1) Read lines from a file having only one word in each row
-----------------------------------------------
for server in `cat $SERVER` # file name
{
echo "Starting scp to server :...... "$server
}
-----------------------------------------------

here each line will come in variable server. SERVER is the name of the input file which is a variable file name. If there are two words in one line then second word would be read in next loop.

2) Now suppose you want to read complete line in the same iteration, then below approach would help:
------------------------------
while read inputline
do
docId="$(echo $inputline | cut -d" " -f1)" #seperated by space
localeId="$(echo $inputline | cut -d" " -f2)"
echo doc = $docId and locale = $localeId
done (less than sign ) REPORT
--------------------------------