Thursday, March 28, 2013

[ Level 1 ] Install Indicator-VirtualBox in Ubuntu

You could install indicator-virtualbox to launch virtualbox guest OS.
https://launchpad.net/indicator-virtualbox/
http://indicator-virtualbox.en.uptodown.com/ubuntu

Wish this helps.

regards,
Stanley Huang

[Level 2] Allow remote display in Ubuntu 12.04/10.04

If you want to allow remote display in Ubuntu 12.04, you have do the following steps:
1. remove "-nolisten tcp" from /etc/X11/xinit/xserverrc
#[before]
$ cat /etc/X11/xinit/xserverrc
exec /usr/bin/X -nolisten tcp "$@"

#[after]
$ cat /etc/X11/xinit/xserverrc
exec /usr/bin/X "$@"

2. add "xserver-allow-tcp=true" into /etc/lightdm/lightdm.conf
#[before]
[SeatDefaults]
user-session=ubuntu
greeter-session=unity-greeter

#[after]
[SeatDefaults]
user-session=ubuntu
greeter-session=unity-greeter
xserver-allow-tcp=true

3. restart X

4. allow remote x connection
local> xhost +

5. ssh remote server and set DISPLAY
local> ssh remote_server
remote> export DISPLAY=local_ip:0.0
remote> xclock
in 10.04, you have to change above step 2 as the following:
2-10.04: add "DisallowTCP=false" in "security" section.
#[before]
$ cat /etc/gdm/custom.conf 
[daemon]
TimedLoginEnable=false
AutomaticLoginEnable=true
TimedLogin=stanley
AutomaticLogin=stanley
TimedLoginDelay=30
DefaultSession=gnome

#[after]
$ cat /etc/gdm/custom.conf 
[daemon]
TimedLoginEnable=false
AutomaticLoginEnable=true
TimedLogin=stanley
AutomaticLogin=stanley
TimedLoginDelay=30
DefaultSession=gnome

[security]
DisallowTCP=false


Wish this helps.

regards,
Stanley Huang

Tuesday, March 26, 2013

[ Level 2 ] Allow VirtualBox guest OS to create symbolic link file in host shared folder.

Allow VirtualBox guest OS to create symbolic link file in host shared folder:
$ VBoxManage setextradata "VM Name" VBoxInternal2/SharedFoldersEnableSymlinksCreate[absolution path for shared folder] 1
$ VBoxManage setextradata "VM Name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/[shared name] 1
Ex.
$ VBoxManage setextradata "MyVM" VBoxInternal2/SharedFoldersEnableSymlinksCreate/home/stanley/shared_folder 1
$ VBoxManage setextradata "MyVM" VBoxInternal2/SharedFoldersEnableSymlinksCreate/shared_name 1

And you could verify it by command:
VBoxManage getextradata "MyVM" enumerate

After setup, you have to shutdown VM (not restart) and boot up it again.

Wish this helps.

regards,
Stanley Huang

Monday, March 18, 2013

[ Level 1 ] Ubuntu tools for Mac OS.

Here are some useful tools for Mac OS.
$ apt-cache search hfs
hfsplus - Tools to access HFS+ formatted volumes
hfsutils - Tools for reading and writing Macintosh volumes
libhfsp-dev - Library to access HFS+ formatted volumes
libhfsp0 - Shared library to access HFS+ formatted volumes
squashfs-tools - Tool to create and append to squashfs filesystems
squashfs-tools-dbg - Tool to create and append to squashfs filesystems (debug)
dmg2img - Tool for converting compress dmg files to hfsplus images
hfsprogs - mkfs and fsck for HFS and HFS+ file systems
hfsutils-tcltk - Tcl/Tk interfaces for reading and writing Macintosh volumes
libhfstdc++6-4.6-dbg-armel-cross - GNU Standard C++ Library v3 (debugging files)
libhfstdc++6-armel-cross - GNU Standard C++ Library v3 (hard float ABI)
rdiff-backup-fs - Fuse filesystem for accessing rdiff-backup archives
$ sudo apt-get -y install hfsplus hfsutils hfsprogs
$ sudo apt-get -y install dmg2img
Other packages for hfs:
$ apt-cache search squashfs
squashfs-tools - Tool to create and append to squashfs filesystems
squashfs-tools-dbg - Tool to create and append to squashfs filesystems (debug)

Wish this helps.

regards,
Stanley Huang

Saturday, March 16, 2013

[ Level 2 ] Python with vim

Python with vim:
http://wiki.python.org/moin/Vim
Wish this helps.

regards,
Stanley Huang

Thursday, March 14, 2013

[ Level 1 ] How ansi color in terminal by Python script.

Sample for show ansi color in terminal by Python script.
#!/bin/env python
import os
print os.popen('echo "\033[31m\033[43mHello World!\033[0m"').read()
print '\033[31m\033[43m' + 'Hello World!' + '\033[0m'

Wish this helps.

regards,
Stanley Huang

[ Level 2 ] Connect pool for ssh.

If you want to use the concept "connection pool" for ssh, you could try the following sample.
#!/bin/bash
#
# You might need to modify sshd_config with the following attributes:
#
# MaxStartup 200
# MaxSessions 200
#
[ "$1" == "-d" ] && set -vx && shift
control_master="$1" && [ "$control_master" != "false" ] && control_master=true
username="$2" && [ -z $username ] && username=stanley
remote_host="$3" && [ -z $remote_host ] && remote_host=127.0.0.1
cmd1="$4"&& [ -z $cmd1 ] && cmd1=ls
control_master_option=""
client_cmd="/tmp/a.sh"

buildControlMaster() {
  if $control_master
  then
    ssh -N -o "ControlMaster auto" -o "ControlPath ~/.ssh/master-$username@$remote_host" $username@$remote_host &
  fi
}

createClientCmd() {
  mkdir -p /tmp/add
  rm /tmp/add/* $client_cmd
  if $control_master
  then
    control_master_option="-o \"ControlMaster auto\" -o \"ControlPath ~/.ssh/master-$username@$remote_host\""
  fi
  echo "ssh $control_master_option $username@$remote_host $cmd1 >/tmp/add/\$\$.txt 2>&1" >> $client_cmd
}

test() {
for i in `seq 1 100`
do
  bash $client_cmd &
done
wait ## wait for all child process finished!
}

buildControlMaster
createClientCmd
time test

$ ./sshControlMaster.sh true ## if open fail, ssh would create isolate session.
channel 67: open failed: administratively prohibited: open failed
channel 69: open failed: administratively prohibited: open failed
channel 86: open failed: administratively prohibited: open failed
channel 88: open failed: administratively prohibited: open failed
channel 72: open failed: administratively prohibited: open failed
channel 18: open failed: administratively prohibited: open failed
...
channel 37: open failed: administratively prohibited: open failed
channel 1: open failed: administratively prohibited: open failed
channel 5: open failed: administratively prohibited: open failed
channel 10: open failed: administratively prohibited: open failed
channel 6: open failed: administratively prohibited: open failed
channel 11: open failed: administratively prohibited: open failed

real 0m5.176s
user 0m0.424s
sys 0m0.232s
$ ./sshControlMaster.sh false ## always create isolate session.

real 0m8.926s
user 0m0.544s
sys 0m0.288s
$ 

You will still get the performance enhancement even though some open session fail and create isolate one.

Wish this helps.

regards,
Stanley Huang

Monday, March 11, 2013

[ Level 1 ] Customize your vim environment.

You could customize your vim environment by this tools.
http://yoursachet.com
MEMO:
1. comment "filetype plugin indent on" and "autoindent" to avoid auto indent mess up the indent during past "Python" script code.
2. add, :vmap <C-C>"+y, to enable Ctrl-C to copy text into clipborad.
2-1. $ vim --version | grep xterm_clipboard
2-2. $ sudo apt-get -y install vim-gtk
2-3. $ sudo update-alternatives --config vim
3. add the following settings to set different tab definition with different extension name,
autocmd FileType py :setlocal sw=4 ts=4 sts=4
autocmd FileType sh :setlocal sw=2 ts=2 sts=2



Wish this helps.

regards,
Stanley Huang

Saturday, March 9, 2013

[Level 3] Network Simulator

Memo it:
1. openWNS: www.openwns.org/Wiki
2. ns-3: www.nsnam.org, ns-3 provides python API to use.

Wish this helps.

regards,
Stanley Huang

[ Level 1 ] How to get vim all commands and argument list.

Use command:
:help :all
:help argument-list

Wish this helps.

regards,
Stanley Huang

[ Level 2 ] How to edit/display mulit-files in one terminal.

You could use serval ways to do that.
1. :tabe => tab edit. You use tabn/tabN/tabn[#] to change tab
2. :vs => virtical split. Back to command mode (press ESC key) then you use ctrl-w to change window
3. :sp => horizontal split. Back to command mode (press ESC key) then you use ctrl-w to change window

To get more help, use commands:
:help :tabe
:help :vs
:help :sp

Wish this helps.

regards,
Stanley Huang