Wednesday, November 28, 2012

Create new user account in SVN

Just a reminder to myself. In order to create a new user in SVN, I'm require to use following command like this:

htpasswd -m < path-to-svn-auth-file > stupid

The above code will create a new user, stupid, after this a new password for this user account will be prompt. The stupid user account can be spot easily by opening the file because the user name is not encrypt but the password is encrypted.

I been doing this for few thousand time since early of this year, but I still couldn't remember such a simple command. When the new server has arrive, I need to configure this for the whole department. I need to be prepare to myself.

Good luck and sigh~

Monday, November 26, 2012

Playing cheat code in Jasper iReport

where 1=1 $P!{Parameter_value}, this code is so beautiful.

I learned a trick on how could I handle false condition on dynamic SQL generation in Jasper iReport. In a conditional SQL select statement, result set is return only if the condition is true, otherwise I'll see nothing. Usually this is what I did everyday.

Now I have a weird requirement, if the condition is not match (meaning false), I still want to see the result set without the condition. That can be done, but my way, no way, so much ugly. Until I meet where 1=1 $P!{Parameter_value}, this guy did a very good job in keeping the code clean. I like this guy, a very smart guy.

I suppose to put the condition validation of a select statement in the where clause, but I take it out instead. Giving an order to Jasper to hold this value for me, say Parameter_value. Now I append 1=1 at the end of the where clause, become this where 1=1. The first time I see this code I though it was a joke because this query will always return a valid result set.

Magic happened when I append $P!{Parameter_value} after where 1=1. Jasper will always compile the Parameter then only compile the whole query statement. If the condition given in $P!{Parameter_value} is valid, then the result set with conditional validation is returned. If the condition given in $P!{Parameter_value} is invalid, then query will become where 1=1, with an empty string at the end, and since 1 always equals to 1, thus it will just return anything without the conditional validation.

This code is like playing cheat, I love it, and like it.

Friday, November 23, 2012

Dirty work to speed up WAS Liberty Profile

When Websphere Application Server Liberty Profile, aka WAS Liberty Profile is first launch, I was really get attracted by its light weight Servlet container. After 3 months of using it in my new project, I found following point.
  1. The start up time is fast because of the JSP compiled classes, JAVA compiled classes, and other resources is not loaded inside the container. Since it is nothing inside the container that's why it is fast.
  2. The run-time is very slow because it needs time to load all the resources and compiled classes before the web app is render on browser. If looking at how Tomcat is work, it will load all the resources during the server start up. 
  3. During the clean process, WAS Liberty Profile took less than 0.0001 sec whereas Tomcat took some time (more than 1 sec) to clean. This could be means that WAS Liberty Profile don't store old cache after server has been stop whereas Tomcat still storing it.
  4. Another thing I have spot on WAS Liberty Profile is that once the web app is loaded at first time, the subsequent load time will back to normal. I think this could be means that once it is load, a copy is cached in client site, but not server side.
There are too many assumption made by myself, don't take it serious, all of them are nonsense. Back to the question, there are actually people out there is making some good work to speed up the server. But it is not document in WAS Liberty Profile documentation, do it at my own risk.

Append this code at the end of Servlet.xml file, and then restart the server.

Wednesday, November 21, 2012

To amend the commit message on SVN under Windows

Another concern on using SVN as source version control is when programmer did something wrong with the commit message. In order to allow amendment on the commit message, I am required to have pre-revprop-change hook script ready.

Doing it in Windows always have extra steps. Save a copy of this pre-revprop-change template file locate under the /hooks directory into .bat extension, replace the code with the one I got from this article. What a nice and clean code.

@ECHO OFF
:: Set all parameters. Even though most are not used, in case you want to add
:: changes that allow, for example, editing of the author or addition of log messages.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5

:: Only allow the log message to be changed, but not author, etc.
if /I not "%propertyName%" == "svn:log" goto ERROR_PROPNAME

:: Only allow modification of a log message, not addition or deletion.
if /I not "%action%" == "M" goto ERROR_ACTION

:: Make sure that the new svn:log message is not empty.
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
set bIsEmpty=false
)
if "%bIsEmpty%" == "true" goto ERROR_EMPTY

goto :eof

:ERROR_EMPTY
echo Empty svn:log messages are not allowed. >&2
goto ERROR_EXIT

:ERROR_PROPNAME
echo Only changes to svn:log messages are allowed. >&2
goto ERROR_EXIT

:ERROR_ACTION
echo Only modifications to svn:log revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1

Done with first step, now come to second step, is to edit the commit message or adding a commit message. If the commit message is already there, use this command to remote access the SVN server to modify the commit message.
svn propedit --revprop -r 25 svn:log \
http://128.230.9.166/svn/trunk/TheJava.java "Update a commit message." \
--editor-cmd notepad.exe
This is to tell SVN that I'm going to update the commit message on revision 25 where the particular file is located at http://128.230.9.166/svn/trunk/ directory using notepad as editor.

If --editor-cmd is not provided, this will assume that the SVN_EDITOR environment variable has been set, otherwise an error will be prompt "None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set...".

If the commit message isn't there, then use this command to add a new commit message.
svn propset -r 25 --revprop svn:log \
"new log message" http://128.230.9.166/svn/trunk/TheJava.java

This is to tell SVN that I'm going to add a new commit message on revision 25 where the particular file is located at http://128.230.9.166/svn/trunk/ directory

Tuesday, November 20, 2012

Setup SVN pre-commit hook script under Windows

It has been so long for me to have this feature to be ready before a project start since long long time ago. I'm talking about SVN under Windows environment. I would like to have a feature when the code is submit, the server will first verify whether the comment is empty. If it is, block them from commit the code.

There has been a time where I feel so frustrated on my team member who never put any comment on their code end up giving me a hard time to trace back their code. And feel so stupid that digging down each revision changes to open up each file to verify and review their code. But I do not have such luxury time for me to do this setup. Until this week, the UAT is sign-off, I take up the opportunity to continue my work.

There is a template code with a filename, pre-commit.tmpl is ready for use locate inside the directory /hooks, but never got a chance to execute it because the code is for *NIX and not for Windows. I am required modify the code provided from this article in order to get it work under Windows.


@echo off
:: Stops commits that don't include a log message of at least 6 characters.      
@echo off

setlocal

rem Subversion sends through the repository path and transaction id
set REPOS=%1
set TXN=%2        

svnlook log %REPOS% -t %TXN% | findstr ...... > nul
if %errorlevel% gtr 0 (goto err) else exit 0

:err
echo --------------------------------------------------------------------------- 1>&2
echo Your commit has been blocked because it didn't include a log message. 1>&2
echo Do the commit again, this time with a log message that describes your changes. 1>&2
echo --------------------------------------------------------------------------- 1>&2
exit 1

There are few thing I need to take note of:
  1. The pre-commit file must be saved as bat or exe file extension.
  2. The pre-commit file must locate under the /hooks directory.
  3. Remember to restart the svn server service when done these changes.

Sunday, November 18, 2012

Successfully install Syntax Highlighter into my Blogger

Cheers. Finally I have successfully configure Syntax Highlighter into my blogger. Thanks to Scott Meyers's post on how this could be done and I really appreciate his effort on posting it up.

Before this, I did try to install Syntax Highlighter from Google code but failed to configure it. Then I tried snipt.net, but this one is a bit slow and cumbersome because I need to edit it somewhere then post it back here. What if their server gone down, or their services has gone? That's why I so keen to Syntax Highlighter because of its functions are self-contained. Meaning I no more require to edit some where and post a link here.

With this post from One Q, One A blog, things is much more easier. It really goes into a level where I don't need my brain to do the configuration. And the most annoying one is transforming angle bracket '<' and '>', I use this tool called Encode/Decode HTML Entities to handle this for me.

Below is my experiment usage of Syntax Highlighter on XHTML code:
  1. I put my code right under the compose mode inside the Blogger. (Before this I have already encode those HTML entities.)
  2. Define a xhtml brush in HTML mode in the beginning of the code, like this: <pre class="brush:xhtml;">
  3. Put this </pre> at the end of the code.
Sample Output
<h:form id="theForm">
  <h:commandLink id="tri_HiddenEvent" value="Trigger Hidden Event" onclick="triggerHiddenEvent(); return false;"/>
      
  <p style="display:none">
    <h:commandLink id="hiddenCommand" styleClass="button" action="#{helloBean.doHiddenCommand}">
      <f:ajax execute="@form"/>
    </h:commandLink>
  </p>
      
  <ui:remove>f:ajax doesn't support inputHidden</ui:remove>
<h:form>
There are a lot more brushes available for all kind of code in this manual. Enjoy blogging.

Emulating IE9 through JSF PhaseListener

I need to emulate my JSF page to behave like IE9 although I'm using IE7. I know that in order to achieve this I must have the following meta tag to be include in my client code, like this:

<meta http-equiv="X-UA-Compatible" content="IE=9">

There is a source mention this should be done using JSF PhaseListener. By adopting that solution, I have this code:

I have tested the above code and its working fine. The code will actually emulate all pages in IE9 in the particular webapp and I have no intention to limit its implementation to a particular page. Anyhow this could be done using this solution.

Oh yah... Before I forgot, I need to register my custom made phase listener class in faces-config.xml file in this way, otherwise it wouldn't work.

JSF doesn't recognize '&' symbol in JavaScript

I don't know there is something I should take note of when using JavaScript in JSF. I found this is interesting to share out when using && operator in JavaScript like this:


This will create an error in JSF because JSF unable to interpret ampersand symbol. To fix this problem, I must not use ampersand symbol. And replace it with this & amp;& amp; in order to make JSF happier.

Saturday, November 17, 2012

My CPU is ready for virtualization

I own an i5 CPU. Just did a quick check on my CPU whether it support for virtualization. Sent out this command egrep '^flags.*(vmx|svm)' /proc/cpuinfo to my computer and I got this bunch of nonsense:

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
This means that my CPU is ready for virtualization, otherwise it wouldn't print anything.

I can't sudo yum-complete-transaction in Fedora

I use to be a fans of Ubuntu because of its convenient and ease of use. To execute a command with root privileged in a rush, just do the following:

sudo yum-complete-transaction

But I don't know how to do this in Fedora. Thus I need to separate the command by execute su first, then only yum-complete-transaction. I did tried on other command with sudo but only this one failed.

Just curious why yum-complete-transaction can't work with sudo?

Thursday, November 15, 2012

Fedora 16 has an unfinished transaction?

I was doing an update in Fedora 16, but the process isn't complete and throw me a weird message.
There are unfinished transactions remaining. Please run yum-complete-transaction as root.
Not sure what is happening, just follow the given instruction and there is a bunch of nonsense as shown below is thrown to me. After this command execution, everything went normal. What a fun?!!

Tuesday, November 13, 2012

select 1 row from a table in DB

In Oracle, I do this:

select * from table where rownum = 1;

In DB2, I do this:

select * from table fetch first 1 row only;

In Informix, I do this:

select first 1 * from table;

Conclusion: To master SQL, don't think it is easy.

Saturday, November 10, 2012

JavaScript is platform dependant

I am feeling so bad on this issue, but I have no choice. When requirement come into my hand, I must get it done. Majority of my development was done on IE, and the initial requirement was targeted on IE as well. When requirement change request to target on other browser like Firefox, Safari, Google Chrome, and Opera, I am required to get the job done as well.

Initially I though everything should be fine, but eventually it is not where the unload event doesn't support in Firefox. Some suggest me that I should use onbeforeunload in Firefox. I had tried it and it's really work. Below is the code snippet on how this could be done.

Here I made the 2nd mistake, once I put in the code snippet, and I forgot to remove this code unload="onUnload()" from body tag. This end up the page sending the request twice to the server during unload event. Thus it is advisable to take it out if the code snippet exists.

But one bad news is Opera doesn't support onunload and onbeforeunload at all.

Dirty way to handle browser close action in JSF

There is a requirement where I need to do some update in the backing bean before exit the browser. Unfortunately JSF doesn't have such event handling for me. Googling around doesn't seems much help, thus I choose to use the dirty way by simulating a click event to trigger the function called in backing bean when unload event is invoke.

Here is the code:


  1. Put a commandLink in hidden form and execute the click simulation in JavaScript when page is unload.
  2. When the unload event is invoked, click event is triggered, and doCloseProcess will get trigger.
  3. Update the necessary stuff there then done.

Handling close event in Firefox and Safari.

My last week was a nightmare. The problem on handling close event in Firefox and Safari is the most tricky code I had ever encounter in my life.

I was trying simulate a click event in JavaScript by doing this:

Interestingly this is working find in IE except Firefox and Safari. Asking around in StackOverflow and I got this so called 'special handling' on Firefox and Safari. This piece of code is required in order to get the click event work and it is also support IE version greater than 8.

The right way of passing parameter in JSF

One day I was trying to pass a parameter from XHTML into the Backing Bean by doing this:


Asking around whether this is right or wrong and I was told that this isn't the right way. It suppose to be like this: