Friday, December 24, 2010

Useful VI commands

Saving the file you're working on and/or leaving vi:

:wq              write the file to disk and quit
:q!              quit without saving any changes
:w! newfile      write all lines from the entire current file into the file 'newfile', 
                 overwriting any existing newfile
:n,m w! newfile  write the lines from n to m, inclusive, into the file newfile, 
                 overwriting any existing newfile

Moving Around In a File


Key(s)   Movement

h        one space to the left (also try left arrow)
j        one line down (also try down arrow)
k        one line up (also try up arrow)
l        one space to the right (also try right arrow)
w       forward word by word
b       backward word by word
e        end of next word

^        beginning of current line
0 (zero) to beginning of line
$       to end of current line
Enter    beginning first word on the next line

G        to last line of file
1G       to first line of file
:n       line n; use :0 to move the beginning of the file

H        to top line of screen
M        to middle line of screen
L        to last line of screen
ctrl-f   jump forward one screen
ctrl-b   jump backward one screen
ctrl-d   scroll down one-half screen
ctrl-u   scroll up one-half screen

%        the matching (, ), [, ], {, or } 
(Press % with your cursor on one of these characters to move your cursor its mate.)

Moving by searching. To move quickly in a file, search for text. In command mode, type a / (slash) followed by the text to search for. Press Return. The cursor moves to the first occurrence of that text. Repeat the search in a forward direction by typing n (lower case), or in a backward direction by typing N (upper case).

Many commands take number prefixes; for example 5w moves to the right by 5 words.

Searching for Text

Type:    To:
/string  search down for string
?string  search up for string
n        repeat last search from present position 

Substituing Text

Change all occurrences on the current line

Type    :s/thee/the/g[Ret]    meaning substitute globally on the line.
     This changes all occurrences on the line.

Change every occurrence of a character string between two lines

     Type   :#,#s/old/new/g[Ret]    where #,# are the numbers of the two lines.

Change every occurrence in the whole file

     Type   :%s/old/new/g[Ret]    to change every occurrence in the whole file.

Inserting Text

Type:        To: 
a            append starting right of cursor 
A            append at the end of the current line 
i            insert starting left of cursor 
I            insert at beginning of the current line 
o            open line below cursor, then enter insert mode 
O            open line above cursor, then enter insert mode 
:r newfile   add the contents of the file newfile starting below the current line 

Deleting Text

Type:    To:
x        delete single character; 5x deletes 5 characters
dw       delete word; 5dw deletes 5 words
dd       delete line; 5dd deletes ... well you get the idea!
cw       delete word, leaves you in insert mode (i.e. change word)
cc       change line -- delete line and start insert mode
s        change character -- delete character and start insert mode
D        delete from cursor to end of line
C        change from cursor to end of line -- delete and start insert mode
u        undo last change
U        undo all changes to current line
J        join current line with line that follows (press Enter in insert mode to split line)

Cutting and Pasting

Type:    To:
xp       transpose two characters (two commands, x followed by p)
yy       yank (i.e. copy) one line into a general buffer (5yy to yank 5 lines)
"ayy     yank into the buffer named a
P        put the general buffer back before the current line
"aP      put from buffer a before current line
p        put the general buffer back after the current line
"ap      put from buffer a after the current line 
Note: dd or any other delete will save a copy of the deleted string in the same general buffer. Therefore a cut and paste can be done with dd and p, rather than copy and paste with yy and p. But make sure not to overwrite the buffer with some other yank or delete command before you have a chance to paste.

Miscellaneous Commands

Type:    To:
Ctrl-g   show line number of current line
Ctrl-l   redraw the entire display
:!sh     fork a shell; type Ctrl-d to get back to vi
.        repeat last text change command at current cursor position

Thursday, December 23, 2010

How to translate your blog into different languages?

Google is providing a very cool tool to translate your blog into different languages.   Here are simple steps to show you how:

Step 1: Log into your blog --> Click on Design --> Click on "Add a Gadget" link --> Select HTML/JavaScript

Step 2: Copy the following code to the HTML/JavaScript page and save it.

<div id="google_translate_element">
</div>
<script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
  }, 'google_translate_element');
}
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Reference to http://translate.google.com/translate_tools

Tuesday, December 14, 2010

Chinese Characters in the Subject Line of Outlook E-Mail Message Appear As Question Marks

Chinese characters in the Subject line of a Microsoft Outlook e-mail message may appear as question marks when the e-mail message is received. This problem may occur with any characters from a double-byte character set (DBCS).

CAUSE
The Subject line in Outlook relies on the character set defined by the operating system on the client computer. To display Chinese characters in the Subject line of an e-mail message, your operating system must support Chinese.

NOTE: Windows 2000 and Windows XP are currently the only English-language Microsoft operating systems that support double-byte character sets. Outlook cannot display Chinese in the Subject line of an Outlook e-mail message on the English-language versions of Microsoft Windows 95 or Microsoft Windows 98 operating system.

To display Chinese in the Subject line of Outlook e-mail messages, install the Chinese language support files on Windows 2000 or Windows XP, and then set Chinese as the default language for the operating system of the client computer. To install the Chinese language support files and set Chinese as the default language, use one of the following methods.
1. How to Enable Chinese Support In Windows XP?
2. How to Enable Chinese Support In Windows 2000?

How to Enable Chinese Support In Windows XP

   1. Click Start, point to Settings, and then click Control Panel.
   2. Double-click the Regional and Language Options icon.
   3. On the Languages tab, click to select the Install files for East Asian languages check box.
   4. When you receive the following message, click OK:
You chose to install the Chinese, Japanese, and Korean language files. This will require 230 MB or more of available disk space. The files will be installed after you click OK or Apply on the Regional and Language Options dialog box.
   5. On the Advanced tab, click Chinese under the Language for non-Unicode programs section.
   6. Click to select the Apply all settings to the current user account and to the default user profile check box.
   7. When you receive the following message, click OK:
You chose to apply these settings to the default user profile. These changes will affect the logon screen and all new user accounts. Some system services may require you to restart your computer before the changes will take effect.
   8. In the Regional and Language Options dialog box, click Apply.
   9. When you receive the following message, click Yes:
The required files are already installed on your hard disk. Setup can use these files, or Setup can recopy them from your original Windows CD-ROM or from a network share.

Would you like to skip the file copying and use the existing files? (If you click No, you will be prompted to insert your Windows CD-ROM or to supply a different location where the files can be found.)
  10. Click Yes when you are prompted to restart your computer.

How to Enable Chinese Support In Windows 2000

   1. Click Start, point to Settings, and then click Control Panel.
   2. Double-click the Regional Options icon.
   3. In the Regional Options dialog box, click to select the Chinese check box.
   4. Click the Set default button.
   5. In the Select System Local dialog box, click Chinese, and then click OK.
   6. In the Regional Options dialog box, click Apply.
   7. When you receive the following message, click Yes:
Required files are already installed on your hard disk. Setup can use these existing files, or Setup can recopy them from your original Windows CD-ROM or from a network share.

Would you like to skip the file copying and use the existing files? (If you click No, you will be prompted to insert your Windows CD-ROM or to supply a different location where the files can be found.)
   8. When you are prompted to restart your computer, click Yes.

How to handle large binary file formats under CVS?

Reference on cvs-home faq-o-matic:

CVS can handle any binary format, but you have to let CVS know it is a binary file by setting the RCS keyword mode to '-kb'. And, the size of the binary file can't exceed 80Mb.

*** If you already have a revision checked in you may have to force an extra commit after setting the keyword substitution mode. 

*** It is worth knowing that sometimes very large binary files can cause slowdown and even stoppage of the server. In these cases, it might be worthwhile to delete revisions on the server end, but you should be very sure you know what you are doing before trying.

Reference from http://www.cvsnt.org/pipermail/cvsnt/2002-December/004403.html

Further splunking on the 'net turns up reference's to not using cvs to store large binary files.  Some of these seem to be based on pratical reasons and others on theoretical reasons (BTW, I disagree with the theoritical ones - I *want* to be able to store large binaries with my source code.  But that's another discussion.)

Oh, BTW, did I mention it works now?  Did two things - increased size of VM on server and had client turn on TCP/IP compression.  When A large binary file is encountered it is still reeeaaaalllllllyyyy slow but it eventual gets past it.  The TCP/IP toggle was
suggested here: http://www.zaptech.com/commentary/cvs/cvs.html and I suspect it is what made the difference.

Moving CVS depository to different box

Moving CVS server from sms192 box to smsjcvs box:

1. Get source files from sms192 into Source directory: (on cvs client machine)

hsual@PSGLTPE279$ pwd
/home/hsual/SanDisk/Source
hsual@PSGLTPE279$ 
hsual@PSGLTPE279$ env | grep CVSROOT
CVSROOT=:ext:hsual@sms192:/opt/cvs
hsual@PSGLTPE279$ 

hsual@PSGLTPE279$ cvs export -D 2005-12-01 JavaBase
===> NOTE: -D  Use the most recent revision no later than 
                  date (ex: 2005-12-01. Today is 2005-11-19.) 

hsual@PSGLTPE279$ cvs export -D 2005-12-01 SMS
hsual@PSGLTPE279$ cvs export -D 2005-12-01 WebSite
hsual@PSGLTPE279$ cvs export -D 2005-12-01 SMSJ_Source

2. Change the name of the SMSJ_Source directory to SMSJ: (on cvs client machine)
hsual@PSGLTPE279$ mv SMSJ_Source SMSJ
hsual@PSGLTPE279$ 

3. Change CVSROOT from @sms192 to @smsjcvs in .bash_profile: (on cvs client machine)
hsual@PSGLTPE279$ cd
hsual@PSGLTPE279$ more .bash_profile | grep CVSROOT
     CVSROOT=:ext:hsual@smsjcvs:/opt/cvs
     CVSROOT=:pserver:hsual@wdsz45.win.wellsfargo.com:/usr/local/cvsroot
hsual@PSGLTPE279$ exit

4. Create a CVS repository on @smsjcvs box: (on cvs server machine)
hsual@PSGLTPE279$ ssh hsual@smsjcvs
hsual@hp400v1$ cd /
hsual@hp400v1$ mkdir -p opt/cvs
hsual@hp400v1$ 
hsual@hp400v1$ cvs -d /opt/cvs init
hsual@hp400v1$ 

5. Handling Binary files(Global): (on cvs client machine)
hsual@PSGLTPE279$ pwd
/home/hsual/SanDisk/Source
hsual@PSGLTPE279$ 
hsual@PSGLTPE279$ cvs checkout CVSROOT
cvs server: Updating CVSROOT
U CVSROOT/checkoutlist
U CVSROOT/commitinfo
U CVSROOT/config
U CVSROOT/cvswrappers
U CVSROOT/editinfo
U CVSROOT/loginfo
U CVSROOT/modules
U CVSROOT/notify
U CVSROOT/rcsinfo
U CVSROOT/taginfo
U CVSROOT/verifymsg
hsual@PSGLTPE279$ 
hsual@PSGLTPE279$ cd CVSROOT
hsual@PSGLTPE279$ ls
CVS/          commitinfo  cvswrappers  loginfo  notify   taginfo
checkoutlist  config      editinfo     modules  rcsinfo  verifymsg
hsual@PSGLTPE279$ more cvswrappers
# This file affects handling of files based on their names.
#
# The -m option specifies whether CVS attempts to merge files.
#
# The -k option specifies keyword expansion (e.g. -kb for binary).
#
# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
#
#  wildcard     [option value][option value]...
#
#  where option is one of
#  -f           from cvs filter         value: path to filter
#  -t           to cvs filter           value: path to filter
#  -m           update methodology      value: MERGE or COPY
#  -k           expansion mode          value: b, o, kkv, &c
#
#  and value is a single-quote delimited value.
# For example:
# Media files
*.gif -k 'b'
*.jpg -k 'b'
*.png -k 'b'
*.tga -k 'b'
*.avi -k 'b'
*.psd -k 'b'
*.bmp -k 'b'
*.ico -k 'b'
*.mp3 -k 'b'
*.ifs -k 'b'
*.fnt -k 'b'
*.ttf -k 'b'
*.tif -k 'b'
*.tiff -k 'b'

# Visual Studio project files (can't be cvsmerged)
*.dsp -k 'b'
*.dsw -k 'b'

# Visual Basic file types
*.vbp -k 'b'
*.cls -k 'b'
*.frx -k 'b'
*.frm -k 'b'

# Office files
*.doc -k 'b'
*.xls -k 'b'
*.vsd -k 'b'
*.pdf -k 'b'

# Binaries
*.dll -k 'b'
*.lib -k 'b'
*.class -k 'b'
*.exe -k 'b'
*.obk -k 'b'
*.vbx -k 'b'
*.ocx -k 'b'
*.oca -k 'b'
*.bin -k 'b'
*.xcf -k 'b'
*.zip -k 'b'
*.tar -k 'b'
*.gz  -k 'b'
*.3ds -k 'b'
*.Z   -k 'b'
*.jar -k 'b'
*.war -k 'b'
*.ear -k 'b'
*.sar -k 'b'
hsual@PSGLTPE279$ cvs commit -m "add file types" cvswrappers
Checking in cvswrappers;
/opt/cvs/CVSROOT/cvswrappers,v  <--  cvswrappers
new revision: 1.2; previous revision: 1.1
done
cvs server: Rebuilding administrative file database
hsual@PSGLTPE279$ 

6. Import Modules to @smsjcvs box;
hsual@PSGLTPE279$ env | grep CVSROOT
CVSROOT=:ext:hsual@smsjcvs:/opt/cvs
OLDPWD=/home/hsual/SanDisk/Source/CVSROOT
hsual@PSGLTPE279$ 
hsual@PSGLTPE279$ ls
CVSROOT/  JavaBase/  SMS/  SMSJ/  WebSite/
$ cd JavaBase
$ cvs import -m "Imported JavaBase Module" JavaBase AlHsu Initiate

$ cd ../SMS
$ cvs import -m "Imported SMS Module" SMS AlHsu Initiate

$ cd ../SMSJ
$ cvs import -m "Imported SMSJ Module" SMSJ AlHsu Initiate

$ cd ../WebSite
$ cvs import -m "Imported WebSite Module" WebSite AlHsu Initiate

7. Verify Checked in Module:
====> CVS SOURCE MACHINE <====
hsual@hp400v1$ pwd
/opt/cvs
hsual@hp400v1$ ls
CVSROOT/  JavaBase/  SMS/  SMSJ/  WebSite/
hsual@hp400v1$ find JavaBase | wc
    114     114    4739
hsual@hp400v1$ 

====> CVS CLIENT MACHINE <====
hsual@PSGLTPE279$ pwd
/home/hsual/SanDisk/Source
hsual@PSGLTPE279$ ls
CVSROOT/  JavaBase/  SMS/  SMSJ/  WebSite/
hsual@PSGLTPE279$ find JavaBase | wc
    114     114    4551
hsual@PSGLTPE279$