Jan 31, 2026

Hi 👋 

My blogs home has been moved to my personal website:

🔗 https://www.lasantha.org/blog/

Please visit that page from now onward to see latest blog posts.

Thank you!  🙏

Sep 6, 2025

May 2, 2012

Apache 2 SSL setup in Ubuntu



I was trying to get SSL setup with Apache 2 Http server in Ubuntu. I've enabled the SSL module and restarted but I was getting this error:

Invalid method in request \x16\x03

After some googling, I've found this article http://ubuntuforums.org/showthread.php?t=806884 .  The following was the suggestion and it works.

sudo ln -s /etc/apache2/sites-available/default-ssl /etc/apache2/sites-enabled/000-default-ssl
sudo service apache2 restart

Apr 8, 2012

Mac OS X Lion and iTerm 2 Keybindings

I had to switch from Linux to Mac OS X Lion (10.7) at my work place. After getting used to Linux bash shell, I did not like the Mac terminal at all. I've install iTerm 2 and played with its keybindings and I've got the following useful keyboard shortcuts working.
  • To move cursor word-by-word  backward: Mapped Option + Left Arrow key to "Send Escape Sequence" and b
  • To move cursor word-by-word  forward: Mapped Option + Right Arrow key and "Send Escape Sequence" and f
  • To move cursor to the beginning of the sentence: Mapped Option + Up Arrow key to "Send Hex Code" and 1
  • To move cursor to the end of the sentence: Mapped Option + Down Arrow key to "Send Hex Code" and 5
  • To delete a word-byword ( backward-kill-word ): Mapped Option + BackSpace key to to "Send Hex Code" and 17
The keybindings can be changed from Preferences > Keys (or Preferences > Profiles > Keys). Since the profile level shortcuts were not useful I got rid of most of them from Preferences > Profiles > Keys.

Additionally, these built-in shortcuts will be useful:
  • Ctrl a : Goto the beginning of sentence.
  • Ctrl e : Goto the end of the sentence.
  • Ctrl w : Delete words backward.

These were couple of useful articles helped me to fix this:

Mar 23, 2011

Is your privacy safe online? (I don't think so)

I have recently found that there are several online people search site which list our name, address, age, phone number, job, photo & map of house, price of the house, parent's names and many more information.

You can search yourself on these sites and see the results:

It is dangerous to keep your privacy information listed online, as a quick search by your name will reveal most your details to any one in the world!
You can remove listing your details from those sites by:


But there may be some other sites doing the same, showing your privacy info. If you find any just remove yourself from that site (and let me know too).

This is a good article about this topic: urbanlegends.about.com/b/2010/04/07/spokeo-com-scam.htm

Feb 11, 2011

It takes only 18 days in Egypt

I was fortunate to see a peaceful revolution within my life. I have admired the peaceful movements by Gandhi and Martin Luther King Jr. But I did not see them from my eyes. Did not hear from my ears. All happened before I was born. But today that is not the case. Egypt is free as a result of a peaceful movement which lasted just 18 days. It is a historical day that we can tell to our grand children. Achievements from peace are more stable and far more valuable. There will be a lot of people 'alive' to celebrate that achievement, that's what make it more valuable. It is the people in Egypt who achieved this freedom. And it is up to the people in Egypt to protect what they have achieved. That is what the rest of the world is hoping for!

Oct 13, 2010

"In Chile, love moves the sun and stars"

It is a wonderful day to live in this world! 
As of 2.26 pm on Oct 13 2010, out of 33 miners trapped in an underground mine in Chile, 20 miners have been rescued. All the recue effort was broadcasted live. There was a nice article on CNN by Arturo Fontaine titled "In Chile, love moves the sun and stars". He ended his article saying: "Sometimes, after all, life is as it should be.", I do agree! 

Sep 10, 2010

EXT4 inode usage in Linux

I am using Linux (Ubuntu 9.10 Karmic) at my workplace and I have a 80GB SSD drive. So I've used almost the entire disk for the root partition (of 75GB) and formatted into 'etx4' file system. We have a large number of small files in our code path and I have several copies of them. Recently when I updated my code branch I got the folliwing error message:

svn: Can't open file '...somefile...': No space left on device

But I had more than 50% of free space left in my disk. When I checked for the usage of inodes (by "df -i") I found that I have hit the maximum number of inodes limit. For a 75DB ext4 partition, there were about 3.5 million inodes allocated. And I had only a little over 1 million files in the system. I do not know how ext4 had used up all the inodes but I found that when I removed my code branches from the file system, inode usage had dropped to 12%. 

So, after some discussion with my coworkers I've decided to create a separate partition using 'reiserfs' as it can better support a large file systems with small files. Since it omits the use of inode table, it does not assign a static number of inodes like in ext4. Now (I think) I do not need to worry about this issue anymore.

Jul 20, 2010

Twitter, Ruby and Scala

This is a good article about how and why Twitter folks rewrote some of their systems in Scala. Those components have been written in Ruby before and its really interesting to hear about their experiences in working with dynamically typed languages. Long live the JVM!

http://www.artima.com/scalazine/articles/twitter_on_scala.html

Lasantha Kularatne
Software Engineer
Bazaarvoice [site | blog | twitter]


Mar 30, 2010

A big hurrah for LCH

It is a historical day: March 30th, 2010
LHC (Large Hadron Collider) has started colliding particles today. World is celebrating it today.
This is the quest for finding Higgs boson, dark matter and studying the big bang theory.

The CNN report:
http://www.cnn.com/2010/TECH/science/03/30/large.hadron.collider/index.html?hpt=T2

Feb 28, 2010

OSx 10.5.7 with ATI Radeon HD 4870

For All Hackintosh enthusiasts,

I got my Diamond ATI Radeon HD 4870 512mb working successfully with QE/CI support. Used OSx 10.5.7 & Natit pkg.

  • I used iAtkos 5i (10.5.5) distro with Voodoo kernel. Selected the the VGA driver and compatible network, SATA driers.
  • Then I had to start in safe mode with ( -x ) kernel parameter. If you start in normal mode it will flicker and just show a blank & pixlated screen.
  • Then in safe mode I have updated to 10.5.7 from the Mac menu ‘Update’ option. This will install the Vanilla 9.7 kernel and I had to enable the vanilla kernel in Boot.plist file changing the kernel mode from ‘custom’ to ‘mach_kernel’. Remember I had to do it in single user (which is root console) mode with -s kernel parameter, because I could not find the root password for iAtkos distro.
  • After restart I still got the flickering, and then safe mode again and installed the Natit pkg.
  • Another restart… voila! It worked with hardware acceleration and QE/CI support in 1080P resolution.

I tried nVidia GTS 250 and GTX 260 but did not have any luck, so I had to gamble with a new 4870 and it paid off.

May 7, 2009

Intel Core i7 System

I am building my next gen pc with Intel's latest processor Core i7. This will be my system. I did not receive all the components yet to build the system, but will get them soon. I will keep the progress and photos posted.

CPU : INTEL Core i7 920
Motherboard : GIGABYTE GA-EX58-UD3R
Memory : OCZ 6GB DDR3 1600
Graphics : XFX Radeon HD 4850 1GB
PSU : CORSAIR 750w TX Series 80
Casing : ANTEC P180
Cooler : Noctua NH-U12P SE1366

Excited...

Feb 9, 2009

Dynamic Column Ordering of a Data Table using JSF & Facelets

I had a requirement for the project I am working on, to generate a data table with dynamic column ordering. I use JSF 1.2 and Facelets. There were several option I could have used meeting the following criteria.

  • It should be simple.
  • I did not want to write Java code to generate the data table.
  • Could be done in the JSF + Facelets tags only.
  • Should be fast.

So I did a lot of research and this is the solution I came up with.

<table>

<thead>
  <tr>
   <ui:repeat  value="#{mycontroller.columnIdList}" var="columnid">
    <ui:fragment rendered="${columnid == 1}">
     <th>My Column 1 Header</th>
    </ui:fragment>
    <ui:fragment rendered="${columnid == 2}">
     <th>My Column 2 Header</th>
    </ui:fragment>
    <ui:fragment rendered="${columnid == 3}">
     <th>My Column 3 Header</th>
    </ui:fragment>
   </ui:repeat>
  </tr>
</thead>

<tbody>
  <ui:repeat value="#{mycontroller.dataList}" var="data">
   <tr>
    <ui:repeat  value="#{mycontroller.columnIdList}" var="columnid">
      <ui:fragment rendered="${columnid == 1}">
        <td><h:outputText value="#{data.field1Value}" /></td>
      </ui:fragment>
      <ui:fragment rendered="${columnid == 2}">
        <td><h:outputText value="#{data.field2Value}" /></td>
      </ui:fragment>
      <ui:fragment rendered="${columnid == 3}">
        <td><h:outputText value="#{data.field3Value}" /></td>
      </ui:fragment>
    </ui:repeat>
   </tr>
  </ui:repeat>
</tbody>

</table>

 

As you can see here; I have numbered each column with a unique id, my controller has a list of column ids in the required order.

List<Integer> columnIds = new ArrayList<Integer>();

And I am reading the column ids in Facelets ui:repeat tag inside the table header row and putting it in the correct order. In the table body I have two ui:repeat tags; one to traverse through my data model objects list & another one to get the correct field according to the column order. The only problem I see here is, it has a complexity of O(n2). It can be trimmed down to O(n) by creating your own data table JSF component; which I did not want to do. And for a small number of columns, I think this this solution is fair enough.

If you are familiar with JSF ( and perhaps with Facelets too) the about piece of code is self-explanatory. Let me know if you have any questions. And also I would like to get your feed back.

Feb 2, 2009

Tech News: Ruby 1.9 is out…

There is a good news for the Ruby community. The major Ruby release 1.9 is out. It is said that the new version is twice as fast as 1.8.

Link: http://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/

Jan 27, 2009

Facelets

Features

  • New replacement for JSP with UI components and XML formatting.
  • Facelets can be used seamlessly with JSF.
  • No compile time overhead like JSP; faster.
  • Easy for UI designers as they can use existing XML/HTML development tools.
  • Easy to build custom components and templates using composite views.
Note: JSP is compiled in to a servlet, Facelets  use a fast SAX parser to build the page.

 

Getting Started

  • Download Facelets zip file and copy jsf-facelets.jar into WEB-INF/lib.
  • Modify faces-config.xml and set com.sun.facelets.FaceletViewHandler as the view handler. (This will override the default view handler setting which is expecting JSP file formats)

    <application>
        <view-handler>
        com.sun.facelets.FaceletViewHandler
        </view-handler>
    </application>

  • Modify web.xml file to give defaul suffix.

    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

Our JSF pages should have the file extension ‘.xhtml’ and you can have a servelet mapping '*.jsf' files for the  faces servlet. In that way, the actual page 'mypage.xhtml' can be accessed as 'mypage.jsf'.

 

How to Use

Templating

One of the main advantages of Facelets is its use as a templating tool for JSF pages. You simply creates a basic layout page, divide it into logical areas as you wish (with ui:insert tags) and implements the basic contents in those logical areas. Then, for any page in your application that you want to use the template just have to put ui:composition tag in the page and override any implementation of the logical areas with ui:define tag. This is a very simple and elegant way of doing page templating; something I was looking for quite a sometime. Let's see this example;

This is my template: layout.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<!--
Author      : Lasantha Kularatne
Date        : Jan 27, 2009
Version     : 1.0
Copy Rights :  Lasantha Kularatne
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
<ui:insert name="scriptslinks">
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<script type="text/javascript" src="../js/myjsfile.js"></script>
</ui:insert>
<title><ui:insert name="title">My Portal</ui:insert></title>
</head>
<body>
<!-- header -->
<ui:insert name="myheader"><ui:include src="header.xhtml"/></ui:insert>
<!-- data -->
<ui:insert name="mydata"></ui:insert>
<!-- footer -->
<ui:insert name="myfooter"><ui:include src="footer.xhtml"/></ui:insert>
</body>
</html>

I have divided my page into three logical areas called myheader, mydata and myfooter. I have basic implementations for header and footer in header.xhtml and footer.xhtml respectively, but not for the data area. Also I have two more logical areas for title and links/scripts.

Let's see how we can use this template: mypage.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="./layout.xhtml">
  <ui:define name="title"><h:outputText value="#{bundle.TESTPAGE_TITLE}" /></ui:define>
  <ui:define name="mydata">
    <h:form id="MyForm">

      ...

    </h:form>
  </ui:define>
</ui:composition>
</html>

As you can see here, I have overridden the title and data areas. I put the title reading from my resource bundle and I have used a JSF form element in m data area. <ui:composition> tag is used to compose the page and notice that template reference (layout.xhtml). You have to give the template file name with the relative path. 

 

Composite Components

It is very easy to build composite components with Facelets. All you have to do is use a ui:component tag and include you code. When ever you want to use that component, you simply have to include that file. Let's look this example: mycomponent.xhtml.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<ui:component>
    <div id="mylogo">
        <a href="
http://www.mycompanypage.com">       
            <span>My Company Pvt Ltd.</span>           
        </a>
    </div>
</ui:component>
</html>

Notice that, although here we have some tags around ui:component tag, those will be discarded by the Facelets engine. Those tags are there only  to identify the page by editors.

 

Commonly Used Tag Libraries

  • JSF Core Tag Library (xmlns:f="http://java.sun.com/jsf/core")
  • JSF HTML Tag Library (xmlns:h="http://java.sun.com/jsf/html")
  • Facelets UI Tag Library (xmlns:ui="http://java.sun.com/jsf/facelets")
  • JSTL Standard Tag Library (xmlns:c="http://java.sun.com/jstl/core")
  • JSTL Functions Tag Library (xmlns:fn=http://java.sun.com/jsp/jstl/functions)

 

Facelets UI Tag Library

For further information, read about these tags and get familiar how you can use them in your project.

 

References

  1. Sun Java official Facelets page.
  2. Facelets Documentation.
  3. Facelets fits JSF like a glove.
  4. FaceletsTools for Dreamweaver.

Dec 10, 2008

JavaScript Performance Testing with 'SunSpider'

I have done some web browser benchmarking with SunSpider benchmark test. I used the following browsers;
  • Chrome 0.4
  • Firefox 3.0.4
  • Opera 9.61
  • IE 6
  • Safari 3.0.3
I found that Google Chrome outperformed all the browsers, and it was 30X faster than IE! There was something going wrong with Safari, it did not even finish the test; it stopped at 'controlflow-recursive' test and did not proceed.


Welcome Back!

Hello There... After a long time I am writing to my personal blog. First I want to apologize for a long delay. This year was a very busy and exciting one for me. Well the big news is I got married in last December and now I am living in Austin with my wife, Natasha. Married life is kind of busy :) and interesting; with some added responsibilities. I am planning to visit Sri Lanka soon and will be back in January 2009. I will post to my blog frequently when I come back. (NO, I mean it, there will not be more long gaps in my blog).

There are some interesting articles I would like to post about the new things I learnt and done in specially Java, Spring, Hibernate, Facelets, CSS, Unit Testing with DBUnit and H2 database etc. I got lot to share, so don't go away, stay tuned!

Aug 22, 2007

Interview with Linus Torvalds about the Linux Kernel

I was reading an interview with Linus Torvalds about the Linux Kernel and related topics. There were very interesting ideas he brought up. The most interesting answer ,as I saw, he gave was to the following question.

APC: Do you use a specific distribution of Linux at home or work?

LT: A "specific" one? No. I have changed distributions over the years, and it tends to really end up depending on various random circumstances, like just when I switch machines around and what happens to be convenient.

So right now I happen to run Fedora on my machines, which largely came about from me running on POWER for a few years, and Fedora supported it pretty well (and since I actually don't care that deeply about the distribution, I tend to prefer running the same thing on everything, just to keep any distro issues away).

Before Fedora had PowerPC support, I ran YDL for a while, and before that I had SuSE. Funnily enough, the only distributions I tend to refuse to touch are the "technical" ones, so I've never run Debian, because as far as I'm concerned, the whole and only point of a distribution is to make it easy to install (so that I can then get to the part I care about, namely the kernel), so Debian or one of the "compile everything by hand" ones simply weren't interesting to me.


Interesting ha?


You can read the whole interview here.


- Lasantha

Aug 14, 2007

Did Life Begin In Space? New Evidence From Comets

This is the view of Scientist Chandra Wickramasinghe.... http://www.sciencedaily.com/releases/2007/08/070814093819.htm
- Lasantha

Extracted from Science Daily...

Science Daily Recent probes inside comets show it is overwhelmingly likely that life began in space, according to a new paper by Cardiff University scientists.


Artist's impression of the Deep Impact comet probe. (Credit: NASA)

Professor Chandra Wickramasinghe and colleagues at the University's Centre for Astrobiology have long argued the case for panspermia - the theory that life began inside comets and then spread to habitable planets across the galaxy. A recent BBC Horizon documentary traced the development of the theory.

Now the team claims that findings from space probes sent to investigate passing comets reveal how the first organisms could have formed.

The 2005 Deep Impact mission to Comet Tempel 1 discovered a mixture of organic and clay particles inside the comet. One theory for the origins of life proposes that clay particles acted as a catalyst, converting simple organic molecules into more complex structures. The 2004 Stardust Mission to Comet Wild 2 found a range of complex hydrocarbon molecules - potential building blocks for life.

The Cardiff team suggests that radioactive elements can keep water in liquid form in comet interiors for millions of years, making them potentially ideal "incubators" for early life. They also point out that the billions of comets in our solar system and across the galaxy contain far more clay than the early Earth did. The researchers calculate the odds of life starting on Earth rather than inside a comet at one trillion trillion (10 to the power of 24) to one against.

Professor Wickramasinghe said: "The findings of the comet missions, which surprised many, strengthen the argument for panspermia. We now have a mechanism for how it could have happened. All the necessary elements - clay, organic molecules and water - are there. The longer time scale and the greater mass of comets make it overwhelmingly more likely that life began in space than on earth."

The new paper, The Origin of Life in Comets, by Professor Wickramasinghe, Professor Bill Napier and Dr Janaki Wickramasinghe is to be published shortly by the International Journal of Astrobiology.

Note: This story has been adapted from a news release issued by Cardiff University.