VIM: show column number

  • Option 1:
    set laststatus=2
    set statusline+=%F\ row\:%l\ col\:%c
  • Option 2:
    set ruler

vim: set line height/space

echo "set linespace=5" >> ~/.vimrc

MacVim: set font size

 echo "set guifont=Menlo Regular:h14" >> ~/.vimrc
  • CMD+= to zoom in
  • CMD+- to zoom out

TCL: array to list or list to array

  1. List to array:
    > array set a [list b 1 c 2 d 3]
    > puts $a(b)
    > puts $a(c)
    > puts $a(d)
  2. Array to list:
    > puts [array get a]
    b 1 d 3 c 2

MacVim for Mac OS X Mavericks

vim: indent with 4 spaces

vi ~/.vimrc
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

Eclipse 4.4 Luna on Mac OS 10.9.5: is not supported on this type of mac

I have recently installed Mac OS 10.9.5 update. After update, I found failed to start, it pops up a window with message: "It is not supported on this type of Mac."

The solution is:

  1. Find your java home:
    /usr/libexec/java_home -V
    , you can see the java home like below:
    Matching Java Virtual Machines (1):
        1.8.0_20, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
  2. Edit file: /Applications/eclipse/, and insert the follow line:
    to the proper location.
  3. Now you can try to click the icon, if it pops up another error message: "Eclipse is damaged and can’t be opened. You should move it to Trash.", you will need to run the following command to fix:
    xattr -d /Applications/eclipse/
  4. Note: you can run the following command to check directory attributes:
    xattr /Applications/eclipse/

see also

Clonezilla: shutting down caused by "critical temperature"

When running clonezilla on a i3 laptop, it shut down because of high cpu temperature. The solution for this is below:
  • While getting into the clonezilla wizard, and before starting the cloning process, Alt+F2 open another terminal:
  • Run the command
    you will see the output like below:
    analyzing CPU 0:
      driver: acpi-cpufreq
      CPUs which run at the same hardware frequency: 0
      CPUs which need to have their frequency coordinated by software: 0
      maximum transition latency: 10.0 us.
      hardware limits: 933 MHz - 2.13 GHz
      available frequency steps: 2.13 GHz, 2.00 GHz, 1.87 GHz, 1.73 GHz, 1.60 GHz, 1.47GHz, 1.33GHz, 1.20 GHz, 1.07 GHz, 933 MHz
  • Run the follow command:
    sudo cpufreq-set -c 0 -f 1.60GHz
    to throttle the cpu speed to 1.6GHz.
  • Alt+F1 to switch back to clonezilla terminal, and start the clone process

See also

Eclipse for Windows: Could not open/create prefs root node Software\JavaSoft\Prefs

When compiling a project cloned from git repository, got the following warning:
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.


  • Run regedit
  • Locate key HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs
  • Right click the icon then select Permissions...
  • Give full control to users

Change directory ownership recursively on Windows 7

Open Command Prompt as Administrator:
takeown /f "C:\Path\To|Folder" /t /d y
icacls "C:\Path\To|Folder" /grant wilson:F /t /q

See also

Create a bootable Window 7 installer usb disk on Debian 7

  1. You need to the Windows 7 ISO image file ready. e.g. Win7.ISO
  2. You need to install p7zip-full to extract the ISO image.
    sudo apt-get install p7zip-full
  3. You need to install ms-sys
  4. Plugin your USB disk and check its device name.
    sudo blkid
  5. Make a NTFS partition on the USB drive by using cfdisk, or gparted and apply boot flag to it.
  6. Format the USB partition,
    sudo mkfs.ntfs -n WIN7 /dev/sdX1
  7. Mount the partition by pulling off and re-plug in the USB drive or run
    mount /dev/sdX1 /media/USB
  8. Extract the ISO image to the mounted partition:
    cd /media/USB; 7z x /path/to/Win7.iso
  9. Run ms-sys to install the Window 7 boot sector:
    ms-sys -7 /dev/sdX
    Note: you need to install the boot sector to the USB drive's MBR, so you should use /dev/sdX NOT /dev/sdX1

See also

Remove grub boot sector from a partition

I accidentally installed grub boot sector onto partition /dev/sdc1 instead of /dev/sdc, which is wrong. To remove the boot sector from partition /dev/sdc1:
sudo dd if=/dev/sdc1 of=sdc1.bootsector bs=512 count=1
sduo dd if=/dev/zero of=/dev/sdc1 bs=512 count=1
The file sdc1.bootsector is a backup in case anything go wrong.

Install ms-sys on Debian

  1. Download ms-sys from
  2. Install required packages:
    sudo apt-get install build-essential gettext
  3. Extract the source, and compile, then install:
    cd /tmp; tar zxvf ~/Downloads/ms-sys-2.4.0.tar.gz; 
    cd /tmp/ms-sys-2.4.0
    sudo make install


  • You need to install build-essential package to install the compilers.
  • You need to install gettext package to fix the error msgfmt: command not found

Javascript: remove an element from an array

var e = { 'name':'John West' };
var array = [];

# remove element from the array
var idx = array.indexOf(e);
array.splice(idx, 1);

javac: include a directory into classpath

On Unix platform:
javac -cp /opt/eclipse/plugins/*:/myproject/lib/*
On Windows platform:
javac -cp "c:/eclipse/plugins/*:d:/myproject/lib/*"

see also

Java decompilers

Open source

Close source

See also

PostgreSQL: make a copy of an existing database (includes tables and all records)

If the source database is owned by another user, you must login as super user, then run the command in psql:
CREATE new_db WITH TEMPLATE old_db OWNER src_db_owner
or run the command in terminal:
createdb -O src_db_owner -T src_db new_db

You may get errors if the source database is in use:
ERROR:  source database "src_db" is being accessed by other users
You can kill all the connections to the source databse:
SELECT pg_terminate_backend(pg_stat_activity.procpid) FROM pg_stat_activity 
WHERE pg_stat_activity.datname = 'src_db' AND procpid <> pg_backend_pid();
then run the command
CREATE new_db WITH TEMPLATE src_db OWNER src_db_owner

Python: int to hex string





Python: generates crc32 and adler32 checksum for big files

import zlib
import sys
import urllib2

def __zlib_csum(url, func):
if isinstance(url, basestring if sys.version_info[0] < 3 else str):
url = urllib2.Request(url)
f = urllib2.urlopen(url)
csum = None
chunk =
if len(chunk)>0:
csum = func(chunk)
while True:
chunk =
if len(chunk)>0:
csum = func(chunk, csum)
if csum is not None:
csum = csum & 0xffffffff
return csum

def crc32(url):
return __zlib_csum(url, zlib.crc32)

def adler32(url):
return __zlib_csum(url, zlib.adler32)

if __name__ == '__main__':