Friday, November 6, 2009

Removing external Javascript from Spring 3 documentation with jEdit

The Spring 3 reference in HTML format loads Javascript files from external sites. It's a bit annoying to wait for the loading of the scripts, particularly when I need to navigate between the pages frequently.

I used jEdit to search for the following regular expressions in the HTML files and replace them with a space
(?s)Begin Google Analytics code.*End Google Analytics code

(?s)Begin LoopFuse code.*End LoopFuse code

Thursday, November 5, 2009

Problems creating a JDBC resource with Glassfish 3 and PostgreSQL 8.4 drivers

What I initially thought was a straight-forward task turns out to be more complex than I imagined. After dumping the jars for PostgreSQL 8.4 driver (postgresql-8.3-701.jdbc3.jar
, postgresql-8.4-701.jdbc4.jar) into <GLASSFISH>/domains/domain1/lib/databases, I started the GF 3 server and tried to create a connection pool. I tried to create a javax.sql.ConnectionPoolDataSource resource using org.postgresql.ds.PGConnectionPoolDataSource. However I kept getting this error:
Can't find ConfigModel.Property for attr -isolation-level-guaranteed on interface com.sun.enterprise.config.serverbeans.JdbcConnectionPool

I get this error even when I do not specifiy "guranteed" for the isolation level.

Googling around,  I finally found someone with a similar problem. Seems that there is a bug in some of the earlier builds, so I downloaded the latest build (build 70)and reinstalled GF3.

All's well? Not quite. When I tried to start the server, I get some problem with using port 7676 for the default JMS host. I dont think I've gotten this error before in the older builds. Well, I did change the http-listener-2 port in domain1's domain.xml, not sure if I introduced some typo error there, so I ran
asadamin verify-domain-xml

and checked that the domain.xml is ok. The error is something along the line of
java.net.SocketException: Address family not supported by protocol family: bind

It turns out that for some reason the new GF3 build has problem using Vista's default hosts file (at C:\Windows\System32\drivers\etc).

To get it to work, change
::1 localhost

to
127.0.0.1 localhost
#::1 localhost

Restart the server again.

Now proceed to create the connection pool. However, according to the PostgreSQL driver download website,
It comes in two flavors, JDBC3 and JDBC4. If you are using the 1.6 JVM, then you should use the JDBC4 version.

.....

JDK 1.6 - JDBC4. Support for JDBC4 methods is limited. The driver builds, but the majority of new methods are stubbed out.

So, you'll need to specify an additional property JDBC30DataSource and set it to true when configuring the connection pool. That should be about it, now you can get some real work done.

Thursday, September 24, 2009

Overheard conversations

I was at Cash Converters the other day, rummaging through some stacks of CDs when I heard this conversation between a female customer and a male sales assistant.
女:请问你们有PS2吗?

男:有。

女:怎么卖?

男:69快。

女:是不是买回家就可以玩?

男:我们保证原装的disc可以玩。

女:这样说就是不可以玩啦?

男:如果是原装的disc一定可以玩。如果不可以玩,可以拿回来换。

女:那么pirated的可以玩吗?

男:我们只保证原装的disc可以玩。

女:那么就是pirated的不可以玩啦?

男:小姐,你还是听不懂我的意思。

For those who don't read Chinese, here's a translation.
F: Do you sell PS2 here?

M: Yes.

F: How much?

M: 69 bucks.

F: So I just bring it home then I can play?

M: We guarantee that you can play original discs.

F: That means it cannot play?

M: If it's original discs, it can play, if it doesn't work you can bring it back for exchange.

F: What about pirated ones?

M: We only guarantee that original discs can be played.

F: That means I cannot play pirated games?

M: Ma'am, you still don't understand what I mean.

Saturday, July 25, 2009

Young programmers win big

Young programmers win big
Straints Times, July 20, 2009

TALK about starting young: Celine Chan, four, took on competitors far older in a national computer programming contest held here recently.

Celine and her sister, Charlene, eight, proved more than a match for the older competitors, trumping most of them handily in the contest, organised by the Information Technology Standards Committee which is supported by the Infocomm Development Authority (IDA).

Called XtremeApps, the competition required those taking part to program computer applications from scratch.

Armed with just the basics in the Squeak programming language, as well as encouragement - but no help - from mum and dad, the Chan sisters came up with an application called Health Fairies.

Two things interest me about this story. First, it is the age of the girls. I think it's quite hard to even understand what computer programming is about at the age of eight, let alone four. I didn't know what programming was when I was eight. Hmm..I don't think I've even played with a computer when I was eight. Anyway, even though tools are greatly simplifying programming, basic programming stuff like looping, conditionals, function calling, differences between classes and objects,etc can still easily overwhelm a young kid's mind. Then you also need to consider things like how the users interact with the program and the animation. You need a certain degree of logic and training to do programming. So I'm truly impressed that they can not only complete the project, but also beat the older competitors.

Second, it's interesting that they used Squeak to implement their project. Squeak is an implementation of the Smalltalk programming language. Most programmers I've talked to have never heard of Smalltalk, but I did manage to use the VisualWorks implementation  for about 3 years for work. Generally, you hear about the SAP, J2EE, .Net stuff powering the enterprise systems, so it is mildly surprising that Smalltalk used to be powering one of the biggest pay systems here. All those policies, payment stuff, bonuses, income tax, CPF computation in beautiful Smalltalk code. Funny how things appear though rose-tinted glasses. Anyway, we have difficulty recruiting people because most people consider Smalltalk to be an antiquated language. There really isn't a market for Smalltalk so no one wants to learn it, at least in Singapore. I'm a bit language agnostic (Ok, actually I prefer Java) so I didn't really think it mattered that much.

Sunday, July 5, 2009

Manhã de Carnaval

The best interpretation of the classic on Youtube by Ulli Boegershausen

Saturday, June 20, 2009

Javascript performance tuning

Recently, I was working on a customer complaint that our application was slow when churning out reports. The worst case occurs when the user selects to generate a report for the time-span of 18 months, and the application will take about 3 minutes plus to generate the reports. Not being very familiar with Javascript and DOM, I googled and found the following resources which were extremely helpful.

Nicholas C. Zakas


Speed up your JavaScript, Part 1
Speed up your JavaScript, Part 2
Speed up your JavaScript, Part 3
Speed up your JavaScript, Part 4

Yahoo! Developer Network
Exceptional Performance

Dev Opera
Efficient JavaScript

IE Blog
IE + JavaScript Performance Recommendations - Part 1
IE+JavaScript Performance Recommendations Part 2: JavaScript Code Inefficiencies
IE+JScript Performance Recommendations Part 3: JavaScript Code Inefficiencies

In our app, I found that main bottleneck was that that there was simply too much DOM interaction when creating the report's table. Creating the report involved  creating TD and TR DOM elements and adding them to a table, and deciding when to break the page. After the report is created, some of the TD cells will be merged based on some criteria.

To tune the app, I cloned the TBODY node of the table, added all the child nodes into this cloned node, and replaced the original node. Then, I has to clone the node again for doing the breaking the pages and merging the cells. Basically, it involved multiple calls to cloning the nodes, creating new doc fragments, and replacing the original nodes. Basically, it seems like the code is doing a lot more work than the original. However, it is more than 60% percent faster after tuning!

As a side-note, it really is hell trying to work on a JSP that mixes scriptlets and badly-written Javascript. First, visually it's so messy it's disorientating. Second, sometimes you can't do profiling until you've refactored the Javascript, which is sometimes hopelessly entangled with the JSP scriptlets.  And some people always wonder why I'm rewriting so much code :/

Friday, March 13, 2009

Quick trip to IT Show 2009

It's the first day of IT Show 2009, and there was a huge turnout of eager shoppers looking for good deals. Being a Thursday afternoon, you'll expect the crowd to be a bit thinner. I expected to be in and out within an hour as I'm a focussed shopper, but the snaking queues almost began the moment I stepped out of City Hall MRT. After about an hour and a half I finally completed my re-contract and purchase of Nokia's XpressMusic 5800. There was a minor hiccup when a staff did not give me free earphones worth 139 bucks, but thankfully it was resolved promptly. Finally, I'm back to owning a camera-phone after more than 3 years!

There's many interesting IT products in the show, like ACRyan's Playon! DVR. I own an older version of ACRyan HD recorder, but the new version is on steroids! Expanded connectivity options (wired and wireless), video-stream playback capability and the ability to record analog and digital TV certainly makes it very attractive.

UOB credit card owners looking for a new camera can check out Harvey Norman for the Fujifilm Finepix F60FD. It's 349 (originally 499) after trade-in with ANY camera (including those using film) and you get a whole lot of freebies (mini-tripod, 8GB SD card, etc) just by swiping your card.

Overall it's a pretty nice shopping experience. With lots of stuff at discounted prices and with cute show girls manning some of the booths, even the congestion can be forgiven :)