Wednesday, May 27, 2009

Javascript - Calculating Elapsed Time

// using static methods
var start = Date.now();
// the event you'd like to time goes here:
doSomethingForALongTime();
var end = Date.now();
var elapsed = end - start; // time in milliseconds

// if you have Date objects
var start = new Date();
// the event you'd like to time goes here:
doSomethingForALongTime();
var end = new Date();
var elapsed = end.getTime() - start.getTime(); // time in milliseconds"

// About Date()
new Date()
new Date(milliseconds)
new Date(dateString)
new Date(year, month, date [, hour, minute, second, millisecond ])

today = new Date();
birthday = new Date("December 17, 1995 03:24:00");
birthday = new Date(1995,11,17);
birthday = new Date(1995,11,17,3,24,0);

Thursday, May 21, 2009

Linux Shell Script - Find Relative Path of Current Script

Linux Shell Script - Find Relative Path of Current Script:

"echo 'Path to $(basename $0) is $(readlink -f $0)'

CURRENTDIR=`dirname $0`
echo 'Path is: ${CURRENTDIR}'

reldir=`dirname $0`
echo 'RelDir $reldir'
cd $reldir
CURRENTDIR=`pwd`
echo 'Directory is ${CURRENTDIR}'
sh ${CURRENTDIR}/samp1.sh
sh ${reldir}/samp1.sh"

Wednesday, May 13, 2009

CSS Properties: Display vs. Visibility

CSS Properties: Display vs. Visibility: "CSS Properties: Display vs. Visibility
Browsers Targeted: Internet Explorer 3+

It's fairly easy to confuse the Cascading Style Sheets (CSS) properties display and visibility, because it would seem that they do much the same thing. However, the two properties are in fact quite different. The visibility property determines whether a given element is visible or not (visibility='visible|hidden'). However, when visibility is set to hidden, the element being hidden still occupies its same place in the layout of the page.


<script language='JavaScript'>
function toggleVisibility(me){
if (me.style.visibility=='hidden'){
me.style.visibility='visible';
}
else {
me.style.visibility='hidden';
}
}
</script>


<div onclick='toggleVisibility(this)' style='position:relative'>
This example displays text that toggles between a visibility of 'visible' and 'hidden'.
Note the behavior of the next line.</div><div>This second line shouldn't
move, since visibility retains its position in the flow</div>

This example displays text that toggles between a visibility of 'visible' and 'hidden'. Note the behavior of the next line.
This second line shouldn't move, since visibility retains its position in the flow

Note that when an item is hidden, it doesn't receive events. Thus in the sample code, the first sentence never detects that there has been a mouse click once the item is hidden, so you can't click the area to make it visible again. The display property, on the other hand, works a little differently. Where visibility hides the element but keeps its flow position, display actually sets the flow characteristic of the element. When display is set to block, for example, everything within the containing element is treated as a separate block and is dropped into the flow at that point as if it were a <DIV> element (you can actually set the display block of a <SPAN> element and it will act like a <DIV>. Setting the display to inline will make the element act as an inline element—it will be composed into the output flow as if it were a <SPAN>>, even if it were normally a block element such as a <DIV>. Finally, if the display property is set to none, then the element is actually removed from the flow completely, and any following elements move forward to compensate:


<script language='JavaScript'>
function toggleDisplay(me){
if (me.style.display=='block'){
me.style.display='inline';
alert('Text is now 'inline'.');
}
else {
if (me.style.display=='inline'){
me.style.display='none';
alert('Text is now 'none'. It will reappear in three seconds.');
window.setTimeout('blueText.style.display='block';',3000,'JavaScript');
}
else {
me.style.display='block';
alert('Text is now 'block'.');
}
}
}
</script>


<div>Click on the <span id='blueText' onclick='toggleDisplay(this)'
style='color:blue;position:relative;cursor:hand;'>blue text</span> to
see how it affects the flow.</div>

Click on the blue text to see how it affects the flow.

Notice that if the display property is not explicitly set, it defaults to the display type the element normally has. Of the two, the display property is definitely the more useful, as most instances of needing to hide text also involve shifting the surrounding HTML flow to accommodate it (think tree structures, as an example)."

Tuesday, May 12, 2009

ANT Task Sending Email to Multiple Receipients with attachments

ANT Task Sending Email to Multiple Receipients with attachments: <project name='SendMail' default='SendEmail'>

<target name='SendEmail'>
<property name='ToEmail' value='To.User1@gmail.com, To.User2@gmail.com'/>
<mail mailhost='smtp.gmail.com' mailport='465' subject='Test Mail from ANT' from='User.Name@gmailcom' tolist='${ToEmail}' user='User.Name@gmail.com' password='passwordhere' ssl='yes'>
<message>Hi, This is Test Mail. </message>
<fileset dir='${basedir}' includes='*.PDF'/>
</mail>
</target>
</project>

ANT Task - Delete Files and Directories

ANT Task - Delete Files and Directories :
<project default='DeleteFilesDirectories' basedir='.'>

<!-- @Ref: http://ant.apache.org/manual/CoreTasks/delete.html -->

<target name='DeleteFilesDirectories'>
<!-- Deletes All Files and Directories (Including Empty Directory) -->
<delete includeemptydirs='true'>
<fileset dir='${basedir}/User' includes='**/*'/>
</delete>

<!-- Deletes All Files and Directories (Excluding Empty Directory) -->
<!--
<delete includeemptydirs='true'>
<fileset dir='${basedir}/User' includes='**/*.*'/>
</delete>
-->

<!-- Deletes All Files and Directories (Including 'User' Directory itself) -->
<!--
<delete includeEmptyDirs='true'>
<fileset dir='User'/>
</delete>
-->

</target>
</project>

ANT Task [propertyregex] - String Replace

ANT Task [propertyregex] - String Replace:
<project name='PRJStringOperations' default='StringOperations' basedir='.'>

<!-- To Remove '' in EmailID's List -->
<typedef resource='./lib/antcontrib.properties' classpath='${basedir}/lib/ant-contrib-1.0b3.jar'/>

<property name='MailTo' value='''sakthi@gmail.com,sakthi@gmail.com'''/>
<target name='StringOperations'>
<propertyregex property='prop.MailTo'
input='${MailTo}'
regexp='([']*)(.*[a-zA-Z])([']*)'
select='\2'
casesensitive='false'/>

<echo message='${prop.MailTo}'/>
</target>

</project>

Thursday, May 7, 2009

Ant - Passing Argument in Command Line

Ant - Passing Argument in Command Line:

Case 1 : Using own bat file (ant.bat) for executing ant
=======================================================
Passing Arguments in Command Line
C:/ant/apache-ant-1.6.2/bin/ant.bat -DArg4First=SUN -DArg4Second=JAVA

In build.xml file
<project default='testAnt'>
<target name='First'>
<echo message='Input value is: ${Arg4First}' />
</target>

<target name='Second'>
<echo message='Input value is: ${Arg4Second}' />
</target>
</project>

Case 2 : Using another batch file(testCallAnt.bat) for calling ant.bat file
===========================================================================
Inside testCallAnt.bat will be,
C:/ant/apache-ant-1.6.2/bin/ant.bat -buildfile testAnt.xml First Second -DArg4First=SUN -DArg4Second=JAVA

Call the Batch file like this,
c:\Ant\> testCallAnt.bat %1 %2

Eg: c:\Ant\> testCallAnt.bat SUN JAVA