Thursday, December 31, 2009

English Windows Systems with Chinese

This web page [ How to display and edit Chinese on English Windows systems ] is worth reading. It can make an English Windows system to be able to work with English and Chinese.

This web page [ Enter Chinese Characters under Windows XP - March 18, 2002 ] also has some information with some screen captures.

Well the above articles tell you how to ENABLE your OS to let you input Chinese char and to display Chinese char. Once, the proper font is used, the Chinese char is displayed happily. However, what is the more in-depth knowledge inside ?

Actually, Windows XP is using NTFS filesystem. This filesystem uses unicode as filenames. In other words, all filenames characters (no matter Chinese, Japanese, Korean, English, Greek, ... etc) as stored as unicode UTF-16 format as the filename. This is the underlying filesystem filename data structure.

Then, how the win32 applications interact with this UTF-16 unicode filesystem ? Unfortunately, there are 2 sets of APIs. For those unicode-aware applications, it will use the unicode API to directly handle the unicode filename. For those non-unicode aware application, there are troubles.

When the non-unicode application handles a filename of a string of double-byte, how to convert each double-byte to a unicode ? The non-unicode API will use MBCS codec. The MBCS codec together with locale information will convert a double-byte to a particular unicode char. With the same double-byte char, changing the locale will change the unicode char.

What is the default locale your XP is using ? It is already determined in Control Panel -> Regional and Language Options -> Advanced -> Language for non-Unicode programs.

This comes another troublesome situation. For example, if your system is of default locale being Traditional Chinese, you can still make a file with Japanese char using unicode aware program. Then, how the non-unicode aware program handle this filename ? This Japanese unicode char should map to a double-byte of the Japanese locale. But, the default locale is Traditional Chinese, not Japnese. What to do then ? Sometimes they simply cannot handle this file, or will display question mark in the filename.

For the details of the MBCS and the API, please refer to this web page [ All About Python and Unicode ].


Wednesday, December 30, 2009

My first "R cannot be resolved" error with Android

When I new a project for an Android sample, I intentionally select a Android 2.0.1 platform to see what happens. The program editing part seems OK. However, when I test run the program, there is an error message saying that the default AVD cannot be used. I have to find another AVD. Then, I try to fix the project property to fall back to use the Android 1.5.0 platform and test run again. Now, error message keeps up coming.

The first error message is "R cannot be resolved!". When I search the internet, I come across many replies, but non of them works. Also, they introduce other messages such as "Build Path error", "The project cannot be built until build path errors are resolved" & "missing required source folder 'gen'". I even delete the 'gen' folder, it still cannot solve the problem. I also try to copy a 'gen' folder from other sample projects, this method does not work either.

At last, what I can do is to give up this project. New another project with Android platform 1.5.0 to do this ample program again. This is a much faster way.


Wrap text inside the HTML pre tag

Normally the text inside the HTML pre tag will NOT be wrapped. However, this document [ Forcing long text lines to wrap ] shows how to make text wrap inside the HTML pre tag.


http header, BOM and meta charset

This document [ HTML-Error documents regarding charset encodings ] has documented some detail description regarding http header, BOM and the charset in meta tag of html.


Monday, December 28, 2009

The Question Mark in the Subtitle of VLC

My previous post The Square in Subtitle of VLC has documented how to set the VLC to use unicode for subtitles. However, even so sometimes there are one or two question marks at the end of each subtitle lines.

For example, when opening the subtitle files, the characters can be read without difficulties. The subtitle lines appear to be chopped at the middle and show with one of two question marks instead. After investigation, when opening the subtitle file using PSPad, the file format (as shown at the status bar) is UTF-16 LE. This is the root cause. For VLC, the subtitle file is better to be in UTF-8 format. So, simply convert the UTF-16 LE format file into a UTF-8 format file with the same name. Then, VLC can display the subtitle correctly.



Thursday, December 24, 2009

My 2nd Hello World Program using XML in Android

After finishing my first Hello World program in Android, I continued explore Android's Hello World web page. The page says that the Hello World program can be written with XML. So, I want to have a try.

Since I want to keep the first non-XML version of Hello World program, I have to setup another project for this XML version. Actually, I prefer to setup a new workspace in Eclipse for this. If I start everything from scratch, I have to input the application name, ... etc. It is quite a headache.After searching the net, I can duplicate an Eclipse workspace. Here is the steps :
  1. Make sure Eclipse is not running
  2. Copy the workspace directory [ ws_hello ] to a new directory [ ws_hello_xml ]
  3. Go to directory [ ws_hello_xml ]
  4. Go to sub-directory [ .metadata\.plugins\org.eclipse.jdt.core ]
  5. Delete all [ *.index ] files
  6. Delete the file [ savedIndexNames.txt ]
  7. Start Eclipse and choose the [ ws_hello_xml ] workspace

Using this way, a new workspace [ ws_hello_xml ] is ready for my development of the Hello World program using XML.

Then, follow the steps as documented in Android's Hello World web page, I finished my second program in Android : the Hello World program using XML.





Wednesday, December 23, 2009

Change Google Desktop Data Directory

There are many configuration data stored under the directory [ Documents and Settings ]. Therefore, it is better to backup this directory regularly. However, Google desktop has put its indexing database under this directory. This make it very large (sometimes more than 10 GB) and difficult to backup. Is it possible to move the Google Desktop directory to another place ? After searching the net, here is the solution :

  1. Stop Google Desktop by:
    1. Go to system tray
    2. Right-click the Google Desktop icon
    3. Select [ Exit ]
  2. Move the [ Google Desktop ] directory to some other location
  3. Run [ regedit ] by :
    1. Go to Start
    2. Click [ Run ]
    3. Input [ regedit ]
  4. Locate the registry key:
    HKEY_CURRENT_USER\Software\Google\Google Desktop\data_dir
  5. Change its value to the location in step-2
  6. Start Google Desktop again





My First Hello World Program in Android

Here is my first day experience of writing my first Hello, World program using Android.

A. Install the Android SDK

Firstly, I had to install the SDK :
  1. Download the SDK file [ android-sdk_r04-windows.zip ]
  2. Unzip it. Actually, it will unzip to a directory [ android-sdk-windows ].
  3. Put this directory under directory [ \bin ] (or other directory you like, provided that its name has no white space char)
  4. Go to directory [ \bin\android-sdk-windows ]
  5. Noted that there is a sub-directory [ platforms ] which is empty. Now, we are going to set it up.
  6. Run the file [ SDK Setup.exe ]
  7. This message may appear [ Failed to fetch URL https://dl-ssl.google.com/android/repository/repository.xml, reason: HTTPS SSL error. You might want to force download through HTTP in the settings. ]. Then, do the following:
    1. Click the menu [ Tools -> android ]
    2. Check [ Settings -> Force https://... sources to be fetched using http://... ]
    3. Click [ Save & Apply ] button
    4. Close
    5. Run the file [ SDK Setup.exe ] again
  8. Now, you should see a list of platforms. Simply install all of them.

After successful installation, there are many different sub-directories under [ \bin\android-sdk-windows\platforms ].

Also, the configuration information can be found in the directory [ %USERPROFILE%\.android ].


B. Install Eclipse 3.5.1

Because I use Eclipse for many other developments, I want to use a CLEAN Eclipse for this Android development. Therefore, I have to install a blank new Eclipse as follows :
  1. Download the file [ eclipse-jee-ganymede-SR1-win32.zip ]
  2. Unzip the directory [ eclipse ] to directory [ \temp ]
  3. Go to directory [ \temp ]
  4. Rename the directory [ eclipse ] to [ eclipse_A ]
  5. Move the directory [ eclipse_A ] under the directory [ \bin ]

Now, Eclipse 3.5.1 is successfully installed under the directory [ \bin\eclipse_A ]


C. Install the Android Development Tools (ADT) plugin for Eclipse

Follow these steps to install this plugin (basically it is the same steps as mentioned in the site http://developer.android.com/sdk/eclipse-adt.html) :
  1. Go to the directory [ \bin\eclipse_A ]
  2. Run the file eclipse.exe
  3. Click the menu Help -> Install New Software
  4. In the [ Available Software ] dialog, click the [ Add ] button
  5. Then, the [ Add Site ] dialog appear
  6. In the [ Name ] field, input [ Android Plugin ]
  7. In the [ Location ] field, input this URL [ http://dl-ssl.google.com/android/eclipse/ ]
  8. Click the [ OK ] button
  9. Back to the [ Available Software ] dialog, you should now see [ Developer Tools ] added to the list.
  10. Select the checkbox next to [ Developer Tools ], which will automatically select the nested tools Android DDMS and Android Development Tools.
  11. Click the [ Next ] button
  12. The [ Install Details ] dialog will appear to list all the Android DDMS and Android Development Tools features.
  13. Click the [ Next ] button to read and accept the license agreement and install any dependencies.
  14. Then, click [ Finish ] button.
  15. Wait for the installation
  16. Restart Eclipse
  17. Quit Eclipse

Now, the plugin is successfully setup in Eclipse.


D. Create Android Emulator - Android Virtual Device (AVD)

Before developing the program, you have to firstly setup the Android Emulator in which your application is run. The emulator is called Android Virtual Device (AVD).

Here are the steps to setup the most simple AVD (basically the steps are the same as documented in the Android developer site) :
  1. Open DOS prompt
  2. cd \bin\android-sdk-windows\tools
  3. Run the following command :
    android create avd --target 2 --name my_avd
  4. When being asked to create a custom hardware profile, press [ ENTER ] to accept the default [ no ]

Now the AVD named my_avd is ready for your Android application. There is a sub-directory [ my_avd.avd ] created under the directory [ %USERPROFILE%\.android\avd ].


E. Develop the Hello World Program

Before writing the Hello program, we have to setup Eclipse workspace and create an Android project inside Eclipse using these steps:
  1. Make a folder [ D:\Android_WS ] to store all Android related Eclipse workspaces
  2. Start Eclipse
  3. When you are prompt for a workspace, input the following [ D:\Android_WS\ws_hello ]
  4. Click the [ OK ] button. Eclipse will create the workspace directory [ ws_hello ] for you.
  5. Inside Eclipse, click the [ Workbench ] button on the right to go to the workbench panel
  6. Then, select the menu [ File -> New -> Project ]
  7. In the [ New Project ] dialog, there should be a folder [ Android ] which contains an item [ Android Project ]
  8. Select highlight the item [ Android Project ]
  9. Click the [ Next ] button
  10. The [ New Android Project ] dialog should appear, now fill in the Android project details.
    • For the [ Project name ] field, fill in [ HelloAndroid ]
    • For the [ Build Target ], tick the box [ Android 2.0.1 ]
    • For the [ Application name ], fill in [ Hello, Android ]
    • For the [ Package name ], fill in [ com.example.helloandroid ]
    • For [ Create Activity ] field, fill in [ HelloAndroid ]
    • For [ Min SDK Version ] field, fill in [ 2 ]
    • Click the [ Finish ] button

Once the [ Finish ] button is pressed, the project is automatically built. Then, a file [ HelloAndroid.java ] should be created under [ HelloAndroid -> src -> com.exmplae.helloandroid ] in the Package Explorer on the left. The HelloAndroid.java should look like this:
package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
Noted that the Eclipse will NOT show the line numbering. I add the numbering information for your easy reference.

Now, we have to write our own Hello World program. as follows :
package com.android.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello, Android"); setContentView(tv); } }
Noted that line-5, line-12 & line-13 are newly added coding.

Now, the program is ready to run.

F. Run the Hello World Program

Run the program inside Eclipse as follows:
  1. Click the menu [ Run -> Run ]
  2. In the [ Run As ] dialog, select [ Android Application ]
  3. Click the [ OK ] button
  4. Wait a while as it needs time to startup the simulator
  5. A red simulation phone should appear
  6. If the screen is locked due to timeout, click the [ menu ] button on the simulation phone.
  7. A text message [ Hello Android ] should appear on the black screen of the phone
  8. Click the [ Back ] button to quit the application
  9. Close the simulation



Thursday, August 6, 2009

Access Permission of the Underlying Directory BEFORE mount

In AIX 5.2, the du, find and tar command will sometimes fail in some directories. But, they can be run successfully in some other directories. Why this happens ? It is all because of the filesystem mounting.

It is very natural to mount numerous filesystems in AIX. Usually, a filesystem is mounted onto a directory of the same name in another filesystem. For example, under the ROOT filesystem, there are numerous other filesystems mounted onto many directories. When you ls these directories, you are actually getting the access permission of the AFTER-MOUNTED image. However, in AIX 5.2, the technical aspect of some commands such as find and tar will check the access permission of the BEFORE-MOUNTED directory. As a result, even the ls command reports a permission of 777 for the directory, the access permission of the BEFORE-MOUNTED underlying directory may have a permissoin of 700. Then, the find or tar command will certainly fail.

Since the ls command (and many other commands) will only reports the access permission of the AFTER-MONUTED image, how to know about the access permission of the before image ? The answer is to check the inode information. But, how to do so ?

First of all, you have to know the inode number. Supposed that your filesystem is mounted onto the directory /usr/your/directory. To search for the inode number of the underlying directory /usr/your/directory, issue this command:
ncheck | grep -e ':$' /usr/your/directory

The output may look like this:
: : /dev/hd1: 1996 /usr/God/directory 1997 /usr/your/directory 1998 /usr/others/directory : :

Then, use this command to check the access permission of the inode of the underlying directory:
istat 1997 /dev/hd1

You will certainly get the access perssions which is very different to that got from the ls command. This is the access permission of the underlying directory.



Monday, August 3, 2009

The Square in Subtitle of VLC

Sometimes when watching videos using VLC 1.0.1 with subtitle srt file, there are squares instead of readable characters in the substitle. Usually, each square is a Chinese character. When opening the srt file using a word processor with appropriate encoding (Big5, GB2312, GB18030 or Unicode), the Chinese character can be read. However, VLC 1.0.1 simply cannot display the Chinese character correctly. You can only see squares. How to handle this situation ?

First of all, convert the srt file to Unicode.

Then config the VLC 1.0.1 as follows:
  1. Open VLC 1.0.1
  2. In the main menu, click Tools
  3. Click Preferences
  4. On the LHS, click Subtitles & OSD
  5. In Subtitles Language > Default encoding, choose Universal, Chinese (GB18030)
  6. In Display Settings > Font, input the fullpath filename of the font : Font Arial Unicode MS
How to find out the fullpath filename of a font ? All fonts should be inside the directory %SystemRoot%\Fonts. Simply open this directory using details view. The filename (XXXXXXXX.TTF) should be displayed next to the column Font Name

By the way, using this method, the srt file must be in unicode and should be stored using UTF-8 format. Using UTF-16 LE format will make VLC displaying one or two question marks at the end of subtitle lines.


Thursday, July 9, 2009

The Equal Sign and Double-Equal Sign

The use of equal sign and double-equal sign is really an interesting topic in programming.
In computer programming, the assignment operation and the equal-comparison operation are two distinct operations. How to 'represent' these two operations ? The equal sign(s) plays an very important role.
In some older programming languages such as BASIC & COBOL, single equal sign is used for both assignment and equality comparison. For example, here is a COBOL snippet:

  COMPUTE X = (5 + 1) * (5 - 1).   
  IF X = 24
  THEN DISPLAY 'YES, 24'
  ELSE DISPLAY 'NOT 24'
  END-IF.


Pascal, as an language for teaching programming, wants to tell the programmer the difference between the assignment operation and the equal-comparison operation. Pascal uses colon-equal (i.e. :=) as assignment operation and single-equal sign as equality comparison. Here is a Pascal snippet:

  x := (5 + 1) * (5 - 1) ; { Assignment uses := } 
  if( x = 24 )             { Equal comparison uses = }   
  then writeln('Yes, 24');
  else writeln('Not 24') ;


Distinguishing assignment and equal-comparison is of great merit in programming. Many modern programming languages agree with this theory. In C programming lanaguage, however, an alternate approach is used. She uses single-equal sign as assignment operator and double-equal signs as the equality comparison operator. C++ and Java also follow this approach. Here is a C snippet:

  x = (5 + 1) * (5 - 1) ;  /* Assignment uses = */
  if( x == 24 )            /* Equal comparison uses == */    
       printf('Yes, 24');
  else printf('Not 24') ;

Why choose single-equal sign (instead of colon-equal or double-equal or else) as assignment operator ? The answer is for efficiency. It was told that assignment operation is a type of very frequent operation. Using a single character (instead of two or more characters) can gain speed in writing programs. Programmers input fewer keystrokes.

Although efficiency is the advantage, this violate the normal behavior of human beings. Most human beings on Earth learns arithmetics and mathematics at his very early age. When learning arithmetics, the single-equal sign represents EQUAL. Some will learn mathematics for more than 10 years before learning programming. As a result, treating single-equal sign as EQUAL is nearly an intrinsic action of human being. Here is a very simple mathematical equation:

      x + 3 = 9        x plus 3 equals 9    
      x = 9 - 3        x equals 9 minus 3
      x = 6            x equals 6


Imaging that, in the middle of the night, you are woken up by an emergency pager call to debug this program snippet:


  x = (5 + 1) * (5 - 1) ;   
  if( x = 24 )      // The programmer intends for an equal comparsion   
       printf('Yes, 24');
  else printf('Not 24') ;
Even experienced programmer may not spot the bug instantly. This is because they intrinsically treat single-equal sign as EQUAL.

To solve this problem, some suggest to put the constant in the left hand side when doing equality comparison such as this snippet:

  x = (5 + 1) * (5 - 1) ;   
  if( 24 = x )     // The compiler will shouts    
       printf('Yes, 24');
  else printf('Not 24') ;
With this method, the compiler will certainly shouts at you. Then, the programmer can fix the bug as:

  x = (5 + 1) * (5 - 1) ;   
  if( 24 == x )
       printf('Yes, 24');
  else printf('Not 24') ;
But, reading "twenty-four equals x" sounds not so comfortable as reading "x equals twenty-four".

Also, this method cannot be used when comparing two variables like this one:
  x = 5 + 1 ;   
  y = 5 - 1 ;
  z = x     ;
  if( x = y )     // Some compiler will assume an assignment   
       printf('the same') ;   
  else printf('different');   
Even the compiler gives you warning, the programming may overlook, especially when there are thousands of warnings.

In my programming life, I have another method to tackle this problem. I use SPACE. Look at this equation:
      x + 3 = 9   
      x = 9 - 3
      x = 6
Do you notice that there is SPACE in both the LEFT and RIGHT hand side of the equal-sign ? Many human beings will do the same. So, my method is to put a space in BOTH the LHS and RHS when doing equality comparison. When doing assignment operation, I put space ONLY at the RHS of the assignment operator like this:

  x= 5 + 1 ;   
  y= 5 - 1 ;
  z= x     ;                // No space at LHS of =
  if( x == y )              // Spaces at both LHS and RHS of ==   
       printf('the same') ;
  else printf('different');

If you adopt this programming style and make it as a habit, you will feel very odd when seeing this:


  x= 5 + 1 ;
  y= 5 - 1 ;
  z= x     ;
  if( x = y )
       printf('the same') ;   
  else printf('different');
This is because putting spaces at both the left & right side of the SINGLE equal sign is NOT your programming habit. There must be something wrong. You can then get aware that you should use double-equal sign.

Alvin SIU
2009-07-09
Copyright/Licence Information:
All information and coding in this article is offered at no charge for NON-COMMERCIAL PERSONAL USE only.
This blog and the coding is copyright.
Reproduction of this blog and its coding in whole or in part in paper or digitally or in any other forms without the explicit written permission of the author is strictly prohibited.

Disclaimer:
All information 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 wholly or partly of the information.

Friday, May 22, 2009

Undelete a PDS member

The following steps show how to un-delete a member of a PDS dataset in MVS
  1. Make sure the PDS dataset is NOT compressed
  2. Go to TSO Ready prompt
  3. Input pds
  4. Input the PDS dataset name
  5. Input restore
  6. answer Y to restore a member (answer N to skip)
    Noted that, for the same name, there happens to be more than one deleted copy.

Monday, May 4, 2009

Different Methods to Specify SAS Config File

There are different methods to config SAS in unix environment. First of all, for every installatoin, there is a config file stored in the installation directory alongside with the SAS executable file (i.e. the sasroot directory). This file is named config.sas in version-6, sasv8.cfg in version-8 and sasv9.cfg in version-9. This config file is effective for all users in this machine using this SAS. For example, this line in the config file can let all users to share the SAS working directory:
-work '/production/global/sas_working_directory' ;

However, if there is a config file in the $HOME directory e.g.
/home/alvin/config.sas
, SAS will use this $HOME config file instead.

Using this method, each programmer can has his/her own SAS configuration setting, e.g. using his own very large working directory instead of the global one :
-work '/my_large_filesystem/sas_working_directory' ;

But, when there are some other parameters changes e.g.
-sortsize 32M
and the program is rolled out to production, how can you ensure that the config file is also adjusted to be similar to the programmer's own config file (i.e. to -sortsize 32M) ? The change is ONLY in the programmer's config file in the programmer's $HOME directory. This is a serious drawback. (Actually, the change is not reflected in system test and user acceptance test either.)

Also, when upgrading from SAS version-6 to version-8, the name of the config file is changed from config.sas to sasv8.cfg. All user's config file under $HOME directory will be affected. Similarly when upgrading from version-8 to version-9.

Starting from version-8, we can also use environment variables SASV8_OPTIONS and SASV8_CONFIG to specify the config files. Using this method, it is more easy for all team members of a department to SHARE a common config file. For example:
export SASV8_OPTIONS='-config /company/department/common/sasv8.cfg' sas my_program.sas
or
export SASV8_CONFIG=/company/department/common/sasv8.cfg sas my_program.sas

These environmental variables can be specified in a common profile file. All team members has to call this departmental common profile file to make it effective for the login sessoin.

Another method is to specify the config file as command line option when calling the SAS executable. The advantage of using this method is the capability of specifing different configuration under different development phases. For example, in development phase, we can use a development configuration file like this :
export MYSASCONFIGFILE=/project/dvt/sasv8.cfg sas -config $MYSASCONFIGFILE my_program.sas
Then, during system test, we can do this :
export MYSASCONFIGFILE=/project/syt/sasv8.cfg sas -config $MYSASCONFIGFILE my_program.sas
During user acceptance test, we can do this :
export MYSASCONFIGFILE=/project/uat/sasv8.cfg sas -config $MYSASCONFIGFILE my_program.sas
Using this method, we can adjust the parameters (e.g. the working directory) in different development phases. In case some parameters needed to be adjusted, the UAT version of sasv8.cfg file can also be check-in / check-out to rollout to production.

By the way, since SAS version-8 and versoin-9 has some more complicated ways to specify the config file please refer here for the details for version-8 and this for version-9.

In short, before using SAS for any project, the first thing is to define the way of using the config file. It is better to use a systematic approach, rather than an ad-hoc way (e.g. the $HOME config file method).


Thursday, April 30, 2009

SAS Operator for Not-Equal

For many programmers, Pascal is the first programming language learnt. In Pascal, the operator <> means not equal.
SAS also has such a <> operator. But, this <> operator does NOT mean not-equal, it means MAX. It simply return the maximum of the 2 values under comparsion.
Actually, the offical not-equal operator in SAS are :
  1. ne
  2. ^=
  3. ¬=
  4. ~=
This is the link for SAS version-8 operators for your reference.
Frankly speaking, this quite odd usage of the <> operator in SAS will easily make some beginners fall into the trap of assuming <> to stand for not-equal. In SAS version-8, you can change the warning level to let the interpreter to issue a warning message when it sees a <> operator to alert the programmer that it is a MAX operator.
Since in real life the usage of getting the maximum using the <> operator is quite rare, my previous working experience is to use a pre-compiler alike construct to scan all SAS program to forbid using the <> operator. This can avoid falling into the trap of mistakenly using it to mean not-equal for everyone in the department. Actually, in SAS, there is a max() function which perform SIMILAR processing as the <> operator.

Substring in SAS

In many programming languages, there is a substr() function which will extract a portion of a string. SAS also has such a function. But, in SAS the substr() function is a little bit complicated.

In SAS version-8, if you put the substr() function on the left of the = sign, the substr() is actually a procedure to substitute string. It will replace a portion of the argument string with values at the right of the = sign. This link shows the version-8 syntax and here is the version-9 syntax.

If, however, the substr() function is put at the right of the = sign, the behavior of the substr() function is the normal sub-string function as expected by many ones. It will return a portion of the argument string. This link is the version-8 syntax and here is the version-9 syntax.

In SAS version-8, there is another function called kstrstrb(). Its function is to extract a substring in terms of byte. The DBCS version of this function is called ksubstr(). SAS version-9 also has these two functions.

In short, putting the substr() function on the LHS or RHS of the = sign will have very different behaviours. Putting it on the LHS will alter the argument string, just like passing parameter by reference. Putting it on the RHS is a function call with parameters passed by value and the argument string will NOT be altered.

By the way, when writing SAS macro, there are %substr() and %qsubstr() macro functions doing similar substring extraction processing.




Tuesday, April 14, 2009

Blackberry Signature Keys and Sign .cod File

This web page Install RIM Blackberry Signature Keys and Sign .cod File tells the necessary steps for handling the signature keys after receiving them.

I follow the steps to 'install' the 3 csi files as emailed from Blackberry. After this 'installation' the RBB, RRT and RCR keys are 'registered' with RIM.

Afterward, double-click the cod file. A window will be displayed to ask for signing the application using the RBB, RRT and RCR keys.

After signed, the .cod file is updated.

Throughout the whole process, there is nothing to do with Eclipse.




Thursday, April 9, 2009

My First Day Experience with Google Chrome 1.0.154.53

After installing Google Chrome 1.0.154.53, the first web page loaded is "Google Chrome: The application failed to initialize properly (0xc0000005)"

To solve this error, use Firefox to google search. This URL in techblissonline.com really helps. It told me to add a --no-sandbox option to open the application.

This is my first day experience with Google Chrome. The moral of this story is : there must be at least two browsers in your computer. In case one browser has error, you can use another one to search the internet for solution !


What is a Job ?

In this article, I am not talking about the job command in unix. I am talking about batch job.

A job can be defined as the smallest unit of work in a job scheduler. Following is some attributes of a job:
#Attributes Description
1.Executing Member Name In unix, this is the name of the job script to be executed.
In mainframe, this is the member name of the JCL.
2.Resident Directory In unix, this is the directory which stores the job script to be executed.
3.Job Owner This is the user-id to execute the job member.
4.Machine name Some scheduler acts as an central job dispatching agent. This field tells the scheduler which machine the job is to be executed.
5.some job ordering information This specify when the job is order to the machine waiting for execution. For example :
  • every 5 minute everyday
  • every 5 minute every business day
  • every 4 hour from 07:00 to 19:00 (both inclusive) everyday
  • at 01:01 daily
  • at 01:02 every business day
  • at 02:21 every Monday
  • at 02:22 every Monday and Thursday
  • at 03:31 every 1st of the month
  • at 03:32 on the last day of every month
  • at 03:33 on the last business day of every month
  • at 04:41 on March 31st of every year
  • at 04:42 on December 31st of every year
6.incoming condition A job is going to be executed only when this incoming condition(s) is satisfied. The incoming condition(s) is actually the outgoing condition(s) of the preceding job(s). Of course, some incoming condition can be an alarm time, e.g. at 0:00 every day.
7.outgoing condition When the job is executed successfully, it will give out this outgoing condition(s) to the scheduler. This outgoing condition(s) is actually the incoming condition(s) of succeeding job(s).
Of course, there are some more attributes. Different scheduler software will have its own set of attributes. The above is some common ones.

These attributes altogether will form a job record. All the job records will be stored in a job database. At regular time, the job scheduler will then scan the database to extract those job records to order (or give birth) jobs in the job agent machine (e.g. a PC) to wait for execution. When the incoming condition(s) of a job is satisfied, the job script member will then put into the unix machine to run.

It is very important to understand that a job is NOT a script nor a JCL. A job is much more than a script or a JCL. For example, a job has incoming condition(s) and outgoing condition(s). A script or JCL will not have this condition information.

Also, in the OO terminology a job is a class declaration, NOT an object. When the job is order out, an object of that job is created. In order words, job ordering is one way to NEW a job object.

When job object is newly born, its status is waiting for execution. When incoming condition is fulfilled, a script in a unix machine will be executed. If the script is executed successfully, the job object will change status to successfully run. Then, it will generate out condition(s) to the job scheduler. When to clean-up these job objects (i.e. garbage collection in Java terminology) ? The job scheduler will do it in regular base.

Each job object will have its own sysout information to store those messages issued by the printf or echo command in the job script. This is similar to the case that each object will have its own variables and methods in the OO terminoloty.

The job scheduler take full control of all job objects.


Saturday, March 28, 2009

Using ffmpeg to capture screen of flv file

ffmpeg is a powerful utility for audio and video processing. However, you have to compile the source code yourself. This web page tells how to compile the source code of ffmpeg to become executables.

One very simple use of ffmpeg is to capture screen from a flv file. Actually, this is to save a video frame to file.

For example, this command :
ffmpeg -i MyFile.flv -ss 00:00:31 -vframes 1 -y MyImage.jpg
will capture a frame from the file MyFile.flv at the time 00:00:31 to the file MyImage.jpg
If you want to capture 101 frames, here is the command:
ffmpeg -i MyFile.flv -ss 00:00:31 -vframes 101 -y MyImage-%03d.jpg
The will capture the 101 frames to the files MyImage-001.jpg to Myimage-101.jpg.
However, under Windows, there is some special processing for the percent sign. Therefore, the command has to be adjusted as follow:
ffmpeg -i MyFile.flv -ss 00:00:31 -vframes 101 -y MyImage-%%03d.jpg
In short, double percent signs have to be used under Windows.


Thursday, March 26, 2009

Change Color of the Tabs in Firefox 3.0.6

In Firefox 3.0.6 the background colors of the selected active tab and the un-selected inactive tabs are very similar. The color of the selected tabs cannot stand-out to catch your eyes. Here is a way to change the colors.
Firstly, go to the chrome directory of your profile in Firefox 3.0.6. Create or edit the file userChrome.css and add the following lines :
tab { -moz-appearance: none !important; } tab[selected="true"] { background-color: #FF6A6A !important; color: blue !important; } tab:not([selected="true"]) { background-color: #CCFFFF !important; color: black !important; }
Then, re-start the firefox.

This will make the active tab have red background with blue text and the inactive tabs have light cyan background with black text.



Saturday, March 21, 2009

Line numbering source code snippet with Javascript function on body load

Yesterday's blog I am talking about performing line numbering using Javascript for-loop hard coding. Since you have to count the line numbering beforehand in order to hard code it, this is quite troublesome. Here is a more automatic method, no need to count the line number manually.

Here is a program code snippet using this line numbering method :
program Hello_World ; begin writeln('Hello World !'); { This source code snippet is line numbered using a Javascript function which replace every line with a <li> and then use the HTML order list tag in order to make it appear as line numbering. As a result, there is a "dot" after each line number. Noted : This method does not work in IE6 when the convert-line-breaks option is turn off in blogspot. Therefore, I simply disable this method for all IE. So, if you are using IE to read this web page, there is no line numbering for this program snippet. } end.
The steps of this method are :
  1. Use a HTML TTT tag with a class XXX where TTT is either a pair of (pre + code) tags or just a div tag.
  2. Put the source code inside the TTT tags
  3. Use a Javascript function to process every lines inside the TTT tags
  4. Make the HTML to call this function in the body tag onload attribute.
The class XXX in the TTT tag is used for easy setup for CSS style sheet. Using the above example, the blue line border and the alternate gray line background image are the CSS style sheet settings.
Also, this class XXX can help as an identifier for the Javascript function to identify this special piece of information for processing. When the browser load this HTML, the function will do the following:
  1. Search all TTT elements in the HTML with the class XXX.
  2. Start processing the innerHTML information of this element
  3. Firstly, add an order list tag <ol> at the beginning with a class XXX.
  4. For each line, add a list item tag <li> at the beginning of the line
  5. At last, close the order list using this tag </ol>
  6. Then, replace the innerHTML using this new piece of information.
When the function is ready, call the function in the onload attribute of the HTML body tag. Using this way, when the HTML is loaded by the browser, this function will be automatically called. The function will scan the whole document to search for all TTT elements to add the order list processing for your source code snippets.
When applying this method in blog post of blogspot, something additional has to be done :
  • Firstly, it will be more easy to put the Javascript function in an external Javascript js file in an outside server, rather than putting inline in the HTML blogspot settings.
  • When the convert line breaks option is turn on, blogspot will replace the hard return with <br> in Firefox 3.0.6 (<BR> in IE6) in the source code snippet. In other words, the source code snippet is no longer line-by-line as seen in the blogspot editor. Instead, the original "lines" are separated by either <br> or <BR> in the innerHTML. The Javascript function has to take care of this during the processing.
  • When the convert line breaks option is turn off in blogspot, no <BR> will be inserted. Then, in IE6, there is not way to "identify" something to convert to <li>. So, I have to disable using this method when detecting a IE browser.
Using this method, the disadvantages are:
  1. One disadvantage is about the browser. As you may have noticed, if this page is read by Firefox 3.0.6, the alternate gray line background image does not match the source code text lines. It is quite difficult to control the line height of the HTML order list tag using CSS under Firefox 3.0.6 (I am still looking into this issue). But, when reading with IE6 or Google Chrome 1.0.154.53, there is no such problem. Maybe this is a bug in Firefox.
  2. Moreover, since the source code is inside the order list tag, it is quite difficult to cut-and-paste the source code in Firefox to Notepad or Writepad. When paste to PSPad, the line number is also pasted. However, if using Google Chrome 1.0.154.53, the line number is also hightlighted during copy. But, there is no line number after paste. The source code looks fine !
  3. In addition, as tested on 2009-03-21, one serious drawback of this method under IE6 is that the indentation leading space are all gone in IE6.
  4. At last, as mention before, this method is disabled when detecting a IE browser because my blogspot has turn off the convert-line-breaks option starting 2009-03-22. This is because I cannot detect a "lin" after turning off the convert-line-break option.

Friday, March 20, 2009

Line numbering source code snippet using Javascript for-loop hard coding

Here is a quick-and-dirty method of adding line numbers to the source code snippet.

program Hello_World ;

begin

   writeln('Hello, World !');

   { This method of line numbering is not so smart.
     The line numbers on the left is generated
     using a Javascript for-loop with hard-coding the
     number of loops which is 12. }

end.

The method is very simple : use a HTML table tag with only 1 row of 2 cells. The right cell is the code snippet. In the left cell, use Javascript to call a for-loop to document.writeln the line number.

The text inside both cells is inside a HTML pre tag. As long as they are of the same fonts and line heights, the line number will match the source code snippet.

Following coding snippet is contained inside a table of one cell :

program Hello_World ; begin writeln('Hello, World !'); { This method of line numbering is not so smart. The line numbers on the left is generated using a Javascript for-loop with hard-coding the number of loops which is 12. } end.

Using the same method, the line numbers are added :

program Hello_World ; begin writeln('Hello, World !'); { This method of line numbering is not so smart. The line numbers on the left is generated using a Javascript for-loop with hard-coding the number of loops which is 12. } end.

Now, the table consists of 2 cells in a row. The left cell is for line numbers.

The disadvantages of this method are:

  1. One disadvantage of this method is that the number of loop is hard-coded. You have count the total number of lines in your source code snippet and put this number in the for-loop.
  2. Another disadvantage is with the browser and blogspot.
    If the convert-line-breaks option is turn on in blogspot and you are using Firefox to read this page, the above table should be very perfect. The Pascal program end statement is at the line-12. But, if you are using IE6, the program end statement is at line-8. This is because the IE6 does not shown the blank lines from Blogger. There should be each of one blank line in between the statements program, begin, writeln, the block comment and the end statements. So, in order to take care of readers using IE6 and the convert-line-breaks is yes in blogspot, you have to count the number of blank lines and do a re-calculation on the final maximum number of lines for using in the for-loop.
    However, it the convert-line-breaks is NO, there is no such problem.
    Now, I have turn off the convert-line-breaks in my blog in blogsport and this page does not have this problem.


Wednesday, March 18, 2009

2 to the power

Here is a table of 2 to the power :

Power Of 2 Decimal Values ---------- ------------------------------------------------
  1. 1
  2. 2 ← 1 bit to store 0 or 1
  3. 4
  4. 8 ← 3 bit octet
  5. 0x10 16 ← 4 bit, half-byte to store hexadecimal
  6. 32
  7. 64
  8. 128 ← 7 bit for ASCII encoding
  9. 0x100 256 ← 1 byte = 8 bit, 0 - 255 ----------------
  10. 512
  11. 1,024 ← 1K (Kilo)
  12. 2,048
  13. 4,096
  14. 8,192
  15. 16,384
  16. 32,768
  17. 0x10000 65,536 ← 2 byte, 64K, double-byte Unicode -------
  18. 131,072
  19. 262,144
  20. 524,288
  21. 1,048,576 ← 1M (Mega), more than 1 million
  22. 2,097,152
  23. 4,194,304
  24. 8,388,608 ← 8M, 23 bit mantissa for float in IEEE754
  25. 0x1000000 16,777,216 ← 3 byte, 24 bit, 16M color --------------
  26. 33,554,432
  27. 67,108,864 ← 64M
  28. 134,217,728 ← 128M
  29. 268,435,456 ← 256M
  30. 536,870,912 ← 512M
  31. 1,073,741,824 ← 1G (Giga)
  32. 2,147,483,648
  33. 0x100000000 4,294,967,296 ← 4 byte ---------------------------------
  34. 8,589,934,592 ← 8G
  35. 17,179,869,184
  36. 34,359,738,368
  37. 68,719,476,736
  38. 137,438,953,472
  39. 274,877,906,944
  40. 549,755,813,888
  41. 1,099,511,627,776 ← 5 byte, 1T (Tera) ----------------------
  42. 2,199,023,255,552
  43. 4,398,046,511,104
  44. 8,796,093,022,208
  45. 17,592,186,044,416
  46. 35,184,372,088,832
  47. 70,368,744,177,664
  48. 140,737,488,355,328
  49. 281,474,976,710,656 ← 6 byte ---------------------------------
  50. 562,949,953,421,312
  51. 1,125,899,906,842,624 ← 1P (Peta)
  52. 2,251,799,813,685,248
  53. 4,503,599,627,370,496 ← 52 bit mantissa for double in IEEE754
  54. 9,007,199,254,740,992
  55. 18,014,398,509,481,984 ← stepping into 17 digits
  56. 36,028,797,018,963,968
  57. 72,057,594,037,927,936 ← 7 byte ---------------------------------
  58. 144,115,188,075,855,872
  59. 288,230,376,151,711,744
  60. 576,460,752,303,423,488
  61. 1,152,921,504,606,846,976 ← 1E (Exa), stepping into 19 digits
  62. 2,305,843,009,213,693,952
  63. 4,611,686,018,427,387,904
  64. 9,223,372,036,854,775,808
  65. 18,446,744,073,709,551,616 ← 8 byte ---------------------------------
  66. 36,893,488,147,419,103,232
  67. 73,786,976,294,838,206,464
  68. 147,573,952,589,676,412,928 ← stepping into 21 digits
  69. 295,147,905,179,352,825,856
  70. 590,295,810,358,705,651,712
  71. 1,180,591,620,717,411,303,424 ← 1Z (Zetta)
  72. 2,361,183,241,434,822,606,848
  73. 4,722,366,482,869,645,213,696 ← 9 byte ---------------------------------
  74. 9,444,732,965,739,290,427,392
  75. 18,889,465,931,478,580,854,784
  76. 37,778,931,862,957,161,709,568
  77. 75,557,863,725,914,323,419,136
  78. 151,115,727,451,828,646,838,272
  79. 302,231,454,903,657,293,676,544
  80. 604,462,909,807,314,587,353,088
  81. 1,208,925,819,614,629,174,706,176 ← 10 byte , 1Y (Yotta) -------------------
  82. 2,417,851,639,229,258,349,412,352


Tuesday, February 3, 2009

Always Keep LCD On in BlackBerry Simulator in Eclipse 3.4.1

I used to program my BlackBerry project in Eclipse 3.1.4 with a 9530 simulator. The LCD display of the simulator will dim out after a while. This is very annoying.

Here is to config the simulator to always keep LCD on :

  1. In the menu bar, click Run
  2. Click Run Configurations...
  3. Click the Simulator tab sheet
  4. In Profile:,click the New button
  5. When prompt for Enter profile name, for example, input 9530 English
  6. Then, click the OK button. Now, you can edit this profile.
  7. Click the Advanced tab sheet
  8. In the text box under Command Line:, there is a long command line string : ... fledge.exe ... /app=Jvm.dll Go to the end of this string, add one more option string : /keep-lcd-on
  9. Then, click the Apply button
  10. Then, click the Close button

Then, the next time when you test run your project using the simulator, the LCD display will always on. You can click the main menu View to double check. The Keep LCD On should be tick


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...