Saturday, November 29, 2008

My Favorites

Here is a list of my favorites:

Favorite Ancient Civilization : Maya
Favorite Animals : Cobra , Firefox & Panda
Favorite Astronomy:Eclipse & Sun
Favorite Drinks:Java
Favorite Flights:Apache & Tomcat
Favorite Fruits:Apple, Blackberry & Orange
Favorite Girl:Ruby
Favorite Heroine:Oracle
Favorite Legends / Mythology:
(Greek)Kerberos, Oracle of Delphi, Python & Trojan Horse
(Indian)Thunderbird
(misc)daemon
Favorite Painter:Michelangelo
Favorite Professionals:Ada & Pascal
Favorite Snacks:cookies & hot dog


Friday, November 28, 2008

Display the Length of the Filename in Windows

Sometimes if the file name is too long, some application will not work properly. So, it is better to make the name short. What is the length of the file name now ?

Instead of counting by fingers, I have written this JScript named filename_length.js :

// -------------------------------------------------------------
// Licence Information:
// --------------------
// This coding is offered at no charge for 
// NON-COMMERCIAL PERSONAL USE only.
// The coding is copyright.
// Reproduction of this coding in whole or in part 
// in any form without the express written permission 
// of the author is strictly prohibited. 
// -------------------------------------------------------------
// Disclaimer : 
// ------------
// This coding is distributed "as is" and is UNSUPPORTED.
// NO WARRANTY of any kind is expressed or implied.
// You use AT YOUR OWN RISK.
// The author will not be liable for any data loss,
// damages, and loss of profits or any other kind of
// tangible or intangible loss while using or 
// misusing this coding.
// -------------------------------------------------------------
// Purpose: Display the length of the filename(s)
//          as well as the length of the fullpath filename(s).
//          If there are multiple files,
//             the whole list of files will be displayed line by line
//             with the length of the fullpath filename inside brackets
//             And, at the end, the file(s) with the longest length
//             will be identified (except when all files are with same
//             length).
// Noted  : This script counts the number of characters in the name,
//          not the number of byte.  Double-byte character (e.g.
//          Chinese) is counted as 1 in the filename length.
//          For example, a filename with 4 Chinese characters will
//          give a length of 4 (even though the name occupies 8 bytes).
// Limitation: 1. The total number of files passed to this script
//                cannot be too large because this will trigger the 
//                error - arguments list is too long
//             2. When filename is with Unicode characters, some 
//                application cannot open it because the application
//                does not use Unicode-API.
//                This script also cannot display Unicode filename
//                correctly.  Instead, a Question Mark will be seen.
// Platform    : Windows XP
// Installation: 1. Put this script in the any folder you like
//               2. Go to the Send To folder
//               3. Create a shortcut to point to this script
// Usage     : Inside any folder,
//             1. Select one (or multiple) file
//             2. Right-Click
//             3. Select Send To
//             4. Select the shortcut of this script
//             The information will be dislayed in a pop up window.
//             After reading, click OK to quit.
// Author    : Alvin SIU
// Date      : 2007-11-28
//-------------------------------------------------------------

  var fso=  WScript.createObject("Scripting.FileSystemObject");
  var args= WScript.arguments;

//-------------------------------------------------------------
// Ensure at least 1 argument
//-------------------------------------------------------------
  if (args.length == 0) { 
    WScript.Echo('The script requires argument(s)'); 
    WScript.Quit()
  }

//-------------------------------------------------------------
// Main program
//-------------------------------------------------------------
  var dasFullpathFilename ;
  var dasFilename         ;
  var dasCount            ;
      dasCount= 0         ;
  var dasLongest          ;   
      dasLongest= 0       ;
  var dasLongestString    ;  // Store all filenames with longest length
      dasLongestString= '';
  var k                   ; 
  var dasString           ;
      dasString= ''       ;
  var dasString1          ;
  var shorter             ; // When all files are with same length,
      shorter= false      ; // both the longer and shorter flags
  var longer              ; // will be false.
      longer=  false      ;
  var dasCount            ;
      dasCount= 0         ;

  for ( k= 0 ; k < args.length ; k++) {
    dasFullpathFilename= args(k) ; 
    dasFilename= fso.GetFileName(dasFullpathFilename);

    dasCount++ ;
    dasString1= '[' + dasCount + '.]     '
              + dasFilename.length + ' ( ' 
              + dasFullpathFilename.length + ' ) ' 
              + dasFilename + '\n';

    dasString+= dasString1 ; 

    if     (dasFilename.length > dasLongest) {
              if (k > 0) longer= true ; 
              dasLongest=       dasFilename.length ;
              dasLongestString= dasString1 ;
    }
    else if (dasFilename.length == dasLongest) {
              dasLongestString+= dasString1 ;
         }
    else shorter= true;
  }

  if (k > 1) {
     if (shorter | longer) {
        WScript.Echo( dasString
                    + '\nThe Longest Filename is/are :\n'
                    + dasLongestString);
     }
     else {
            WScript.Echo( dasString );
          }
  }
  else {
         WScript.Echo( dasFilename.length + ' : ' 
                     + dasFilename+'\n'
                     + dasFullpathFilename.length + ' : ' 
                     + dasFullpathFilename);
       }

//-------------------------------------------------------------
// End Of Script
//-------------------------------------------------------------
The installation and usage instructions are at the beginning of the script flower comment.


Alternate Line Shading in Program Coding

It is very simple to use alternate line shading in program coding like this :

program Hello_World; begin; writeln('Hello World !'); writeln('This is a demo for alternate line shading.'); end.

The alternate line shading in the above example are simply implemented by repeating the image at the left.
Of course, you have to adjust the height of the image to the line-height of the text.

This demo shows alternate line shading for 5 different shadings :

All animals are equal, but some animals are more equal than others. They are ... Administrators. Better late than never. Better never be late. Curiosity killed the cat. Who kill the Cat Woman ? Do as I say, and not as I do. How about when you say 'I do' ? Early bird catches the worm. Early programmer catches the bug. Failure is the mother of success. Program failure is a shit. Garbage in, garbage out and garbage inside out. Hello World ! Halloween ! I am serious. It was a joke. I am just kidding. Java, cookies together with the Sun : this is my breakfast. Keep your mouth shut and your ear, eye, mind, source-code, ... open. Life is just a bowl of cherries, and ... honeys. Money($) is not everything, but no money makes you a nothing. Nothing is impossible. Impossible is nothing. Is nothing impossible ? Orz Practice makes perfect. Illegal practice makes money. Quality rather than quantity. But, man-day is a measure for quantity. Rome was not built in one day, so did computer systems. Simple is beautiful. Simple mind is brilliant. Simphson is ... There are 10 types of people in the world: Those who understand binary, and those who don't. Universe in a nutshell. C, C++, Java, Perl, SQL, Unix, ... also in a nutshell. Vision without action is merely a dream. Action without vision just passes time. Wonder is the beginning of wisdom. Wonder Woman is ... WoW ! XD :) XP (^o^) (^0^) (^O^) ... 囧囧 You jump, I jump ! Z notation is ...

The alternate line shading colors in the above example are implemented by repeating the image at the left.

Licence Information:
All coding in this article is offered at no charge for NON-COMMERCIAL PERSONAL USE only.
The coding is copyright.
Reproduction of this coding in whole or in part in any form without the express written permission of the author is strictly prohibited.

Disclaimer :
All coding in this article is distributed "as is" and is UNSUPPORTED.
NO WARRANTY of any kind is expressed or implied.
You use AT YOUR OWN RISK.
The author will not be liable for any data loss,damages, and loss of profits or any other kind of tangible or intangible loss while using or misusing this coding.


Thursday, November 27, 2008

Make Hong Kong Post as a Trusted CA in Firefox 3.0.4

Every time when I login the Renewal of Libarary Materials of Hong Kong Public Libraries and the eTax of Inland Revenue Department of Hong Kong to perform any taxation related activities, Firefox 3.0.4 will pop up to ask me to add the site as exception. So far I was asked 3 times because in each time I was re-directed to a different server , namely etax11, etax21 and etax22. This is quite troublesome.

So, the best way is to add the Hong Kong Post as a trusted CA in Firfox.

To do so, the first step is to get the certificate of Hong Kong Post.

Then, follows these steps

  1. Go to Firefox 3.0.4
  2. In the main menu, click Tools
  3. Click Options
  4. Click Advanced
  5. Click Encryption tab
  6. Click View Certificates button
  7. Click Authorities tab
  8. Click Import... button
  9. In the pop up window, locate the file Hongkong Post Root CA 1.cer
  10. Click Open button
  11. In the Downloading Certificate window, click View button to examine the certificate
  12. Make sure the Issued by is Hongkong Post Root CA 1
  13. Make sure the SHA1 Fingerprint is D6:DA:A8:20:8D:09:D2:15:4D:24:B5:2F:CB:34:6E:B2:58:B2:8A:58
  14. Click Close button to close the view
  15. Tick the check box Trust this CA to identify web sites
  16. Click OK button
  17. When back to the Authorities tab, the Hongkong Post entry should be appear in the Certificate Name column.
  18. Click many OK buttons to end and save the setting

Now the Hongkong Post is one of the trusted CA in your Firefox. When going to the sites having certificates issued by Hongkong Post, it will be trust and will not prompt for add exception in Firefox.

For example, when you go to Hong Kong Public Libraries for books renewal, the site will be trusted. At the bottom right corner of the status bar, there is a site name libcat.hkpl.gov.hk with a lock button. Double-click the lock button and then the View Certificate button will see the certificate.

BTW, as at 2008-11-28, the eTax of Inland Revenue Departement of Hong Kong still cannot support the browser Firefox 3. However, as at 2009-02-05, Firefox 3 can be used to login the eTax.


Wednesday, November 26, 2008

Search Operators in Google

Although we use Google everyday, do you really know about some advanced technique.

This URL www.googleguide.com - Special Characters: Summary show some useful search operators (e.g. + - ~ OR | .. *) in Google search.

The URL also contains some other userful information of Google search.


Tuesday, November 25, 2008

Remove Square Brackets in Filename

When you drag a file (e.g. index.htm) from the Temporary Internet Folder to a standard folder, the file is renamed with square brackets with a number inside (e.g. index[1].htm or index[2].htm).

The URL SCRIPTING REMOVE BRACKETS REVISITED has a JScript to remove this square brackets. The steps are :

  1. Put the JScript in the SendTo directory
  2. Over the file (e.g. index[1].htm), right click
  3. Select Send To
  4. Select the JScript

Then, the file will be renamed with square brackets removed.


Monday, November 24, 2008

Run the BlackBerry Localization Demo

After numerous trials and errors and searching the net, I finally can partially run the Localization Demo of BlackBerry in Eclipse 3.4.1.

By default, the simulator's language is English. So, the followings are the steps to call the application in English :

  1. Go to the Simulator
  2. Press Menu key
  3. Choose Downloads
  4. Choose Localization Demo
  5. In Choose a Country:, the default is United States. Just let it be.
  6. Press the Menu key
  7. Choose View. The information of USA is displayed on the screen.
  8. Press Escape key to back to the Choose a Country:
  9. Click the United States to call the pop up menu
  10. Press down arrow in the keyboard to go to China
  11. Press Enter key in the keyboard. Now, the China information is display.
  12. Press Escape key to back to the Choose a Country:
  13. Click the China to call the pop up menu
  14. Press down arrow in the keyboard to go to Germany
  15. Press Enter key in the keyboard. Now, the information of Germany is displayed.
  16. Press Escape key to back to the Choose a Country:
  17. Press Escape key to quit the application

To test the Demo in German, one have to add the German language into the simulator. For example, when using the simulator 9530, edit the 9530.xml to locate the line:

<application>net.rim.blackberry.lang.en_GB</application>
Then, add the following line under it :
<application>net.rim.blackberry.lang.de</application>
Afterwards, use the followings to test the application in German :
  1. Go to the Simulator
  2. Press Menu key
  3. Choose Options
  4. Choose Language
  5. In the Language:, choose Deutsche
  6. Press Menu key
  7. Choose Save. Now everything is in German. Hope that you know German :)
  8. Press Escape key
  9. Choose Downloads
  10. Choose Sparchopti...
  11. In the screen, the default is United States. Just let it be.
  12. Press the Menu key
  13. Choose Anzeigen to view the information of USA in German language
  14. Press Escape key to go back
  15. Click the United States to call the pop up menu
  16. Press down arrow in the keyboard to go to China
  17. Press Enter key in the keyboard. Now, the China information is display in German
  18. Press Escape key to go back
  19. Click the China to call the pop up menu
  20. Press down arrow in the keyboard to go to Deutschland
  21. Press Enter key in the keyboard. Now, the information of Germany is display in German
  22. Press Escape key to go back
  23. Press Escape key to quit the application
  24. Now reset the phone to English.   Choose Optionen
  25. Choose Sprache
  26. In Sprache:, click the Deutsch to show the pop up menu
  27. Choose English
  28. Press the Menu key
  29. Choose Speichem to save the setting. Now, everything will resume to English

For France, in the 9530.xml add the following lines under it :

<application>net.rim.blackberry.lang.fr</application>
Then, follow the similar steps as German to test the application.

BTW, I have tried the followings language but seems that 9530 simulator does not support them :

  • Netherland (net.rim.blackberry.lang.en_NL)
  • Traditional Chinese (net.rim.blackberry.lang.zh_TW)
  • Simplied Chinese (net.rim.blackberry.lang.zh_CN)


Duplicate Open Current Folder in a New Window

Sometimes after I opened a folder in Win7, I would like to duplicate open the same folder again in another explorer window. Then, I can ope...