Tuesday, May 13, 2008

Ali rustam had supper at Subaidah Cafe

Just now, I had my supper with my friend at one cafe called Subaidah. We spent there for around 2 hours more. When we were about to leave, we saw chief minister of the Melaka state, Ali Rustam came together with one of his friend. I think he just finished OT? Haha.

Anyway, as he showed up, a group of customers from the table next to us quickly dashed forward to shake hand with him. Wow! Do they really need to do that?

Monday, May 12, 2008

Apache POI

I have one web application, everytime i deploy i will need to load initial reference data again and again.

The amount of these data is huge!

I used to hardcode all these data in my Java file. I organised them properly using data structure such as String array and so on. In my Java file i have a few functions that actually perform the data loading job.

The problem is, It's time consuming and error prone to hardcode each and every data in the Java file.

Therefore, today i decided to put all the data in Spreadsheet program. It is easier to maintain data at Spreadsheet rather than in the Java file itself.

Then i used Apache POI library to read me those data from the Spreadsheet (Microsoft Excel).

Just one time try and it worked fine!

So simple! I was really delighted!

Wednesday, May 7, 2008

One day effort for unknown vm crach of Eclipse during Subclipse installation

WTF,

It took me one day to get the problem fixed. The solution is so simple!

I setup Eclipse at my new laptop. As usual, i also installed the Subclipse plugin. By right it should work properly. Well, when i tried to create a new remote source repository using Subclipse Perspective in Eclipse, Eclipse just quitted suddenly followed by a prompt saying that it is some kind of memory crash.

Also, there is an error log file generated each time Eclipse exited. However the message is so so not comprehensive.

Here's the message:


## An unexpected error has been detected by Java Runtime Environment:
## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x3b397bfc,
pid=3824, id=5160
## Java VM: Java HotSpot(TM) Client VM (10.0-b22 mixed mode
windows-x86)
# Problematic frame:# C [libapr-1.dll+0x7bfc]
## If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.


With this only clue, i kept Googling for the whole day and still did not get the problem fixed! How frustated was i!

Besides trying out the solutions found online, I also tried to tackle the problem by doing a few times of trial and error, which is actually install-uninstall this kind of stuff.

We really got to be patient enough when dealing with this kind of problem.

Yet, the problems stayed. All the tries did not bring positive outcome.

Office hour ended. Today i did nothing but just configuring stupid Subversion on Eclipse. Boss, please don't get mad.

I started over the puzzle solving game again at home after coming back from dinner.

With calm mind, and of course enough of rest, i found the answer within an hour!

I came across this article online:

http://subclipse.tigris.org/faq.html#win32-crash

Here's the excerpt:


As soon as I do something with Subclipse on Windows, Eclipse just
crashes. Why does this happen?


This is a fairly recent problem that is caused by a DLL incompatibility. Subversion uses a library called APR or the Apache Portable Runtime. This library has a component called APR-ICONV which is used for translating characters in path and file names to/from UTF8 and the local character set. The release of Apache 2.2 brought with it new releases of APR and APR-ICONV and these are not binary compatible with previous releases.


Subclipse ships with the Apache 2.0 version of these libraries. This crash
occurs if you install an application that installs the Apache 2.2 version of
these libraries AND ALSO sets the APR_ICONV_PATH environment variable to a path that contains the Apache 2.2 version of the APR-ICONV .so objects.


The fix is actually simple. Change the name of the environment variable to APR_ICONV1_PATH. The Apache 2.2 library will look for this environment variable name first, and only fallback to the older name if it is not found. You can safely have an APR_ICONV_PATH environment variable pointing to the Apache 2.0 version of these libraries and the APR_ICONV1_PATH environment variable pointing to the Apache 2.2 version. Subversion 1.5 has resolved this problem by discontinuing the use of APR-ICONV. Instead, Subversion will use translation routines that are provided by the Windows operating system.


So, i uninstalled the Subversion Server built against Apache 2.2 and replaced it with the one built against Apache 2.0.

Eclipse looks fine now.

Finally!

Thursday, April 17, 2008

2008澳门游记

感谢公司给予的机会,让我体验了在澳门旅游的乐趣。

虽然旅程只有短短数天,不足以更深入的体会澳门,但由于乃自由活动,是以也不虚此行。

由于地点靠近,有些同事选择第二天往香港去了。他们一大早就赶往渡轮码头以乘搭第一班船,我觉得旅行需让身心放松才能达到目的,所以不随他们了。

之后与另一位同事穿梭于澳门的大街小巷间,体验大众的生活形态,满意非常。那种感觉是非常随意、非常悠闲的。

尤其是他们的大众食物让我感到兴趣万分,虽然多数看看就知道都不合我胃口,但很高兴能打开眼界。

Thursday, April 3, 2008

Hibernate Tips - delete existing item from children

Scenario as below:

I am at a screen now from a web application.

There is a swap-select box on the screen. I select 5 items and click Save button.

Next, the system creates 1 parent object and saves 5 items (selected from screen's swap-select box) as children(a Set) into their parent.

I leave the screen.

Upon next visit to the same screen again, i am trying to remove 2 among the 5 selected items. After that i click Save button.

How should i handle this?

What i need to do is:

1) Get the original Set from the parent object. (Let's name it 'children')

2) At the same time, create new Set(let's name it 'removedChildren'), add those objects that are meant to be removed. (In this case this new Set will have 2 objects)

3) Using removeAll method from Set, put the 'removedChildren' Set in it (children.removeAll(removedChildren))

4) Set the 'children' Set back to the parent. (parent.setChildren(children))

5) Save the parent. (saveOrUpdate(parent))

How to get the last 2 decimal digits using JAVA?

Example:

To get 0.99
from
double abcd =123456789012345.99;

Solution:
double a = 12345678901234.99*100;
String f = Long.toString(((long) a)%100);

Wednesday, March 5, 2008

Very, very much blood shed in KLSE

Over the past few days, KLSE index dropped drastically. A few billions of RM just gone like that. It's like a dagger ripping my heart! Nobody like us (small investors) have ever expected this. Especially right now the general election is approaching!

The profit earned from both stock counters and funds last year soon turned into ashes.

So far, over the 3 stocks i am holding, 2 of them achieve a growth of 46.06% & 46.45% respectively. I have been holding these 2 stocks for 3 years already. It means on average, they have brought >14% profit each year. Well, the other one, which is the only one, causes me losses anyway! It's approaching one year and so far it causes loss at -17.37% ! Well, everything stated here is not the physical one as i have not yet sold the counters off!