Monday, June 29, 2009

Limiting number of rows in Database

// mysql
select col from tbl limit 20;

// Oracle
select col from tbl where rownum<=20;

// Microsoft SQL
select top 20 col from tbl;

Sunday, June 21, 2009

Use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup

Using the FindBugs tool
Inefficient use of keySet iterator instead of entrySet iterator

This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.
if(hashMap != null) {
Set set = hashMap.keySet();
Iterator it = set.iterator();
if (messageId!=null)
string += "MSGID=" + messageId + " ";
string += "TAG Details:{";
while(it.hasNext()) {
Integer intValue = (Integer)it.next();
string += GetTagName(intValue.intValue()) + "(" + intValue + ")=" + hashMap.get(intValue);
if (it.hasNext()) string += ", ";
}
}


instead use hashMap.entrySet()

Monday, June 15, 2009

Generating Dummy umf message files

sh-3.2$ while true; do cp esmehub_72502044_0001_20.UMF esmeHub$RANDOM.umf
> done

Thursday, June 11, 2009

Epoch time Conversion

Epoch Time Conversion
Just in case above website is down
What is epoch time?
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds. The epoch timestamp 0 can be written in ISO 8601 format as: 1970-01-01T00:00:00Z. One epoch hour is 3600 seconds, one epoch day is 86400 seconds long, leap seconds are not calculated. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).

Human readable time Seconds
1 minute 60 seconds
1 hour 3600 seconds
1 day 86400 seconds
1 week 604800 seconds
1 month (30.44 days) 2629743 seconds
1 year (365.24 days) 31556926 seconds


How to get the current epoch time in ...
Perl time
PHP time()
Ruby Time.now (or Time.new). To display the epoch: Time.now.to_i
Python import time first, then time.time()
Java long epoch = System.currentTimeMillis()/1000;
Unix/Linux date +%s
Other OS's Command line: perl -e "print time"

Monday, June 8, 2009

GetStackTraceFromException

public static String GetStackTraceFromException(Exception e)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);

return sw.toString();
}

Sunday, June 7, 2009

MSSQL For dumping

dump transaction partner4_bulkmsg with no_log