Tuesday, November 04, 2008

Sweet golden November

Saturday, October 11, 2008

SourceForge stopped shell service and broken maven2 site deployment

According to the sourceforge notice, the access methods for project web file management have changed. The new accepted methods are: SFTP, SCP, rsync over SSH. SSH shell service is not supported anymore.

When maven 2 SSH based wagon deploy site, it zip the whole site, upload zip file and unzip it with remote SSH call, which wouldn't work after SHELL service is stopped. Which means SSH wagon is broken for all projects hosted in sourceforge.

Issue has been raised but not resolved. Until this issue is resolved, all site deployment to sourceforge hosted project remains broken.

Tuesday, July 29, 2008

Replace jconsole with command line based jmxterm

JMXTERM is a command line based interactive JMX client software. It opens a command line console and user can open connection to an MBean server, then operation against it with interactive commands. The user experience of JMXTERM is like a combination of jconsole and ftp. With JMXTERM, JMX operation doesn't have to be done in graphical environment anymore.

JMXTERM project has recently release the second version 0.2, which is much more reliable and better documented than the previous version 0.1. Several serious bugs including white space in MBean name and user/password based authentication were resolved in version 0.2. Besides, version 0.2 adds the feature of listing local running Java process even if they aren't launched with jmxremote argument.

Links:

Monday, July 21, 2008

Dark Knight, the #1 movie in IMDB


This movie tells that,
  1. A comic super hero move, a box office blockbuster movie can be appreciated in the same way God Father or The Shawshank Redemption is
  2. It doesn't take comedy to be a profitable super hero movie
  3. To be a good movie, it doesn't matter how many predecessors there are.
Dark Knight is unique and unconventional. The #1 position in IMDB may turns out to be too overwhelming in the future, but it's definitely easily the best movie of year, best superhero movie and a movie should be appreciated by Oscar academy.

Click to see bigger picture

Thursday, July 17, 2008

Reflection is expensive? Illusion!

Reflection invocation is a little bit more expensive comparing to the direct call, but it wasn't very slow and it's not slow at all now in JDK 6. It is looking up by name that takes long time.

Operation2000/11 (probably jdk 1.3.1)2003/1 (probably jdk 1.3.1)2004/10 (jdk1.4.2_03)2007/2 (jdk1.6.0_b105)
100,000 regular calls2664ms281ms203ms78ms
100,000 reflection calls without lookup4216ms297ms250ms78ms
100,000 reflection calls with lookup45505ms938ms562ms203ms
1,000,000 regular calls27840ms2578ms1828ms594ms
1,000,000 reflection calls without lookup43863ms2782ms2485ms641ms
1,000,000 reflection calls with lookup47097ms5453ms9343ms1984ms
10,000,000 regular calls-25906ms17766ms5063ms
10,000,000 reflection calls without lookup-27891ms24813ms6141ms
10,000,000 reflection calls with lookup-54843ms93611ms20093ms


Link: What are the performance costs involved in Java reflection? E.g., looking up a method by name and then invoking it.

Neutual density filter and long exposure

Pictures in this album were all taken from Pier66 in Seattle, between dawn and pitch black night. Most of them were under long exposure (5~60 seconds). Some were taken with neutral density filter. For examples:

  • P7137679 is taken in early dawn with 5s exposure, with .9 neutral density filter plus a .6 graduated neutral density filter.
  • P7137705 is taken in late dawn with 40s exposure, with .6 neutral density filter and a polarizing filter. It was already dark at that time, lights in building is on.
  • P7137712 and P7137721 are both 50s exposure with only a polarizing filter, they were taken in dark.


Friday, April 04, 2008

4-states state machine for CSV parsing

Parsing CSV file is easy, it's nothing but splitting string with comma delimiter, which can be easily done in Java... The first thing came to my mind when I'm about to parse CSV file in Java is just like that. Now, reality is that following examples are all possible valid lines in a CSV file
  • 1,Bender
  • 2,"Bender"
  • 3,"Bender, Bending"
  • 4,"Ben""d""er"
  • 5, Ben"der
  • 6, Ben""der
Line 7 might be arguable but anyway, two basic rules are
  • If there's comma in field, use double quot to wrap field, otherwise double quot wrapper isn't required.
  • Inside double quot, double quot is used to escape double quot.
Suddenly the problem is complicated to something more than string splitting, however it can be simplified into a finite state machine with 4 states.

States:
  • 1. Ready for new field (initial state)
  • 2. Field without double quot
  • 3. Field with double quot
  • 4. Escaping or end of double quot
Transitions

*Direction*|*Condition*|*Action*
1->2 |not(" or ,)|Append character to buffer
1->3 |" |Nothing
2->2 |not , |append character to field
1|2|4->1 |, |Output complete field and create buffer for next field
3->3 |not " |Append character to buffer
3->4 |" |Nothing

Wednesday, January 23, 2008

Guess a number (Find the floor in building that breaks egg)

Question

I have a integer number M in my mind, a number between 1 and N where N is a big number. Chances for M to be any integer between 1 and N are the same. A friend tries to guess this number by asking me to compare M with another number, and I'll answer "your number is bigger", "smaller" or "correct". Another constraint is, his number can be bigger than or equal to M for up to 2 times. What is the strategy to figure out M with least questions?

A variation of this question is, in a N stories building, with 2 eggs, find the lowest floor from where egg breaks when it drops to ground.

Example answers

  • With only one egg, I can try the 1st floor, the 2nd, 3rd ... until the egg break. This strategy works but it's the worst.
  • Improved answer is, try 2, 4, 6, 8...until one egg breaks. Then use the other egg figure out answer.
  • Or, try 10, 20, 30, 40.... If egg breaks on 60, try 51, 52, 53... This is slightly better than previous answer, but might not be the best.
Analysis

Follow this idea, assume the first egg is tried every X stories, then the total number of attempts is:

f(X) = N/2X + X/2.

When f(x) is minimized, df(x)/dx = 0. Which means: 1 - N/(X^2) = 0, therefore X=N^(1/2).

Enhance difficulty

What if there are 3 eggs? Assume the 1st egg is tried for every y stories, seconds is tried every x stories, and y=g(x), then the total number of attempts is:

f(x) = (N/g(x) + g(x)/x + x)/2.

When f(x) is minimized, its differential expression should be 0, which means:

1 + g'(x)/x - (g(x))^2/(x^2) - N * g'(x) / (g(x) ^ 2) = 0

When g(x) = x ^ 2 and N = x ^ 3, the equation stands. Therefore the answer is N^(2/3) stories for the first egg, N^(1/3) stories for the second egg and every story for the third one.

Next question

On top of what we found, what if we also what the worse case to be as good as possible? In previous analysis, the worse cases are 2 * N^(1/2) for two eggs and 3 * N^(1/3) for 3 eggs. The average number of guess can't be improved any more, since already made the differential result 0. But with some small adjustment, the worst case can be improved dramatically.