Friday, October 31, 2008

Applications that I have lost while upgrading to a new laptop

PDFSAM: split and merge PDF files
Gallery remote: upload pictures to gallery
Cygwin: X-win simulation system under windows
Avaya IP Softphone: allow me to use my desktop phone on my computer
7-Zip: A group of compress/decompress tools, mainly used it for handling RAR files
SecureFX: complete broken on the new system, always crashes, have to use FileZilla instead
SecureCRT

After starting the new computer, I found that another important feature that I missed to backup is Macros for Microsoft word. All gone!

Saturday, August 30, 2008

2006 Pillar Box Red (Australian)

Some quotes "
Pillar Box red is an opaque red/black color with a scarlet rim. It displays aromas of sweet, ripe red berries underpinned cinnamon spice and dark chocolate. The palate is rich and fleshy with vibrant raspberry & blackcurrant fruit intertwined with a citrus like cedary oak complexity. The tannins are full yet soft and supple, combined with the gentle acidity to produce a lingering harmonious finish. 53% Shiraz/37% Cab/10% Merlot Named after the proprietor of the 19th century mail coach service which once ran through their property, the Longbottom family has created a new family tradition of winemaking with such Henrys Drive, Parson's Flat and now Pillar Box Red. An INCREDIBLE value wine made by Chris Ringland.
"

Friday, July 18, 2008

Fontanafredda Barbera D'alba Briccotondo 2006 - Red wine (Notes)

Quotes from wine spectator (90 points):

"Very plummy and grapey on the nose, with hints of chocolate. Full-bodied, soft and succulent, with lots of flavor and a long, long finish. Delicious. This is very well-made."

Saturday, July 05, 2008

Wairau River Sauvignon Blanc 2006 Notes

Quote from wine seller
"
Established in 1978, the Rose family estate vineyards are situated on the banks of the Wairau River. Low crops and ripe fruit produce wine that has become renowned for exhibiting intense fruit characteristics and classical elegance. “The philosophy that we pursue has always been one of elegance and fruit power with the foundation of the style being drinkability. We put a lot of store in the selection of flavors in the vineyard, subsequent small batch vintning and the final touches of the marriage are created at the blending table.

Fleshy and ripe, with very good intensity to guava, pink grapefruit, grass and wet stone flavors. Tart lime juice acidity streamlines the fruit through a minerally finish.
90 Points
Wine Spectator
"

Wednesday, June 04, 2008

Facebook Wiretap puzzle - Heuristic Solution

The original problem description is available here at Facebook website (Illegal Wiretaps).

Since the puzzle is basically related to finding the minimal cost of analyzing all the names, we need to figure out the cost of assigning each name to the different programmers. The cost associated with each (name, programmer) pair is quite straightforward given all the weird behaviors described for each programmer :-)

Let's use matrix c[n, n] (bad feeling here because we are looking at n^2 at least here) to store the cost values where n is the number of names and m is the number of programmers. c[i, j] represents the cost for assigning name[i] to programmer j.

For i = 1 to n {
parse name[i] to get length[i], vowel[i], consonant[i];
for j = 1 to n {
c[i, j] = length[i];
if(j%2 == 0) c[i, j] += vowel[i]*1.5;
else c[i,j] += consonant[i];

//Need to find the greatest common divider
gcd = GCD(length[i], j);

//find the prime factors of the gcd
k = factor(gcd);

c[i,j] += k*2;
}
}

Now that we have the cost matrix, the problem basically becomes how to pick n values from this matrix so that the sum of these n values is minimized. In addition, these n values cannot share the same row or column numbers with each other. The solution to this part might be obvious to anyone with CS background, but it took me some time to associate this problem with an interesting problem (mincost maxflow) in graph theory: If we view the 26 names as 26 nodes on the left side and the 26 programmers as 26 nodes on the right side, then each left node has a full mesh connection to the 26 right nodes forming a bipartite graph; we can view each connection from left to right as having capacity 1, but the cost is equal to c[i, j]. In addition, if we connect a virtual source node to the 26 left nodes and a virtual sink node to the 26 right nodes, assuming the virtual connection each have capacity 1 and the same cost (e.g. 1), then the problem now becomes how to find the max flow from the source node to the sink node with lowest cost. The max flow in this case is always 26, but the minimal cost and mapping structure is what we want to find here.

More details will come ...

Other stuff related to the above solution:
1. Find the GCD of two numbers (Facebook programmers really like GCD as it is used also in the Korn shell puzzle):

GCD(i, j)
{
if (j==0) return i;
return gcd(j, i%j);
}

2. Find the prime factorization of a number. This is supposed to be a difficult problem as many of the crypto algorithms rely on the fact that it is hard to factor numbers. But luckily we are dealing with small numbers here (first of all, only 26 characters used; second of all, hope any reasonal people will not give their child a long name that takes hours or more to write :-)), so the follow simple algorithm should do:

factor(n)
{
k = 0; factor = 2;

while(n > factor) {
if (n%factor == 0) {
n = n/factor;
k++;
} else { factor++;
}
}

return k;
}

The return value k is the number of primes that n can be factored into.

Monday, June 02, 2008

Facebook Korn Shell Puzzle - heuristic solution

The original problem description is available here at Facebook website (Korn Shell).

The example itself gives a hint on how to start the thinking:
Mike Korn <-what you typed originally
Jodt Dabn
Kafh Flcn
Dlmw Mgzn
Fgjq Jixn
Mike Korn <-what appears eventually

For each character, there is group of characters related to it and they form a closed group {M, J, K, D, F}, {O, A, L, G, I}, {T, H, W, Q, E}, {B, C, Z, X, R}, {N}, the period of each group is 5, 5, 5, 5, and 1 respectively in this case, so the number required to get back to Mike Korn from initially typing this name would be least common multiplier of those period, which is 5 in this case.

Now if we generalize this problem for any name, then the question can be viewed as follow:
For a name containing n distinct characters, how do you divide 26 characters into m (m <= n) groups so that the least common multiplier (LCM) of the cardinality of these m groups can be maximized. The valid value for n is between 1 and 26, but it is obvious that even if n=26, you may still want to divide the characters into fewer than 26 groups to achieve max value.

Let's focus on finding the max value if we divide the 26 characters into m different groups. Let's define f(n, m) as the max value for dividing n characters into m groups.

For m=1, it is easy, the max period is n if we view the n characters as a single group. f(n, 1) = n, n = 26 in the facebook puzzle.

For m=2, we need to divide the n characters into two groups, the max period is

f(n, 2)
{
max = 1;
for i = 1 to n/2
if LCM(i, n-i) > max {max = LCM(i, n-i); }

return max;
}


For general m, the problem is a bit trickier, we can try to use the following recursive function to get f(n, m)

f(n, m)
{
if n = m { return 1;}
if m = 2 { return f(n, 2) as calculated above in m=2 case;}

max = 1;
for i=1 to n- m + 1
if LCM(i, f(n-i, m-1)) > max { max = LCM(i, f(n-i, m-1); }

return max;
}


If the top-down recursive approach is not preferred, then we can convert the above function into a bottom-up array calculation as follows:

Initialize f[n, n] to all 1;

for i = 1 to n {
for j = 1 to i {
if i = j then f[i, j] = 1;
else if j = 1 then f[i, j] = i;
else {
for k = j-1 to i-1
f[i, j] = max(f[i, j], LCM(i - k, f[k, j-1]));
}
}
}

Once you get f[n, m], then for a particular n, the max value will be the one given by max (f[n, i]) where i=1 to n.

In our case, n=26, the result shows that when i=5, you achieve the max value 1260. This means that when the name contains at least 5 distinct characters then there is a way to design the keying function so that you need to type 1260 times to get the correct name. The keying function is designed by dividing 26 characters into groups of 1, 4, 5, 7, and 9, each group containing at least one of the distinct characters in the name.

Now, the above solution gives us O(n^3) time complexity which is awful. Is there anyway we can optimize the solution? After let my mind wondering off some time at work :-) (sorry, I can't help but thinking about this thing ...), it seems that there might be another simpler way to formulate the solution:

Instead of looking at f(n, m), where m is the distinct number of groups that we need to divide the n characters, we can just look at the f(n), which represents the max value obtained by dividing the n character into n or fewer than m groups. Obviously f(1) = 1. The problem now becomes: given f(i) where i < n, how do we get f(n)? We can see that the new divisions allowed are:
- putting all n into one group
- putting i (1~n-1) into one group, while the rest are distributed based on the best case in f(n-i).
As a result, we get the following simplified algorithm:

initialize all f[n] to 1;

for i = 1 to n
for j = 0 to i-1
if(j=0) f[i] = max(i, f[i]);
else f[i] = max(f[i], LCM(i-j, f[j]);

return f[n];

Again if n=26, then f(n) = 1260. Note that j=0 in the above code is important to cover the boundary case; if you start from j=1 the calculation will be off by one (f[n] actually gives the value for n-1).

Other stuff related to this problem:

1. Function for calculating LCM:


LCM(i, j)
{
k = i*j;

//calculate the Greatest common divisor of i and j;
while i!= 0 {
if i < j {
tmp = i; i=j; j=tmp;
}
i = i%j;
}
return k/j;
}


2. You can notice that in both the complex solution and the simpler solution, there is an important assumption, the calculation of f(n) (f[n, m] in the first case) can be build upon the value calculated in f(i) (f[i, m-1] in the first case) where i is smaller than n. Still need to find a way to prove the above algorithms are correct based on this assumption.

Baggage fees for different airlines

Here is a list of the fees that the airlines will charge you for domestic flights within US unless you have achieved certain status in their mileage program.

Airlines 1st Checked Bag 2nd Checked Bag
American$15$25
UnitedNone$25
DeltaNone$25
US AirwayNone$25
SouthwestNoneNone
ContinentalNone$25
AlaskaNone$25
Midwest ExpressNone$20

Sunday, June 01, 2008

Uploading AVI or big images to Gallery

As long as ffmpeg plugin is installed properly, you should be able to upload video files to Gallery.

However, while using Gallery Remote, I kept getting some strange errors every time I tried to upload some AVI files. The error messages does not help much to resolve the issue. After some research, I found that the real problem is really the upload size limitation of your web server, nothing else.

One way to solve the problem is to change the upload size limitation within php.ini (usually located under /usr/local/lib/):
post_max_size => your preferred size
upload_max_filesize => your preferred size

Wednesday, May 28, 2008

Thoughts on Business Model and Strategy

While talking about successful companies for the past few years, people always points to companies such as Google and Apple for reference. In Apple's case, Steve Jobs is always claimed to be the one that has great vision and thus has led Apple to its success. However, from a business case study perspective, many of the analysis is retrospective in nature. For example, nobody claimed Jobs as a visionary leader when he was working on NeXT which failed later. Apple was used as a successful case in the 1st Edition of "Crossing the chasm" but was removed in the 2nd Edition during its miserable times. Business school students can analyze the hell out of why Google is successful, but it was really not Sergey Brin and Larry Page's master plan from the very beginning that made Google successful. Instead, Google's success can be attributed to a number of small successes building up to its status today. (Check the unorthodox opinion in coincidences that made google successful.)

The term "visionary" or "innovation" is always also associated with failures and trial-and-error on the other end of the spectrum. The distribution of innovation and failures can be viewed as a normal distribution. If the variance is small, it is easy to guarantee that majority of the ideas will be within the regular limit, however, this also reduces the probabilities of both the innovative ideas and foolish ideas. By allowing large variance, the probability of getting innovative idea will be high, but the probability of foolish ideas increase as well. It is important to allow trial and errors if an organization would like to encourage innovation. If we divide the idea space into four quadrants with (consensus, non-consensus)x(right, wrong), then it is the non-consensus+right idea that will generate the most return. In reality, most people are comfort within the consensus+right or consensus+wrong area just to appear normal.

Innovation itself is not enough though, the organization should also be adaptive enough to adjust its scope and areas of expertise to the challenges that the market presents.

Tuesday, May 27, 2008

You are dominated by "Network Power"

The original article titled "Network power that works too well" is available at Financial Times.

The theory is very interesting. The basic idea is very simple: people have the tendency or are even obliged to join a network with more users. The idea itself is not dramatically new as it is evident that companies are striving hard to gain their "network power" every day around us: in-network free calling or fav-5 like promotions from wireless carriers, referral plans from advertising companies, social networking from internet companies.

Tuesday, May 20, 2008

Small App to get latitude and longtitude information from Google

Have to get the lat/long values this way because the embedded geocoder is not working well with large amount of data:




Before developing this small application, I got most of my geo data from this website: http://www.realestate3d.com/gps/world-latlong.htm

To change the icons on the map, this site (http://econym.googlepages.com/geicons.htm), provides some quite detailed reference to what icons are available from google.

Monday, May 19, 2008

China Earthquake and Efficiency for Charitable Organizations

This morning Chinese news just announced that the country will put most activities on hold for three days to mourn for the huge losses in the earthquake in the southwestern region.

To find out more about the earthquake, check the following links:
** CCTV News Update (Magnitude of SW China earthquake revised to 8.0)
**Full Coverage from Yahoo
**NY Time Report
**MSN News
**Wikipedia
**China-quake.com

While making donations, both my wife and I started to look seriously on the overhead or charitable efficiencies of various organizations. It is surprising to see that many of the organizations we checked, they don't have the actual efficiency/overhead number of organization readily available from their website. There are some useful information from Charity Watch and Charity Navigator but the information is far from complete and is not very accessible.

We have put out faith in the organization sponsored by some alumni: Tsinghua Foundation, which claims to forward 100% of the donation money to China Red Cross. However, I heard rumors that the overhead of China Red Cross is over 30%, I have not been able to confirm this number from any official sources, but just hope that it is a real rumor instead of a fact.

Wednesday, April 16, 2008

Good articles on the current wave of anti-China demonstration

I may not agree what is said in this article 100%, but at least it provides some new viewpoint. It is tiring to see all the western media rattling against China without a full picture of the history and current situation.

Friday, March 21, 2008

Microsoft Word Tips: Copy/Paste with track changes

Copy text to another document with the tracked changes?

In the source document, turn off Track Changes.
In the target document, turn off Track Changes.

Now copy and paste.

However, if you have a table containing tracked changes and you select only the table, then the tracked changes won't copy into the new document. You need to select a paragraph before or after the table as well as the table itself. Now, the tracked changes will copy along with the text.

Thursday, January 03, 2008

Migrated old travel notes

2004 Mammoth Trip: Timber Ridge Lodging site

This lodge is about 2 blocks away from Canyon Lodge (Lift 7, 17, 16, 8).But it is not viable to walk if you carry gears. Next time, we can find some place on the top of Lakeview dr., which is right next to Canyon Lodge.

2003 Rafting in California

We stayed in the College Motel at Reedley (on Manning Ave.), it is a nice location with McDonald, Carls' Jr, and KFC within walking distance. There are a few Chinese Restaurants in the town, but from our experience at one of them, it was not good at all. We didn't find other interesting eating places, but the lunch box from R-N market located at the intersection of Manning and Mendocino is not a bad substitute for bread if you want to take your lunch into the National parks. A plus of staying in the College Motel is that we got to see the Fourth of July Fireworks right in front of the hotel. There are also a lot of fruit stands around the town, the white meat peaches are especially tasty.
In general, the three town: Reedley, Kingsburg and Sanger are all good places to stay because it takes only 1.5~2 hours driving to get to Yosemite, Kings or Sequoia National Parks. Sanger is the closest to the national parks, but it is within several minutes' drive to the other two town. We also found a good Italian Restaraunt in Sanger on Academy Ave. It is located in the same mall as Save Mart.

  • Advice from our guide on the Kings river:

Lower kern coming out of Bakersfield is a good choice for someone who has already rafted one or two times and learned the basic rafting. Lower kern is around class 4 with a combination of class 3 and class 4 rapids, but the river is mellifluous and is the best choice for transition from class 3 to class 4. The best time to go is when the flow is above 1000.
If you really want to try something more adventurous, Kaweah may be the river. According to the guide, on one trip, 53 out of 58 paddlers swimmed at least once.
No matter whichever river you are rafting on, Whitewater Voyage may be a good company to go.