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


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