Friday, January 29, 2010

Passing Special Characters to Commands

Citing from The Linux Cookbook: Tips and Techniques for Everyday Use

Some characters are reserved and have special meaning to the shell on their own. Before you can pass one of these characters to a command, you must quote it by enclosing the entire argument in single quotes (`'').

For example, here's how to pass `Please Stop!' to a command:

'Please Stop!'
When the argument you want to pass has one or more single quote characters in it, enclose it in double quotes, like so:

"Please Don't Stop!"
To pass special characters as a string, give them as:

$'string'
where string is the string of characters to be passed. Special backslash escape sequences for certain characters are commonly included in a string, as listed in the following table.
ESCAPE SEQUENCE DESCRIPTION
\a Alert (rings the system bell).
\b Backspace.
\e Escape.
\f Form feed.
\n Newline.
\r Carriage return.
\t Horizontal tab.
\v Vertical tab.
\\ Backslash.
\NNN Character whose ASCII code is NNN in octal (base 8).
To demonstrate the passing of special character sequences to tool, the following examples will use the figlet tool, which displays the text you give as an argument in a "font" made up of text characters (see Horizontal Text Fonts).

To pass a backslash character as an argument to figlet, type:
$ figlet $'\\' [RET]
To pass a form feed character followed by a pilcrow sign character (octal character code 266) to figlet, type:
$ echo $'\f\266' [RET]

Wednesday, April 08, 2009

Binary numerical file IO in PERL

#following is a simple example
open FP, '>a.bin';
binmode FP; #make it binary file
@values=(3.2,3.3,3.4); #list of floating values
$a=pack 'f3' , @values; #pack as 32bit floating point value
#use 'd' for 64bit floating point
syswrite(FP,$a,12); #save to file
close FP;

Tuesday, August 05, 2008

Styling form file input

Due to certain security considerations, it is very difficult to change the style of file input.
Here is a good post on how to do it.
http://www.quirksmode.org/dom/inputfile.html

Following is quoted from above article:
  1. Take a normal < type="file">
  2. To this same parent element, add a normal <> and an image, which have the correct styles. Position these elements absolutely, so that they occupy the same place as the < type="file">.
  3. Set the z-index of the < type="file"> to 2 so that it lies on top of the styled input/image.
  4. Finally, set the opacity of the < type="file"> to 0. The < type="file"> now becomes effectively invisible, and the styles input/image shines through, but you can still click on the "Browse" button. If the button is positioned on top of the image, the user appears to click on the image and gets the normal file selection window.
    (Note that you can't use visibility: hidden, because a truly invisible element is unclickable, too, and we need the < type="file"> to remain clickable)
  5. When the user has selected a file, the visible, fake input field should show the correct path to this file, as a normal < type="file"> would. It's simply a matter of copying the new value of the < type="file"> to the fake input field, but we need JavaScript to do this.

Linking with static runtime libraries with MFC

In Visual C++, due to some conflicts between libcmt.lib and nafxcw.lib, you need to
make following changes in Linker->Input

Additional Dependencies: nafxcw.lib libcmt.lib
Ignore specific libraries: libcmt.lib nafxcw.lib

Wednesday, May 28, 2008

Using C99 support in Intel Compiler

C99 only works for C. Not C++. So the code must be compiled as C code not C++ code.

Thursday, April 24, 2008

javascript variable scope

The scope of a variable is the current function or, for variables declared outside a function, the current application.
Aassigning a value to an undeclared variable implicitly declares it as a global variable.

Each function is associated with its closure chain
A variable is undefined if cannot be found in the current closure chain,
and the access attemp will generate error.

The global function 'eval' uses current closure chain to evaluate the string.
If a function is still accessible, its function closure chain is still in memory.

Tuesday, April 22, 2008

Image flicker in IE6

This is due to IE 6 keeps check for the background image specified in css property everty time the element is moved over. Note that IE 5 or IE 7 do not have this problem.

A good post about this problem is at http://www.mister-pixel.com/

The solution is to add following javascript code inside the HEAD of the page:
try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

This fix works only with Internet Explorer 6, Service Pack 1 or newer.
Also, the fix does not apply if you change the background image on :hover. It only prevents the flicker of the same background image, when changing other rules inside the :hover state. But you can still change the background position.

Thursday, September 13, 2007

Save file using different extensions in MS Word

Usually, MS Word will append a fixed extension for a given file type. If you want to use a different extension, you need to enclose the file name in quotes. For example, "textfile.dat" will force MS Word to use dat as extension.

Open a file by drag-and-drop in MS Word

Unlike many other editors, for MSWord, the file should be dropped in the menu area.
It should not be dropped in document area. If it's dropped in document area,
it will become an embedded file.

Friday, August 31, 2007

File Security tab in Windows XP

The security tab for the file property disappears in certain Windows XP installations. Here is how to display the security tab
Citing from
http://www.microsoft.com/windowsxp/using/security/learnmore/accesscontrol.mspx

To display the Security tab

Open Folder Options in Control Panel. (Click Start, click Control Panel, click Appearance and Themes, and then click Folder Options.)

On the View tab, under Advanced settings, clear the Use simple file sharing [Recommended] check box.
By using the access control feature available in Windows XP Professional, you can help ensure that only the people you want to access the files and folders on your network are able to get to them

Monday, January 22, 2007

Misleading median income

Suppose your income is at the top 20% percentile. You think your income are quite good?
Not necessarily.

Consider following senario:

You are in a BIG established company, you have a stable income of, let's say, $100k/year.
However, each of your 9 buddies are in a startup company, each only get a $80k/year salary each year.
Suppose each year one of your buddy's company go IPO, then one of them get $1M from stock options.

Then you are one of the top 20% earners among these 10 persons, because only one get higher income than you because of the stock option.
But wait.
After 9 years, you earned $100k x 9 = $900k
But each of your buddies earned $80k x 9 + $1M = $1720k
Now you are lowest one among these 10 persons.

Tuesday, December 05, 2006

use MPICH on linux

Setup environment (assuming csh or tcsh)
setenv PATH mpi_install_dim/bin:$PATH

Setup ssh:
1. Setup host authentication (by administrator), following two files are relevant. See ssh manual page for detail.
/etc/ssh/ssh_known_hosts
/etc/ssh/ssh_host_rsa_key

2. Setup user authentication (by user)
ssh-keygen -b 1024 -t rsa
cp .ssh/is_rsa.pub .ssh/authorized_keys

If ssh is setup correctly, following command should be able to run without entering password:
ssh remosthostname date

Friday, August 18, 2006

conflict of matlab with Intel IPP

If you use latest version of IPP with matlab 7.1,
then you need make sure your IPP\bin and IPP\bin\win32 is ahead of MATLAB's directory in the PATH environment variable.

linux email forwarding

Create a file named .forward at home directory with the following content:
\username, emailname@abc.com

Of couse, you need to change username, emailname and abc.com to suitable value

Saturday, May 27, 2006

Defragment windows system files

Windows Disk defragmenter does not defragment system files.
A good tool PageDefrag at http://www.sysinternals.com/Utilities/PageDefrag.html can do this.

Optimize the System Cache Size

System Key: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ Session ManagerMemory Management]
Value Name: LargeSystemCache
Data Type: REG_DWORD (DWORD Value)
Value Data: "0" for Desktops; "1" for Servers

Reference: http://www.winguides.com/registry/display.php/931/

Friday, April 14, 2006

Notes on using GnuPG

1. generate key-pair of yourself using
gpg --gen-key

2. Download desired file and its signature. The signature is supposed from person Joe
The desired file: abc.tar.gz
Its signature: abc.tar.gz.sig

3. Obtain the public key of Joe using
gpg --import KEY-FILE
or
gpg --keyserver pgpkeys.mit.edu --recv-key KEY-ID

Here KEY-FILE is the name of the file for the public key of Joe. This file needs to be obtained from Joe or other trusted source.
KEY-ID is the id of the public key of Joe. It should be obtained from Joe or other trusted source.

4. Verify that the signature using is signed using the public key
gpg --verify abc.tar.gz.sig

5. Make sure the key actually belongs to Joe by confirming the key fingerprint of the public key. The ultimate confirmation is by face to face communication.
gpg --fingerprint KEY-ID

6. If you trust Joe and are sure the public key belongs to Joe, you can sign the public key of Joe using
gpg --sign-key KEY-ID