Monday, January 12, 2009

A very simple handy script...

At work, I use Linux for building our software package. Most of the time we will give build just before lunch, so that during the lunch break build will be done. And we, the lazy developers wait till the last minute to commit.. so people will be waiting for us to commit, so that they can start the build before lunch.. I got this idea today, so that we need not wait till everybody completes. We just delay the launch of the build by say 15 minutes so that you can execute the command and go for your lunch.. the lazy developer will commit in the meantime and the build kick starts without your presence..

Just 2 lines.. see below:
echo "Waiting for $1 seconds to launch $2"
sleep $1
$2

I saved the script as defer and put it in the /usr/local/bin directory. I did chmod to make the file executable.. so if i need to defer my build for 15 minute == 900 seconds

so my command will be:
defer 900 "make mytool"

there you go.. after 15 minutes your make will start... hurray!!

A realllly simple, handy script...

Paging database query

This is a very common scenario in web application where we have to show data in the DBMS in pages, since we cannot show indefinitely large quantity data in a browser in one go. I never tried it before and was wonder if it is easy to do that. To my surprise it is really easy to page the data in a web application. O/R mapping tools like hibernate makes the job even more easier.
Every RDBMS systems has a SQL syntax for limiting the amount of data chucked out.

With MySQL:
(any query you need to write) LIMIT {OFFSET}, {RECORD_PER_PAGE}


With Hibernate:
Query q = session.createQuery("...");
q.setFirstResult(start);
q.setMaxResults(length);
Pretty simple isn't it.. Please follow the below links for more reading..
Javalobby article on paging
Devx article on J2EE paging