09 January 2010

available memory less than 128mb!!! -1 half life 2

Half Life 2 has got some problem on Vista 64 bit, it keeps crashing with a pop up message:
 available memory less than 128mb!!! -1
Solution for this is to run Half Life in Windows XP Compatibility Mode, right click on the short-cut of Half Life, click on the Compatibility tab, select Run this program in compatibility mode for:  

06 January 2010

Enable GZip Compression on Glassfish v3

Login to https://localhost:4848 (admin panel). Go to the Network Config > Network Listener and select the listener for which you want to enable gzip. Click on the HTTP tab, see below:

Scroll down until you get the following entries:

Select Compression= on, Put the mime types and click on Save button.
Its done!!

03 January 2010

mysql and jtpl template engine tutorial

jtpl is a light-weight java template engine, which is good for small size application but becomes sludgy for data intensive apps. Following example shows how to use jtpl with mysql.

jtpl replaces everything which is put inside {} and it uses html comments as entry and exit points
< ! -- BEGIN: main -- >
{This will be replaced by jtpl}
< ! -- END: main -- >
this template file should be saved with the extension .jtpl
In your servlet you need to create a Template object which will take template file as input parameter.
Template tpl = new Template(new File("FULL_PATH\\home.jtpl"));
 next you need to assign the value to the template parameters like:
tpl.assign("ThisToo", "Assigned Value Here !"); 
in the end template is parsed using
If you have nested template regions in a template like this:

< ! -- BEGIN: main -- >
< ! -- BEGIN: header-- >
< ! -- BEGIN: header-- >
< ! -- END: main -- >
Everything remains same except when you parse, you'll have to parse the inner region first, like:
then the outer (or main) region:
You can put as many regions you want inside a main region.
Using jtpl with mysql(or any other db) is simple as explained above. Here is a sample template file home.jtpl:
<!-- BEGIN: main1 -->
                       <a class="a" href="/anylink1">{LINK1}</a>
                       <a class="a" href="/anylink2">{LINK2}</a>
                       <a class="a" href="/anylink3">{LINK3}</a>
                        <!-- BEGIN: div -->
                                <a target="_blank" href ="{LINK}">{TITLE}</a>
                        <!-- END: div -->
<!-- END: main1 --> 
and here is the Servlet:
import net.sf.jtpl.Template;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

 * @author viksin
public class sample extends HttpServlet {

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {
        } catch (Exception e) {
        } finally {

    protected String generatePage() throws Exception {
        Template tpl = null;
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        String Content = "";
        TimeCalc tc = new TimeCalc();
        tpl = new Template(new File("FULL_PATH\\home.jtpl"));
        tpl.assign("PTITLE", "MySite");
        tpl.assign("LINK1", "Home");
        tpl.assign("LINK2", "News");
        tpl.assign("LINK3", "About");
        try {
            conn = DriverManager.getConnection("mysql_URL", "USERNAME", "PASSWORD");
            st = conn.createStatement();
            rs = st.executeQuery("select title,link,content from table");
            while (rs.next()) {
                tpl.assign("TITLE", rs.getString("title"));
                tpl.assign("CONTENT", rs.getString("content"));
                tpl.assign("LINK", rs.getString("link"));
        } catch (Exception ex) {
            return ex.toString();
        } finally {
            if (rs != null) {
            if (st != null) {
            if (conn != null) {
        return (tpl.out());
jtpl is meant for small and simple applications, it does not have many features which other template engines like velocity, stringtemplate etc. have.
jtpl also uses the SingleThreadModel which is not recommended also it gets slower with large data.
Presently I am using StringTemplate which is faster and better than jtpl.

Bad Old Year! Happy New Year!

2009: One of the worst years of my life!

Here are a few facts which support above statement:

1. Got cheated for USB modem in March.
2. Got chicken-pox in April.
3. Lost money in shares in June
4. Father got into a major accident in Oct.
5. Got back pain in Nov.
6. Troubles at workplace (Whole Year!)

There were a few good moments too:

1. Got a beautiful niece (Asmi) on 7th March.
2. Had fun with college friends in Ahemdabad and Mumbai.
3. Watched following TV Series:
1) The Sopranos
2) Carnivale
3) Scrubs
4) Dead Like Me
5) 24
6) The Life and Times of Tim
7) Rome
8) John Adams
9) Avatar the last Airbender
10) Psych
11) That 70's Show
12) Curb Your Enthusiasm
13) Dexter
14) Heroes
15) Bones
2010: Expectations!

1. Complete the development of 9am.in, algowiki.com, showthe.info/about, paltan.org, index3r.com
2. Complete remaining TV series: The Wire, OZ, Deadwood, Futurama, Meerkat Manor, Generation Kill, Mash, Six Feet Under,Twin Peaks, From the Earth to the Moon
3. Self Employment
4. Get a powerful server for natmac.org