Monday, September 03, 2007

Rattlesnake Lake

Enjoying the beauty of Rattlesnake Lake doesn't require strenuous hiking at all, the lake is right beside the parking lot. With extra 4-mile easy hiking, people can also find stunning mountain view from the summit of Rattlesnake Ridge.

Saturday, September 01, 2007

Cenqua Acquired by Atlassian

Received a mail from cenqua recently:
1 August, 2007: Today we’re announcing the acquisition of Cenqua! There is a lot of synergy and similarities between Cenqua and Atlassian, from our business models to the philosophy behind our development, so the merging of the two companies makes a lot of sense. While plugins already exist to connect JIRA and FishEye and Bamboo and Clover, we will be building tighter integrations between all the products.

...
Details

Tuesday, August 28, 2007

23 prisoners problem, brutal solution and analysis

Problem abstract

23 prisoners are going to be sent to isolated 23 cells and in each day, the guard will randomly pick one of them and have him change the status(either on or off) of one of two switches(switch A and B). The guard promises that if one day the prisoner he picks looks at the two switch, confidently tells that all 23 prisoners have been picked in past and it's truth, then all prisoners are set free. If the prisoner is wrong, game is over and they stay in prison for ever. Before the game begins, 23 prisoners have one chance to sit together and figure out a strategy to go free. (Detailed version)


Quick analysis

  1. Since each prison HAS TO change one of the switch, his decision is not "which combination to change to", but "which switch to turn". Therefore his decision is only one out of two: changing switch A vs. changing switch B.
  2. The information that two switches can contribute is 2 bit a time. At any given moment, for a prisoner to tell if everyone has been picked(one special case out of 2^22 cases), the minimal input is a 22 bit binary sequence. Therefore the prisoner has to have be picked for 11 time at least before he can tell. And this is for the very ideal case without any noise whatsoever, in theory.

The brutal force solution

The first solution came to my mind was brutal force.

1 prisoner is elected to be the Mr. Counter and other 22 report themselves. Take switch A as counting switch. Every time Mr. Counter is picked, if he sees A is on(someone has reported), he turns off A(reset counting switch) and increase the number in his mind. If A is off he changes B and doesn't do anything. For the other 22 people, if A is off(nobody has reported yet) and he hasn't reported before, he turns A on to report himself. Otherwise changes B.

In this solution, the counter has to have been picked for at least 22 times before he can draw the conclusion. The efficiency sounds really low.

Analyze the efficiency

Nothing happens for sure. From now on, the estimate time is always "the time it takes before happening 80% for sure).
At any given moment, if it takes N days before Mr. Counter is picked,
1.0 - (22/23)^N = 0.8
N = log5 / (log23 - log22) = 36
This means Mr. Counter is 80% likely going to be picked in next 36 days at any given moment. And of course, the average life cycle is 23 days, for which I'll talk about in the end.

At the very beginning of the game, before Mr. Counter is called, chance is 100% for one of the other 22 to report himself. After Mr. Counter reset counting switch for the first time, there's 1 - (1/22)^36 chance for the second prisoner to report. After counter switch is reset for N times, chance for next person to report is 1 - (N/22)^36. Even for the last person, the chance for him to miss is about 18%.

So the conclusion for brutal force approach is, it takes a little more time for Mr. Counter to be picked for 22 times before Mr. Counter confidently know all other 22 prisoners have been picked before. How much more than that? It is 80% likely

((1/22)^36 + (2/22)^36 + (3/22)^36 + ... (21/22)^36) * 36 (days)
~= ((21/22)^36 + (20/22)^36) * 36(days) ~= 8 (days)
X = 36(days) * 22 + 8 = 800 (days) totally
It 80% likely takes 800 days for Mr. Counter to figure out. By average, it takes 23 days rather than 36 days for a person to be picked. If I replace all 36(days) with 23(days) and start over again, the average result is actually 514 days. The most magical solution based on prior analysis is 11*36 = 396 (days) for 80% and 11*23 = 253 (days) as average. Considering the noise, the brutal force solution isn't bad at all.

Monday, May 07, 2007

Upgrade to Ubuntu 7.04, Feisty Fawn

Ubuntu 7.04, "Feisty Fawn" is the latest stable release of Ubutun Linux distro. Although the Ubuntu community doesn't support direct upgrade from 6.06 (Breezy) to 7.04, re-installation isn't that scary if your personal data is stored in separated partition. Only a few fundamental mount points like root, /usr, /var and /boot, need to be formatted during re-installation.

Screen shot

Monday, April 30, 2007

Weekend hiking in Lake Serene

Lake Serene hike, the 7 miles round trip with 2000 feet elevation, probably takes a whole afternoon. The trail is strenuous, dangerous and out of maintenance for years. However, the stunning view from the summit of Mt. Index makes every drop of sweat count.

Direction: Take highway 2 from Monroe heading east, exit at milepost 35 for Mt. Index Rd. Map

Lookout from summit of Mt. Index Creek Lake Scenery

Album (74 photos)

Thursday, April 26, 2007

Wednesday, April 25, 2007

Maven Book, Maven: The Definitive Guide (1.0 Alpha 1)

It's also downloadable from http://www.sonatype.com/MavenTheDefinitiveGuide.zip

Why a Book?

You may ask "Why a Maven book? There are plenty of documents online, right?". The problem of diving into any new software project is the problem of where to begin. Yes, there is a growing wealth of information pertaining to the Maven project - but it is scattered and piecemeal. They make great reference materials (we even used some docs for this book) - but many developers, myself included, desire a narrative - a jolly stroll through the growing Maven metropolis - a place to see the grand sites without being overwhelmed - where does the yellow-brick road begin? Here.

Read more ...

Customize IdGenerator in JPA, gap between Hibernate and JPA annotations

JPA annotation is like a subset of Hibernate annotation, this means people will find something available in Hibernate missing in JPA. One of the important missing features in JPA is customized ID generator. JPA doesn't provide an approach for developer to plug in their own IdGenerator. For example, if you want the primary key of a table to be BigInteger coming from sequence, JPA will be out of solution.

Assume you don't mind the mixture of Hibernate and JPA Annotation and your JPA provider is Hibernate, which is mostly the case, a solution before JPA starts introducing new Annotation is, to replace JPA @SequenceGenerator with Hibernate @GenericGenerator. Now, let the code talk.
/**
* Ordinary JPA sequence.
* If the Long is changed into BigInteger,
* there will be runtime error complaining about the type of primary key
*/
@Id
@Column(name = "id", precision = 12)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XyzIdGenerator")
@SequenceGenerator(name = "XyzIdGenerator", sequenceName = "xyz_id_sequence")
public Long getId() {
   return id;
}

In order to generate BigInteger primary key, a custom BigIntegerSequenceGenerator is created.
package com.mycompany.myapp.id;

import org.hibernate.id.SequenceGenerator;
...

public class BigIntegerSequenceGenerator
    extends SequenceGenerator
{
    @Override
    public Serializable generate(SessionImplementor session, Object obj)
    {
        ...
    }
}
Replace the JPA @SequenceGenerator with Hibernate @GenericGenerator, where the strategy can be the class name of IdGenerator.

@Id
@Column(name="id", precision = 32)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XyzIdGenerator")
//@SequenceGenerator(name = "XyzIdGenerator", sequenceName = "xyz_id_sequence")
@GenericGenerator(name = "XyzIdGenerator",
        strategy = "com.mycompany.myapp.id.BigIntegerSequenceGenerator",
        parameters = {
            @Parameter(name = "sequence", value = "xyz_id_sequence")
        })
public BigInteger getId()
{
   return id;
}
Customized IdGenerator is one of the features in the gap between JPA and Hibernate persistence Annotations. Similar missing features in JPA include other things like @Generated annotation in Hibernate for non-primarykey generated fields.

Sunday, April 08, 2007

Mount Little Si, North Bend



Five miles to the summit, with 1200 feet elevation. The two hour hiking in Mount Little Si became perfect activity for Cloudy Saturday. Most part of the trail hides deeply inside the dark silent forest. This is not the trail where people can walk, chat, enjoy and relax. This is a hard, secret and spooky kind which make people sweat.

Friday, February 09, 2007

Velocity based static website generation under Maven2

For several times I went into the situation where I need to seriously decorate a Maven2 generated website, and a more powerful and scriptable way of writing page content than APT and XDOC is required. CSS can do some decoration work and a customized master velocity layout for maven-site-plugin gives me full control of the template. But still, APT and XDOC are limited as a script language to write content. Velocity content may be ideal.

The idea is rendering Velocity template in a way similar to VelocityLayoutServlet and Apache Turbine, which is merging context with velocity template for content body, then put the body into another layout Velocity template. This work can be done within a maven2 goal easily.

In existing arapaho-maven-plugin project, I created flatsite mojo to do this Velocity based static website generation. It's basically a one class deal so I didn't make it a standalone maven2 plugin. It's not a maven2 report, it's a simplified version of maven-site-plugin replacement.

After flatsite mojo is created, I migrated two existing website subprojects to website project and made them generated by arapaho-maven-plugin:flatsite. These two subprojects are example sites of flatsite.

Friday, February 02, 2007

"Couselist" demo site backs to business

"courselist" ( http://www.cyclopsgroup.org/projects/courselist ) is an academic small project done by several students in University of Texas at Dallas, back in 2004. It was built on top of waterview and tornado project hosted in cyclopsgroup.org and using commons-jelly as UI rendering tool, hibernate as persistence layer and plexus/avalon as IOC container.

The project hasn't be touched in the last two years. I recently found it out and turn it on at http://demo.cyclopsgroup.org/courselist during the domain change. Many thanks to Chris Menken, Javis Cline, John Christin and Josh Allen.

Officially deprecate cyclopsgroup.com domain

I'm trying to move everything to http://www.cyclopsgroup.org from cyclopsgroup.com, and drop the cyclopsgroup.com domain name. The domain name was dropped on time while not everything was smoothly migrated to new domain name...wonderful

Oh my god, they killed the domain, they...