LendKey

Monday, March 23, 2009

How to write a servlet filter

Since you can call HttpServletResponse.getWriter() only once, it is a little bit tricky to add more output in servlet filter, because it is very likely your call to getWriter to be failed.

Come examples about filter can be found at:
http://download.oracle.com/docs/cd/A97329_03/web.902/a95878/filters.htm

Monday, March 16, 2009

Tips on svnmailer

svnmailer is a great tool to help admin monitor changes made in SVN repositories.
There're zillions of nice articles/docs on how to config it. So I won't bother adding one more here.
Only a couple of tips that I hope can help myself and you trouble-shooting it:

1. To remove =3D kind of characters in email
Looks like the current version of svnmailer (1.08x) and Python 2.4.3 will generate characters like =3D to replace special character = in the notification email. This is caused by the default encoding used by svnmailer (quoted-printable). The quick fix is to set it to utf8.
To apply the quick fix, open mailer.conf file, put the following setting in [defaults] section:

mail_transfer_encoding = 8bit

2. To test svnmailer without really committing anything into the repository:
After your configured svnmailer, you probably want to test the settings, but do not want to really commit anything into the repository. A quick command, which was actually suggested by svnmailer doc, is:

sudo -u apache ./post-commit [Repo Path] [Ver No.]

e.g.:

sudo -u apache ./post-commit /var/svn/2009 55

will send notification of change 55 of repository /var/svn/2009 to the designated email address.

Cheers!

Monday, February 23, 2009

Nagios killed all web sites created by virtualmin

I have a bunch of domains running on a Linux box. They are managed by VirtualMin. Each site has its own user name, group and home folder.
For example, site www.infolexllc.com under VirtualMin has user name and groups infolex as well as home folder /home/infolex.
The document root of the site is /home/infolex/public_html.
Everything was working great until I installed Nagios, hoping it could help me monitor status of my server.
But after Nagios was installed, all my sites on this server became unaccessible. when I pointed my browser to:
http://www.infolexllc.com
I got 403 error saying there's no permission to access the site.

I remember I ran into similar issue on a client's server before. So I found log I wrote down about two years ago. Looks like Nagios somehow removed user apache from group apache. Therefore, Apache server lost access right to website's document root which was owned by apache.apache.

So I guess similar thing must happened to my server also. I checked owner of /home/infolex/public_html, it's infolex.infolex.

I check groups apache belongs to, they are:
apache, nagois, nagiocmd


So I added apache back top group infolex by:
/usr/sbin/usermod -a -G infolex apache


I did the same to all other virtual hosts on the same server.

Then restart Apache. Everything is back to work!

I'm still having problem with Nagois itself so far. Will post more if I ran into anything worth to share.

Monday, February 16, 2009

Google Gear slows down WIFI?!

Man! if you read my previous post, you already know I have been fighting WIFI slowness on my Mac for many days.

I installed a 16Mbps Comcast business broadband service about two weeks ago. Since then, I noticed my MacBook Pro's WIFI speed drops down to only 100Kbps almost all the time. It's only good for a very short period of time after I restart router, blindly changed some setting on my MacBook Pro or router.
There were many times I thought the problem got resolved, I even posted a BLOG to celebrate it :). But after a few more minutes, the problem always comes back! My hair got almost pulled out completely and my mind became crazy!

Finally from last night, I noticed ping time in my network was very unreliable:

64 bytes from 192.168.0.5: icmp_seq=1757 ttl=64 time=0.933 ms
64 bytes from 192.168.0.5: icmp_seq=1758 ttl=64 time=1095.138 ms
64 bytes from 192.168.0.5: icmp_seq=1759 ttl=64 time=102.211 ms
64 bytes from 192.168.0.5: icmp_seq=1760 ttl=64 time=1451.482 ms
64 bytes from 192.168.0.5: icmp_seq=1761 ttl=64 time=467.000 ms
64 bytes from 192.168.0.5: icmp_seq=1762 ttl=64 time=1859.467 ms
64 bytes from 192.168.0.5: icmp_seq=1763 ttl=64 time=861.624 ms
64 bytes from 192.168.0.5: icmp_seq=1764 ttl=64 time=1.828 ms


I started thinking maybe I should try close all application one at a time and see if any of them had any impact on the thing.
So I left a terminal open, with ping running, so I could see change of ping speed. At the same time, I started to close applications I run, such as Adium, Skype, Firefox... Wait! after Firefox was close, the ping speed turned back to a normal range:

64 bytes from 192.168.0.5: icmp_seq=453 ttl=64 time=2.267 ms
64 bytes from 192.168.0.5: icmp_seq=454 ttl=64 time=1.001 ms
64 bytes from 192.168.0.5: icmp_seq=455 ttl=64 time=1.004 ms
64 bytes from 192.168.0.5: icmp_seq=456 ttl=64 time=0.987 ms
64 bytes from 192.168.0.5: icmp_seq=457 ttl=64 time=1.197 ms
64 bytes from 192.168.0.5: icmp_seq=458 ttl=64 time=1.008 ms
64 bytes from 192.168.0.5: icmp_seq=459 ttl=64 time=1.245 ms


It got be Firefox!

Then another question comes back. Why did Firefox behave pretty good before? And I cannot live without it.

That's when I realized I installed GoogleGear to enable offline access to my gmail account almost the same time when I installed Comcast. Could that plugin be a problem? Easy to know. I removed this plugin. And everything is back to normal, even with Firefox running! I enabled/disabled it many times just to confirm. And looks like IT WAS GOOGLEGEAR THAT CAUSED ALL MY HAIR-LOSS!

I will report the problem to our google friend. In the mean time, in case you are losing your hair as I was. Hope this post helps.

Li

Tuesday, February 10, 2009

WIFI slowness of my Macbook Pro

My Macbook Pro (2007 edition)'s WIFI turned to be very slow recently. Speed test (http://www.speedtest.net) sometime report only 10K download while I have 15M Comcast broadband.
I struggled many days and tried different ways I could imagine, even bough a new router, problem still unresolved.

Today, I tried to check /var/log/system.log and found lots of error messages like:

Feb 9 01:10:06 li-mac-2 mDNSResponder[22]: AppendDNSNameString: Illegal empty label in name "."
Feb 9 01:10:06 li-mac-2 mDNSResponder[22]: RegisterSplitDNS: bad domain .


Then I Googled the keywords:mDNSResponder[22]: RegisterSplitDNS: bad domain . and found a hint at:
http://discussions.apple.com/message.jspa?messageID=6911574


Followed suggestion from the site, I finally managed to resolve my issue. Since the DNS error msg is gone, my MacBook Pro could do 14Mbps on wifi.

Here's summary of what I did:
1. run scutil --dns and saw something like:

DNS configuration

resolver #1
nameserver[0] : 192.168.0.1
order : 200000

resolver #2
domain : .
options : pdns
timeout : 5
order : 150000

resolver #3
domain : local
options : mdns
timeout : 2
order : 300000
...


2. Open Keychain Access
3. Click on System at left side
4. Find and delete item named DNS Key
5. Reboot
6. Problem resolved!

Friday, January 23, 2009

Thread-safe singlton instantiation

Very often that we need to get instance of a single which is initialized Lazily, meaning only when it is first be needed.

What we normally do is:



After reading a scary article about Java memory model, I realized this code does not always work in a multi-threaded environment:
http://www.ibm.com/developerworks/library/j-jtp03304/
and
http://www.ibm.com/developerworks/java/library/j-jtp02244.html
and
http://www.javaworld.com/jw-02-2001/jw-0209-double.html

The idea is complicated, but to describe it in a simple sentence, I would say:
Because modern compiler might reorder execution sequence of the commands, the code might fail under certain hardware/software environment.

So a safer solution is:


Because JVM guarantee initialization and execution order static inner classes, this solution is not only safe, but also faster than using volatile or synchronized keywords.

Thursday, January 22, 2009

Javascript compressors

I ran into a nice websites that compares JS compressors on the fly. Cool stuff. So I write down here as a reference for myself, and you, just in case:
http://compressorrater.thruhere.net/