Saturday, November 24, 2007

Howto install Firefox 3 to co-exists with Firefox 2

Mozilla just release Firefox 3 Beta 1. Review said it is much faster and consume less memory. It definitely worth a try but for the obvious reason you have to keep your Firefox 2. Here is the steps show you how to install Firefox 3 and make it co-exists with Firefox 2. 1. Right click the shortcut of the Firefox 2, click "Properties". Add "-profilemanager" at the end of the shortcut path. Click OK. Then run this shortcut to launch Firefox Profile Manager. 2. Create a new profile, name it "firefox3". And uncheck the "Don't ask at startup" 3. Go to Properties of the Firefox 2 shortcut again, remove the "-profilemanager" and add "-p default" at the end of the path. This forces Firefox 2 to open the original profile. 4. Start install Firefox 3. Choose "Custom" when you are asked. 5. The default Destination Folder is "Mozilla Firefox 3 Beta 1", which is stupid when you later update to Beta 2, Beta 3 or even 3.0.1. So change it to Mozilla Firefox 3 6. Same in Start Menu Folder name. 7. When installation completed, uncheck the "Launch Firefox now". You still have something to do before you can run it. 8. Go to the Properties of the Firefox 3 shortcut. Append "-no-remote -p firefox3" to the Target. The "-no-remote" will let Firefox run a separate instance. The "-p firefox3" will force your Firefox 3 to run the newly clean profile. 9. Run the Firefox 3, and you will be prompted that your Firefox is not the default browser. DON'T click Yes. Firefox 3 is not stable and you won't like to use it as your default browser. Simple uncheck the "Always perform this check when starting Firefox" and click No. 10. Now you can run Firefox 2 and Firefox 3 at the same time. Enjoy it.

Saturday, September 29, 2007

Greasemonkey script to show actual unread count in Google Reader


I subscribed over 200 feeds in Google Reader. And for some reason I did not login for a week, guess what? I have thousands of unread items. At the old days, Google Reader displayed "100+" unread items which is absolutely not enough for most users. After upgrading, it improved. Now it displays "1000+" as unread items count. It is enough for most cases, but not this one.

I start clearing the articles. After a few hours I loss the motivation. The unread count is always "1000+" and I don't know when can I finish. I don't know the target. I need to know the exact unread items count. So I wrote a Greasemonkey script to calculate the actual unread count.


After installed the script, you can see a button (the Google Reader icon) besides the unread count, click on it will do the calculation and update the unread count with the actual number. Note that it will ignore any duplicated entries.

This is not the best solution. It doesn't auto-update, you have to click it every time. But at least you can get the count and you shouldn't use it every day.

Wednesday, April 4, 2007

Learn from PNG file header

When you designing your own file format, you should consider to use the PNG file header.  This is the smartest file header.

Here is the first 8 bytes of a PNG file:

13780787113102610
PNG\r\nCtrl-Z\n

Each byte has it's own usage:
 
137
This is a non-ASCII character to serve two purposes:
- Text editor will treat it as binary file
- To catch the error on FTP ASCII transfer types

80 78 71 (PNG)
Human readable file type

13 10 (\r \n)
To catch the the file is converted from Windows line encoding to Unix line encoding

26 (Ctrl-Z)
This is end-of-file marker to prevent dispalying lots of garbage characters if user "type" file in DOS

10
To catch the the file is converted from unix Line encoding to Windows line encoding

The PNG file header can detect common transfer errors and is readable if type the file in DOS terminal.

Tuesday, February 13, 2007

A bug that is easily overlooked

Today I found a bug at work. The program is simple but the bug is easily overlooked. Here is the program (Java):
long timeSpan = 90 * 24 * 3600 * 1000;
System.out.println(timeSpan);
What is the result of execution?

This line is to calculate the total milliseconds of 90 days. The correct result shoudl be 7776000000, but the above program prints -813934592. We all know that it is numerical overflow. But why it is overflowed even I am already using long?

The problem is Java uses integer to store the intermediate result before assigning to the final variable. The correct syntax should be:
long timeSpan = 90L * 24 * 3600 * 1000;
System.out.println(timeSpan);

Wednesday, February 7, 2007

Preserve directory when change drive in cygwin

In cygwin, you can use "cd c:" or "cd d:" to change to different drives. However, it always change to the root directory of the drive. In Windows command prompt you have a nice feature that the c: or d: will change to the directory that you previous stayed in that drive. For example:
  
C:\Program Files\Mozilla Firefox\extensions>d:
D:\>c:
C:\Program Files\Mozilla Firefox\extensions>

However, in bash, you just can't do this
   
extensions>cd d:
d>cd c:
c>

Here I add some aliases to implement this feature in bash. Add the following lines in $HOME/.bashrc:
   
export PWD_c=c:/
export PWD_d=d:/
export PWD_e=e:/
alias c:='export PWD_`expr substr "$PWD" 11 1`="$PWD";cd "$PWD_c"'
alias d:='export PWD_`expr substr "$PWD" 11 1`="$PWD";cd "$PWD_d"'
alias e:='export PWD_`expr substr "$PWD" 11 1`="$PWD";cd "$PWD_e"'

You may need to add more PWD_x environment variables and alias in case you have more drive. Make sure you have the quotes (") because of the spaces in long file name.