<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8444186573141677286</id><updated>2012-02-16T16:46:00.141+08:00</updated><category term='MP4'/><category term='XtraDB'/><category term='Gossips'/><category term='cli'/><category term='DNS'/><category term='Performance'/><category term='Memcached'/><category term='SQL'/><category term='Encoding'/><category term='Simulation'/><category term='Stored Procedure'/><category term='BSD License'/><category term='Device Management'/><category term='apt-get'/><category term='Wine'/><category term='Windows7'/><category term='VirtualDisk'/><category term='Rescure'/><category term='Grub'/><category term='DTrace'/><category term='Drizzle'/><category term='OpenVPN'/><category term='VPN'/><category term='make'/><category term='Opening'/><category term='Games'/><category term='yum'/><category term='Column Database'/><category term='Git'/><category term='Jython'/><category term='Beta'/><category term='Mac'/><category term='Networking'/><category term='Benchmark'/><category term='dpkg'/><category term='Web Links'/><category term='Juniper'/><category term='Distro_Const'/><category term='JavaSE8'/><category term='Java Script'/><category term='Cassandra'/><category term='Adobe'/><category term='Zip'/><category term='System'/><category term='MySQL'/><category term='Ntpserver'/><category term='Shell Script'/><category term='Resource'/><category term='LVM'/><category term='User Management'/><category term='CentOS'/><category term='UDF'/><category term='IllumOS'/><category term='Innotop'/><category term='XML'/><category term='Perl'/><category term='bash'/><category term='Refactoring'/><category term='usb2com'/><category term='CouchDB'/><category term='Templates'/><category term='SMF'/><category term='OpenSolaris'/><category term='Tomcat'/><category term='Vim'/><category term='Firefox'/><category term='Vala'/><category term='Labs'/><category term='Django'/><category term='OpenCluster'/><category term='Notes'/><category term='Solaris10'/><category term='Reference'/><category term='Certificate'/><category term='expect'/><category term='Widget'/><category term='Process'/><category term='Benelix'/><category term='OpenSSH'/><category term='Blog'/><category term='DHCP'/><category term='Installation'/><category term='Python'/><category term='Wireless'/><category term='Level 2'/><category term='Zone'/><category term='Commands'/><category term='EeePC'/><category term='VirtualBox'/><category term='Replication'/><category term='Repository'/><category term='Info'/><category term='OpenSSL'/><category term='Compress'/><category term='Build'/><category term='Security'/><category term='Firewall'/><category term='GNOME'/><category term='Configuration'/><category term='Gcc'/><category term='Module'/><category term='Scala'/><category term='Audio'/><category term='Chrome'/><category term='Level 1'/><category term='Input Method'/><category term='MutliMedia'/><category term='Freeware'/><category term='JSON'/><category term='ScaleDB'/><category term='Transaction'/><category term='Level X'/><category term='Filesystem'/><category term='Sample'/><category term='ZFS'/><category term='Stored Functions'/><category term='Zenity'/><category term='stty'/><category term='Recovery'/><category term='MP3'/><category term='Stress Test'/><category term='ssh'/><category term='Java'/><category term='X'/><category term='Boot'/><category term='Level 3'/><category term='Scapy'/><category term='regex'/><category term='Algorithm'/><category term='terminal'/><category term='Maven'/><category term='Linux'/><category term='DRBD'/><category term='gtk+'/><category term='My BoyF riend Project'/><category term='Design Pattern'/><category term='Tools'/><category term='MySQLdb'/><category term='Hardware'/><category term='Ubuntu'/><category term='Storage Engine'/><category term='Innodb'/><category term='mkisofs'/><category term='Books'/><category term='Utilities'/><title type='text'>Open or not open, that is the stupid question.</title><subtitle type='html'>Recommend to use google chrome to browse this blog. Let's Rock~</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default?start-index=101&amp;max-results=100'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>328</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2748251758355337030</id><published>2012-02-16T14:59:00.001+08:00</published><updated>2012-02-16T14:59:50.017+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hardware'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] How to get ram spec in Ubuntu</title><content type='html'>If you want to get the ram module information from Ubuntu.&lt;br /&gt;Please use command dmidecode with type 17.&lt;br /&gt;ex.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;$ sudo dmidecode --type 17 | more&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2748251758355337030?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2748251758355337030/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/02/level-1-how-to-get-ram-spec-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2748251758355337030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2748251758355337030'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/02/level-1-how-to-get-ram-spec-in-ubuntu.html' title='[Level 1] How to get ram spec in Ubuntu'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3172305499046383506</id><published>2012-01-19T14:25:00.002+08:00</published><updated>2012-01-19T14:25:51.011+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Maven'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Installation'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] Install maven in Ubuntu</title><content type='html'>In Ubuntu, you could use apt-get to install maven.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# apt-get -y install maven2&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3172305499046383506?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3172305499046383506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-install-maven-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3172305499046383506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3172305499046383506'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-install-maven-in-ubuntu.html' title='[Level 1] Install maven in Ubuntu'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1177682526396747690</id><published>2012-01-19T14:24:00.002+08:00</published><updated>2012-01-19T14:24:42.280+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Git'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Installation'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] Install git in Ubuntu</title><content type='html'>If you want to install git in Ubuntu, you could use apt-get command:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# apt-get -y install git-core git-doc git-gui gitk&lt;/pre&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1177682526396747690?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1177682526396747690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-install-git-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1177682526396747690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1177682526396747690'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-install-git-in-ubuntu.html' title='[Level 1] Install git in Ubuntu'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7337674975265514347</id><published>2012-01-19T14:21:00.002+08:00</published><updated>2012-01-19T14:27:38.567+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Cassandra'/><category scheme='http://www.blogger.com/atom/ns#' term='Stress Test'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 3] Cassandra stress tool from git in Ubuntu.</title><content type='html'>If you want to do the stress test for Cassandra.&lt;br /&gt;You could try an open source project call cassandra-stress of zznate.&lt;br /&gt;First you must to have git client and maven.&lt;br /&gt;&lt;br /&gt;Please reference here: &lt;a href="http://stanley-huang.blogspot.com/2012/01/level-1-install-git-in-ubuntu.html"&gt;git installation&lt;/a&gt;, &lt;a href="http://stanley-huang.blogspot.com/2012/01/level-1-install-maven-in-ubuntu.html"&gt;maven installation&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Clone the src from git.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# git clone https://github.com/zznate/cassandra-stress.git&lt;/pre&gt;Then you would find a folder named "cassandra-stress", cd it and build the binary.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# cd ./cassandra-stress&lt;br /&gt;# mvn install &lt;/pre&gt;and mvn would create a sub folder "target", cd it and run the stress script.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# cd ./target/appassembler/&lt;br /&gt;# sh ./bin/stress -o insert -b 1000 -n 2000000 localhost:9160&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7337674975265514347?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7337674975265514347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-cassandra-stress-tool-from-git.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7337674975265514347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7337674975265514347'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-cassandra-stress-tool-from-git.html' title='[Level 3] Cassandra stress tool from git in Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2220342002585471626</id><published>2012-01-18T14:58:00.000+08:00</published><updated>2012-01-18T14:58:22.318+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Shell Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] Run python in shell script.</title><content type='html'>If you want to wrap python script into shell script.&lt;br /&gt;You could use the following sample code.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/sh&lt;br /&gt;# -*- mode: Python -*-&lt;br /&gt;&lt;br /&gt;""":"&lt;br /&gt;# bash code here; finds a suitable python interpreter and execs this file.&lt;br /&gt;# prefer unqualified "python" if suitable:&lt;br /&gt;python -c 'import sys; sys.exit(sys.hexversion &amp;lt; 0x020500b0)' 2&amp;gt;/dev/null \&lt;br /&gt;    &amp;&amp; exec python "$0" "$@"&lt;br /&gt;for pyver in 2.6 2.7 2.5; do&lt;br /&gt;    which python$pyver &amp;gt; /dev/null 2&amp;gt;&amp;1 &amp;&amp; exec python$pyver "$0" "$@"&lt;br /&gt;done&lt;br /&gt;echo "No appropriate python interpreter found." &amp;gt;&amp;2&lt;br /&gt;exit 1&lt;br /&gt;":"""&lt;br /&gt;&lt;br /&gt;import os, sys &lt;br /&gt;&lt;br /&gt;print os.path.dirname('/Hello/World/c.txt')&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./test.sh&lt;br /&gt;/Hello/World&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2220342002585471626?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2220342002585471626/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-run-python-in-shell-script.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2220342002585471626'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2220342002585471626'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-run-python-in-shell-script.html' title='[Level 3] Run python in shell script.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-9218333657410016849</id><published>2012-01-16T16:54:00.000+08:00</published><updated>2012-01-16T16:54:49.923+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cassandra'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Cassandra token generation tool by Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import sys &lt;br /&gt;if (len(sys.argv) &gt; 1): &lt;br /&gt;    num=int(sys.argv[1])&lt;br /&gt;else:&lt;br /&gt;    num=int(raw_input("How many nodes are in your cluster? "))&lt;br /&gt;for i in range(0, num):&lt;br /&gt;    print 'node %d: %d' % (i, (i*(2**127)/num))&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./cassandraTokenGenTools.py &lt;br /&gt;How many nodes are in your cluster? 5 &lt;br /&gt;node 0: 0&lt;br /&gt;node 1: 34028236692093846346337460743176821145&lt;br /&gt;node 2: 68056473384187692692674921486353642291&lt;br /&gt;node 3: 102084710076281539039012382229530463436&lt;br /&gt;node 4: 136112946768375385385349842972707284582&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-9218333657410016849?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/9218333657410016849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-cassandra-token-generation-tool.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9218333657410016849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9218333657410016849'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-cassandra-token-generation-tool.html' title='[Level 2] Cassandra token generation tool by Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3119057543796823737</id><published>2012-01-16T16:46:00.001+08:00</published><updated>2012-01-16T16:46:33.001+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSON'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] JSON module in Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import json&lt;br /&gt;import random&lt;br /&gt;&lt;br /&gt;data = {}&lt;br /&gt;for i in range(0,2):&lt;br /&gt;    key = 'i%s' % i &lt;br /&gt;    data[key] = {}&lt;br /&gt;    for j in range(0,3):&lt;br /&gt;        subkey = 'j%s' % j &lt;br /&gt;        data[key][subkey] = {}&lt;br /&gt;        for k in range(0,4):&lt;br /&gt;            item = 'k%s' % k &lt;br /&gt;            value = int(random.random() * 100)&lt;br /&gt;            data[key][subkey][item] = value&lt;br /&gt;print json.dumps(data)&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testPython.py &lt;br /&gt;{"i1": {"j0": {"k3": 93, "k2": 98, "k1": 0, "k0": 3}, "j1": {"k3": 53, "k2": 28, "k1": 99, "k0": 69}, "j2": {"k3": 3, "k2": 93, "k1": 74, "k0": 28}}, "i0": {"j0": {"k3": 67, "k2": 98, "k1": 15, "k0": 92}, "j1": {"k3": 70, "k2": 22, "k1": 63, "k0": 3}, "j2": {"k3": 88, "k2": 28, "k1": 30, "k0": 54}}}&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3119057543796823737?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3119057543796823737/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-json-module-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3119057543796823737'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3119057543796823737'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-json-module-in-python.html' title='[Level 2] JSON module in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3423747734119031299</id><published>2012-01-16T02:47:00.001+08:00</published><updated>2012-01-16T16:37:19.331+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><title type='text'>[Level 3] Add row count in select of MySQL.</title><content type='html'>&lt;pre class="prettyprint lang-html"&gt;mysql&amp;gt; set @row_count;&lt;br /&gt;mysql&amp;gt; select *, @row_count := @row_count + 1 as row_count from test;&lt;br /&gt;+------+---------+-----------+&lt;br /&gt;| id   | product | row_count |&lt;br /&gt;+------+---------+-----------+&lt;br /&gt;|    1 | cloth   |         1 |&lt;br /&gt;|    2 | shoes   |         2 |&lt;br /&gt;|    3 | paints  |         3 |&lt;br /&gt;+------+---------+-----------+&lt;br /&gt;10 rows in set (0.00 sec)&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3423747734119031299?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3423747734119031299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-add-row-count-in-select-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3423747734119031299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3423747734119031299'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-add-row-count-in-select-of.html' title='[Level 3] Add row count in select of MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2486098627620897872</id><published>2012-01-16T01:04:00.000+08:00</published><updated>2012-01-16T01:04:37.015+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Stored Functions'/><title type='text'>[Level 3] rw_ether_atob, rw_ether_btoa stored function in MySQL.</title><content type='html'>&lt;pre class="prettyprint lang-sql linenums:1"&gt;delimiter //&lt;br /&gt;&lt;br /&gt;drop function if exists rw_ether_atob//&lt;br /&gt;create function rw_ether_atob(sAscii char(17))&lt;br /&gt;returns bit(48)&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare bReturn bit(48);&lt;br /&gt;  ##set bReturn=conv(replace(sAscii,':',''),16,2); ## string output not bit&lt;br /&gt;  ##set bReturn=conv(replace(sAscii,':',''),16,10); ## not work&lt;br /&gt;  ##set bReturn=cast(replace(sAscii,':','') as bit(48)); ## syntax error&lt;br /&gt;  ##set bReturn=bin(replace(sAscii,':','')); ## syntax error&lt;br /&gt;  set bReturn=unhex(replace(sAscii,':',''));&lt;br /&gt;  return bReturn;&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;drop function if exists rw_ether_btoa//&lt;br /&gt;create function rw_ether_btoa(sBit bit(48))&lt;br /&gt;returns char(17)&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare sReturn char(17);&lt;br /&gt;  set sReturn=lpad(hex(sBit),12,'0');&lt;br /&gt;  set sReturn=concat_ws(':', substr(sReturn,1,2), substr(sReturn,3,2), substr(sReturn,5,2), substr(sReturn,7,2), substr(sReturn,9,2), substr(sReturn,11,2));&lt;br /&gt;  return sReturn;&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;mysql&gt; create table ether_table (b bit(48), a char(17), index(b), index(a));&lt;br /&gt;Query OK, 0 rows affected (0.67 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into ether_table values (rw_ether_atob('00:CD:EF:00:CD:EF'),'00:CD:EF:00:CD:EF'); &lt;br /&gt;Query OK, 1 row affected (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select rw_ether_btoa(b), a from ether_table&lt;br /&gt;    -&gt; where b=rw_ether_atob('00:CD:EF:00:CD:EF');&lt;br /&gt;+-------------------+-------------------+&lt;br /&gt;| rw_ether_btoa(b)  | a                 |&lt;br /&gt;+-------------------+-------------------+&lt;br /&gt;| 00:CD:EF:00:CD:EF | 00:CD:EF:00:CD:EF |&lt;br /&gt;+-------------------+-------------------+&lt;br /&gt;1 rows in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; explain select rw_ether_btoa(b), a from ether_table&lt;br /&gt;    -&gt; where b=rw_ether_atob('00:CD:EF:00:CD:EF');&lt;br /&gt;+----+-------------+-------------+------+---------------+------+---------+------+------+-------------+&lt;br /&gt;| id | select_type | table       | type | possible_keys | key  | key_len | ref  | rows | Extra       |&lt;br /&gt;+----+-------------+-------------+------+---------------+------+---------+------+------+-------------+&lt;br /&gt;|  1 | SIMPLE      | ether_table | ALL  | NULL          | NULL | NULL    | NULL | 1002 | Using where |&lt;br /&gt;+----+-------------+-------------+------+---------------+------+---------+------+------+-------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2486098627620897872?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2486098627620897872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-rwetheratob-rwetherbtoa-stored.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2486098627620897872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2486098627620897872'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-rwetheratob-rwetherbtoa-stored.html' title='[Level 3] rw_ether_atob, rw_ether_btoa stored function in MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8764111698394655549</id><published>2012-01-16T01:00:00.001+08:00</published><updated>2012-01-16T01:00:20.227+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Notes'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><title type='text'>[Level 1] Notes for MySQL. (config)</title><content type='html'>&lt;pre class="prettyprint lang-html"&gt;## take care with signature '???'&lt;br /&gt;&lt;br /&gt;[mysql]&lt;br /&gt;user=root&lt;br /&gt;password&lt;br /&gt;database=mysql&lt;br /&gt;#!include /etc/my.inc&lt;br /&gt;#prompt=\R:\m \d&amp;gt;&lt;br /&gt;#prompt=\u:\h \d&amp;gt;&lt;br /&gt;&lt;br /&gt;[mysqldump]&lt;br /&gt;&lt;br /&gt;[client]&lt;br /&gt;## new cert&lt;br /&gt;#ssl-key=/usr/local/mysql/newcerts/client-key.pem&lt;br /&gt;#ssl-cert=/usr/local/mysql/newcerts/client-cert.pem&lt;br /&gt;#ssl-ca=/usr/local/mysql/newcerts/ca-cert.pem&lt;br /&gt;user=root&lt;br /&gt;host=localhost&lt;br /&gt;protocol=tcp&lt;br /&gt;compress&lt;br /&gt;password&lt;br /&gt;&lt;br /&gt;######################################################[mysqld_multi]&lt;br /&gt;[mysqld_multi]&lt;br /&gt;server-id  = 0&lt;br /&gt;mysqld     = /usr/local/mysql/bin/mysqld_safe&lt;br /&gt;mysqladmin = /usr/local/mysql/bin/mysqladmin&lt;br /&gt;user       = multi_admin&lt;br /&gt;password   = my_password&lt;br /&gt;&lt;br /&gt;[mysqld2]&lt;br /&gt;socket     = /tmp/mysql.sock2&lt;br /&gt;port       = 3307&lt;br /&gt;pid-file   = /usr/local/mysql/data2/hostname.pid2&lt;br /&gt;datadir    = /usr/local/mysql/data2&lt;br /&gt;language   = /usr/local/mysql/share/mysql/english&lt;br /&gt;user       = unix_user1&lt;br /&gt;&lt;br /&gt;[mysqld3]&lt;br /&gt;mysqld     = /path/to/safe_mysqld/safe_mysqld&lt;br /&gt;ledir      = /path/to/mysqld-binary/&lt;br /&gt;mysqladmin = /path/to/mysqladmin/mysqladmin&lt;br /&gt;socket     = /tmp/mysql.sock3&lt;br /&gt;port       = 3308&lt;br /&gt;pid-file   = /usr/local/mysql/data3/hostname.pid3&lt;br /&gt;datadir    = /usr/local/mysql/data3&lt;br /&gt;language   = /usr/local/mysql/share/mysql/swedish&lt;br /&gt;user       = unix_user2&lt;br /&gt;&lt;br /&gt;[mysqld4]&lt;br /&gt;socket     = /tmp/mysql.sock4&lt;br /&gt;port       = 3309&lt;br /&gt;pid-file   = /usr/local/mysql/data4/hostname.pid4&lt;br /&gt;datadir    = /usr/local/mysql/data4&lt;br /&gt;language   = /usr/local/mysql/share/mysql/estonia&lt;br /&gt;user       = unix_user3&lt;br /&gt; &lt;br /&gt;[mysqld6]&lt;br /&gt;socket     = /tmp/mysql.sock6&lt;br /&gt;port       = 3311&lt;br /&gt;pid-file   = /usr/local/mysql/data6/hostname.pid6&lt;br /&gt;datadir    = /usr/local/mysql/data6&lt;br /&gt;language   = /usr/local/mysql/share/mysql/japanese&lt;br /&gt;user       = unix_user4&lt;br /&gt;######################################################[mysqld_multi]&lt;br /&gt;&lt;br /&gt;[mysqld]&lt;br /&gt;server-id=0&lt;br /&gt;basedir=/usr/local/mysql&lt;br /&gt;datadir=/Karajon/MySQLData # default $basedir/data&lt;br /&gt;skip-name-resolve&lt;br /&gt;&lt;br /&gt;## new cert&lt;br /&gt;#ssl-key=/usr/local/mysql/newcerts/server-key.pem&lt;br /&gt;#ssl-cert=/usr/local/mysql/newcerts/server-cert.pem&lt;br /&gt;#ssl-ca=/usr/local/mysql/newcerts/ca-cert.pem&lt;br /&gt;&lt;br /&gt;## ignore storage engine&lt;br /&gt;#skip-innodb&lt;br /&gt;#skip-myisam # cannot skip myisam&lt;br /&gt;#skip-memory  # skip memory is not working, but no error.&lt;br /&gt;#skip-blackhole&lt;br /&gt;#skip-archive&lt;br /&gt;#skip-mrg_myisam&lt;br /&gt;#skip-csv&lt;br /&gt;##skip-federated # no working, even enable federate.&lt;br /&gt;#default-storage-engine=InnoDB # work in 5.1.38&lt;br /&gt;&lt;br /&gt;################################################### enable federate&lt;br /&gt;federated &lt;br /&gt;&lt;br /&gt;################################################### setting log&lt;br /&gt;#log                       # default: off, on: log=$datadir/$hostname.log&lt;br /&gt;log-bin=/Karajon/bin-log/stanley-nb-bin                   # default: off, on: log-bin=$datadir/$hostname-bin&lt;br /&gt;binlog_format=row         # default: statement. BINLOG_FORMAT=[row|statement|mixed|default]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#max_binlog_cache_size=xxx # default: max_binlog_cache_size=18446744073709547520&lt;br /&gt;#max_binlog_size=xxx       # default: max_binlog_size=1073741824&lt;br /&gt;expire_logs_days=7 # default: expire_log_days=0 # never purge log files&lt;br /&gt;&lt;br /&gt;log-slow-queries  # default off, on: log-slow-queries=$datadir/$hostname-slow.log&lt;br /&gt;long-query-time=5 # default: long-query-time=10, mysql&amp;gt; set long_query_time=10;&lt;br /&gt;#log-error=/usr/local/mysql/data/Stanley-NB.err # default: $datadir/$hostname.err&lt;br /&gt;#log-output=file  # default: file, file/table/none&lt;br /&gt;#log-short-format # suppress the extra information&lt;br /&gt;#log-queries-not-using-indexes&lt;br /&gt;&lt;br /&gt;################################################### pid file&lt;br /&gt;#pid-file=/usr/local/mysql/data/Stanley-NB.pid # default: $datadir/$hostname.pid&lt;br /&gt;#socket=/tmp/mysql.sock&lt;br /&gt;&lt;br /&gt;################################################### transaction isolation level&lt;br /&gt;#transaction-isolation=READ-COMMIT&lt;br /&gt;&lt;br /&gt;################################################### connections&lt;br /&gt;thread_cache_size=0  # default: 0, no. of threads for reuse.&lt;br /&gt;max_connections=200  # default max_connection=100&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;################################################### MyISAM settings&lt;br /&gt;# modify MyISAM key cache, unit=K, M or G, &lt;br /&gt;# in mysql&amp;gt; set   global key_buffer_size=128*1024*1024&lt;br /&gt;#           set @@global.key_buffer_size=128*1024*1024&lt;br /&gt;key_buffer_size=128M            # default is 8M&lt;br /&gt;bulk_insert_buffer_size=4194304 # default is 8M&lt;br /&gt;&lt;br /&gt;################################################### InnoDB settings&lt;br /&gt;## set values&lt;br /&gt;#innodb_data_home_dir=/usr/local/mysql/data&lt;br /&gt;#innodb_data_file_path=innodata1:10M&lt;br /&gt;#innodb_data_file_path=innodata1:100M&lt;br /&gt;#innodb_data_file_path=innodata1:100M:autoextend&lt;br /&gt;#innodb_data_file_path=innodata1:100M:autoextend:max:500M&lt;br /&gt;#innodb_data_file_path=innodata1:100M;innodata2:100M:autoextend&lt;br /&gt;#innodb_log_file_size=50M&lt;br /&gt;#innodb_log_files_in_group=2&lt;br /&gt;innodb_buffer_pool_size=32M # default 8M&lt;br /&gt;innodb_log_buffer_size=8M   # default 1M&lt;br /&gt;&lt;br /&gt;## setting flag&lt;br /&gt;innodb_file_per_table &lt;br /&gt;#loose_innodb_file_per_table ## if you use install plugin statements to install the InnoDB plugin, prepend loose_ for each InnoDB option.&lt;br /&gt;&lt;br /&gt;################################################### skip engine&lt;br /&gt;#skip-InnoDB&lt;br /&gt;#skip-Memory&lt;br /&gt;&lt;br /&gt;#&lt;br /&gt;#transaction-isolation = READ-COMMITTED&lt;br /&gt;# set global transaction isolation level [isolation_level];&lt;br /&gt;# set session transaction isolation level [isoloation_level];&lt;br /&gt;&lt;br /&gt;default-storage-engine=MyISAM&lt;br /&gt;## select @@storage_engine;&lt;br /&gt;## set @@storage_engine=InnoDB; ## in mysql prompt&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;################################################### for MyISAM storage only&lt;br /&gt;myisam_data_pointer_size=7 ## default: 6&lt;br /&gt;&lt;br /&gt;################################################### for memory storage only&lt;br /&gt;#max_heap_table_size=16777216 ## default: max_heap_table_size=16777216, limit memory storage size&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;################################################### for unix only&lt;br /&gt;## window is case insensitive&lt;br /&gt;#lower_case_table_names=1&lt;br /&gt;&lt;br /&gt;################################################### buffer &amp; cache&lt;br /&gt;sort_buffer_size=2048000&lt;br /&gt;query_cache_size=8M ## default:0, sometimes fail why???&lt;br /&gt;#query-cache-type=on ## fail why???&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;####################################################### for window only&lt;br /&gt;#shared-memory&lt;br /&gt;#enable-named-pipe&lt;br /&gt;## set pipe name if enable named pipe.&lt;br /&gt;#socket='c:/s.socket'&lt;br /&gt;&lt;br /&gt;####################################################### for myisam auto-repair&lt;br /&gt;myisam-recover=FORCE,BACKUP # options: DEFAULT,BACKUP,FORCE,QUICK&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;####################################################### sql mode&lt;br /&gt;#sql_mode='no_auto_create_user' ## for user/security&lt;br /&gt;sql_mode='traditional'&lt;br /&gt;&lt;br /&gt;####################################################### network&lt;br /&gt;max_allowed_packet=128M ## default:1048576, will begin with net_buffer_length and increasing if necessarily.&lt;br /&gt;net_buffer_length=16384     ## default: 16384&lt;br /&gt;#bind-address=127.0.0.1      ## bind ip with loopback interface.&lt;br /&gt;#bind-address=172.31.255.100 ## bind ip with specific nic(172.31.255.100), to secure mysql on TCP/IP&lt;br /&gt;&lt;br /&gt;####################################################### table&lt;br /&gt;table_open_cache=64 # default: 64, no. of entries&lt;br /&gt;&lt;br /&gt;####################################################### special&lt;br /&gt;#skip_symbolic_links&lt;br /&gt;&lt;br /&gt;####################################################### replication&lt;br /&gt;## @master server, set bin log database&lt;br /&gt;#binlog-do-db=db1&lt;br /&gt;#binlog-do-db=db2&lt;br /&gt;#binlog-do-db=db3&lt;br /&gt;## @slaver server1, set replicated database&lt;br /&gt;#replicate-do-db=db1&lt;br /&gt;#replicate-do-db=db2&lt;br /&gt;## @slaver server2, set replicated database&lt;br /&gt;#replicate-do-db=db2&lt;br /&gt;#replicate-do-db=db3&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8764111698394655549?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8764111698394655549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-notes-for-mysql-config.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8764111698394655549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8764111698394655549'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-notes-for-mysql-config.html' title='[Level 1] Notes for MySQL. (config)'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8587249000131357813</id><published>2012-01-16T00:54:00.001+08:00</published><updated>2012-01-16T00:55:56.726+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Notes'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><title type='text'>[Level 1] Testing notes for MySQL. (mysql commands)</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash&lt;br /&gt;#ln -s /dev/null .mysql_history ## in my.cnf MYSQL_HISTFILE=/dev/null&lt;br /&gt;#export MYSQL_PS1="(\u@\h) [\d]&amp;gt; " ## mysql --prompt="(\u@\h) [\d]&amp;gt; "&lt;br /&gt;#mysql -u mysql mysql &amp;lt; ./test_mysql.sql&lt;br /&gt;#mysql -u root mysql &amp;lt; ./test_mysql.sql&lt;br /&gt;#mysql -u root --defaults-file=/etc/my.ini&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## mysqlslap, benchmark test&lt;br /&gt;# mysqlslap -auto-generate-sql # use default script&lt;br /&gt;mysqlslap -a -c100 i10 -u root -p --engine=InnoDB,MyISAM,MEMORY,ARCHIVE&lt;br /&gt;&lt;br /&gt;## mysqlcheck, for MyISAM, InnoDB, CSV and Archive.&lt;br /&gt;#mysqlcheck world;&lt;br /&gt;#mysqlcheck world City Country;&lt;br /&gt;#mysqlcheck --databases world test;&lt;br /&gt;#mysqlcheck --all-databases;&lt;br /&gt;&lt;br /&gt;## bin-log&lt;br /&gt;#mysqlbinlog bin.000001 bin.000002 | more&lt;br /&gt;#mysqlbinlog bin.000001 bin.000002 | mysql&lt;br /&gt;#mysqlbinlog --start-datetime="2009-01-01 00:00:00" --stop-datetime="2009-01-01 23:59:59" bin.000001 bin.000002 | mysql&lt;br /&gt;#mysqlbinlog --start-position=1001 --stop-position=1999 bin.000001 bin.000002 | mysql&lt;br /&gt;## purge binary logs&lt;br /&gt;#mysql&amp;gt; purge binary logs to 'mysql-bin.010'; # mysql-bin.010 will not be deleted.&lt;br /&gt;#mysql&amp;gt; purge binary logs before '2009-05-31 23:59:59';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## mysqlhotcopy, for MyISAM not for Innodb&lt;br /&gt;## perl script, need to install DBI module first&lt;br /&gt;#mysqlhotcopy world /var/archive&lt;br /&gt;#mysqlhotcoyp world./Country/ /var/archive&lt;br /&gt;&lt;br /&gt;mysql_multi&lt;br /&gt;mysql_multi --example # list example configuration&lt;br /&gt;&lt;br /&gt;## replication&lt;br /&gt;mysqldump --master-data=2 &lt;br /&gt;## option write to the dump file a comment&lt;br /&gt;## line containing the replication coordinates, &lt;br /&gt;## which can be used when setting up replication slaves.&lt;br /&gt;## That line has this format:&lt;br /&gt;## CHANGE MASTER TO MASTER_LOG_FILE='file_name', MASTER_LOG_POS=file_position;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8587249000131357813?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8587249000131357813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-testing-notes-for-mysql-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8587249000131357813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8587249000131357813'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-testing-notes-for-mysql-mysql.html' title='[Level 1] Testing notes for MySQL. (mysql commands)'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8206115378655489253</id><published>2012-01-16T00:51:00.002+08:00</published><updated>2012-01-16T00:55:30.693+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Notes'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><title type='text'>[Level 1] Testing notes for MySQL. (sql commands)</title><content type='html'>The following commands are my testing notes for MySQL.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;set sql_mode:='';&lt;br /&gt;&lt;br /&gt;-- set sql_mode='only_full_group_by'; -- with group by syntax, select columns must be included in group by list.&lt;br /&gt;set sql_mode='traditional';        -- a set of modes, fail sql transaction while datatype error or out of range.&lt;br /&gt;-- set sql_mode='pipes_as_concat';    -- set || from logic 'or' to string concatenation (standard sql).&lt;br /&gt;-- set sql_mode='ansi_quote';  -- ' for string, " for column name&lt;br /&gt;select @@sql_mode;&lt;br /&gt;-- set sql_mode='no_auto_create_user'; -- for not auto create user when grant, except grant with identified by.&lt;br /&gt;&lt;br /&gt;######################################### notes&lt;br /&gt;## select @@query_cache_type&lt;br /&gt;##        @@query_cache_size&lt;br /&gt;## show variable like 'query%';&lt;br /&gt;## show status like 'qcache%';&lt;br /&gt;## select sql_no_cache ...&lt;br /&gt;&lt;br /&gt;/* mysql client */&lt;br /&gt;/*&lt;br /&gt; \c to cancle mysql statement.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* command */&lt;br /&gt;/*&lt;br /&gt;show processlist;&lt;br /&gt;show full processlist;&lt;br /&gt;show databases;&lt;br /&gt;show tables;&lt;br /&gt;use mysql;&lt;br /&gt;show table status like 'user'&lt;br /&gt;show table status like '%user%';&lt;br /&gt;show full tables;&lt;br /&gt;show tables from information_schema;&lt;br /&gt;show columns from information_schema.character_sets;&lt;br /&gt;show character set;&lt;br /&gt;show global status;&lt;br /&gt;show create function/procedure func_name/proc_name;&lt;br /&gt;show function/procedure status;&lt;br /&gt;show function/procedure status like 'xxx';&lt;br /&gt;show function/procedure status where db='xxx' and name='yyy';&lt;br /&gt;show triggers;&lt;br /&gt;show collation; ## [like 'utf8%']&lt;br /&gt;&lt;br /&gt;show errors;&lt;br /&gt;select @@error_count;&lt;br /&gt;show count(*) errors;&lt;br /&gt;show warnings;&lt;br /&gt;select @@warning_count;&lt;br /&gt;show count(*) warnings;&lt;br /&gt;&lt;br /&gt;show variables;&lt;br /&gt;pager;               -- pager on, default command is /usr/bin/less -ins.&lt;br /&gt;pager /usr/bin/less -NJ10 ; -- show line no and jump 10 lines for once.&lt;br /&gt;pager /usr/bin/more; -- set paging by command /usr/bin/more&lt;br /&gt;nopager;             -- pager off.&lt;br /&gt;show variables like 'charset%';&lt;br /&gt;&lt;br /&gt;check table mysql.user;&lt;br /&gt;repair table mysql.user; &lt;br /&gt;-- repair table support with engine&lt;br /&gt;--   MyISAM&lt;br /&gt;-- no support with engine&lt;br /&gt;--   InnoDB, MEMORY&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* create if not exists */&lt;br /&gt;/*&lt;br /&gt;create database if not exists test;&lt;br /&gt;create table if not exists test (no int);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* special datatype */&lt;br /&gt;/*&lt;br /&gt;## enum max items: 65535&lt;br /&gt;-- drop database christy; create database christy;&lt;br /&gt;-- drop database if exists christy;&lt;br /&gt;create database if not exists christy;&lt;br /&gt;use christy;&lt;br /&gt;create table mon_enum (&lt;br /&gt;  Mon enum('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')&lt;br /&gt;);&lt;br /&gt;insert into mon_enum values (1),(2),(3),('ABC'),('May'),('JUN');&lt;br /&gt;select * from mon_enum;&lt;br /&gt;create table mon_set (&lt;br /&gt;  Mon set('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')&lt;br /&gt;);&lt;br /&gt;insert into mon_set values('Jan');&lt;br /&gt;insert into mon_set values(1),(2),(3),('ABC'),('May'),('JUN');&lt;br /&gt;insert into mon_set values('Jan,Feb');&lt;br /&gt;insert into mon_set values('Jan,Feb,Mar');&lt;br /&gt;insert into mon_set values('Jan,XYZ,Mar');&lt;br /&gt;insert into mon_set values('ABC');&lt;br /&gt;insert into mon_set values('Jan, Feb,Mar, Apr,May'); -- result =&amp;gt; 'Jan,Mar,May'&lt;br /&gt;select * from mon_set;&lt;br /&gt;&lt;br /&gt;## how many records can insert into testSetPK? if sql_mode is not strict_all_tables, strict_trans_tables&lt;br /&gt;## =&amp;gt; 4: '','a','b','a,b'&lt;br /&gt;create table testSetPK (&lt;br /&gt;  a set('a','b'),&lt;br /&gt;  primary key(a)&lt;br /&gt;) engine=MyISAM;&lt;br /&gt;insert into testSetPK values ('a'),('b');&lt;br /&gt;insert into testSetPK values ('b,a');&lt;br /&gt;insert into testSetPK values ('a,b'); # ERROR 1062 (23000): Duplicate entry 'a,b' for key 'PRIMARY'&lt;br /&gt;insert into testSetPK values ('ab'); # will insert empty '' into table.&lt;br /&gt;select * from testSetPK;&lt;br /&gt;# +-----+&lt;br /&gt;# | a   |&lt;br /&gt;# +-----+&lt;br /&gt;# |     | &lt;br /&gt;# | a   | &lt;br /&gt;# | b   | &lt;br /&gt;# | a,b | &lt;br /&gt;# +-----+&lt;br /&gt;# 4 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## how many records can insert into testEnumPK? if sql_mode is not strict_all_tables, strict_trans_tables&lt;br /&gt;## =&amp;gt; 3: '','a','b'&lt;br /&gt;create table testEnumPK (&lt;br /&gt;  a enum('a','b'),&lt;br /&gt;  primary key(a)&lt;br /&gt;) engine=MyISAM;&lt;br /&gt;insert into testEnumPK values ('a'),('b'); # enum=1,2&lt;br /&gt;insert into testEnumPK values ('abc'); # will insert empty '' into table. enum=0&lt;br /&gt;select * from testEnumPK;&lt;br /&gt;# +---+&lt;br /&gt;# | a |&lt;br /&gt;# +---+&lt;br /&gt;# |   | &lt;br /&gt;# | a | &lt;br /&gt;# | b | &lt;br /&gt;# +---+&lt;br /&gt;# 3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* normal datatype */&lt;br /&gt;/*&lt;br /&gt;-- drop database chantelle; create database chantelle;&lt;br /&gt;-- drop database if exists chantelle;&lt;br /&gt;create database if not exists chantelle;&lt;br /&gt;use chantelle;&lt;br /&gt;set sql_mode='traditional';&lt;br /&gt;&lt;br /&gt;-- auto_increment;&lt;br /&gt;create table abc (i int);&lt;br /&gt;insert into abc values (1),(2),(3),(4);&lt;br /&gt;&lt;br /&gt;create table xyz (i int auto_increment, primary key(i));&lt;br /&gt;insert into xyz values();&lt;br /&gt;select last_insert_id(); -- =&amp;gt; 1&lt;br /&gt;insert into xyz values();&lt;br /&gt;select last_insert_id(); -- =&amp;gt; 2&lt;br /&gt;insert into xyz values(),(),(),();&lt;br /&gt;select last_insert_id(); -- =&amp;gt; 3, not 6; get the first values generates for auto_increment.&lt;br /&gt;delete from xyz where i between 2 and 5;&lt;br /&gt;alter table xyz auto_increment=1;&lt;br /&gt;select auto_increment from information_schema.tables&lt;br /&gt;where table_schema='chantelle' and table_name='xyz'; -- =&amp;gt; 6&lt;br /&gt;delete from xyz where i &amp;gt;1;&lt;br /&gt;alter table xyz auto_increment=1;&lt;br /&gt;select auto_increment from information_schema.tables&lt;br /&gt;where table_schema='chantelle' and table_name='xyz'; -- =&amp;gt; 2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- for testing zero fill&lt;br /&gt;create table testZeroFill (&lt;br /&gt;  n int(5) zerofill&lt;br /&gt;);&lt;br /&gt;insert into testZeroFill values (1),(11),(111),(1111),(11111);&lt;br /&gt;insert into testZeroFill values (-1),(-11),(-111),(-1111),(-11111);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;create table integers (&lt;br /&gt;  n smallint unsigned&lt;br /&gt;);&lt;br /&gt;insert into integers values (-5);&lt;br /&gt;select * from integers;&lt;br /&gt;create table bits (&lt;br /&gt;  b bit(10)&lt;br /&gt;);&lt;br /&gt;insert into bits values (b'1'),(b'101'),(b'1000001');&lt;br /&gt;select * from bits;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* temporal data type */&lt;br /&gt;/*&lt;br /&gt;create database if not exists chantelle;&lt;br /&gt;use chantelle;&lt;br /&gt;-- set sql_mode='traditional';&lt;br /&gt;create table if not exists test_time (&lt;br /&gt;  z int,&lt;br /&gt;  a time,&lt;br /&gt;  b year,&lt;br /&gt;  c date,&lt;br /&gt;  d datetime,&lt;br /&gt;  e timestamp&lt;br /&gt;); &lt;br /&gt;&lt;br /&gt;insert into test_time(z) values (1);&lt;br /&gt;insert into test_time(a) values ('23:59:59');&lt;br /&gt;insert into test_time(b) values ('2008');&lt;br /&gt;insert into test_time(b) values ('09');&lt;br /&gt;insert into test_time(c) values ('2008-01-23');&lt;br /&gt;insert into test_time(a) values ('23:59:59');&lt;br /&gt;insert into test_time(d) values ('2008-01-23 23:59:59');&lt;br /&gt;insert into test_time(e) values (NULL);&lt;br /&gt;insert into test_time(d) values ('2008-01-23 23:59:59');&lt;br /&gt;insert into test_time(a) values ('24:61:61'); -- error then stop&lt;br /&gt;select * from test_time;&lt;br /&gt;&lt;br /&gt;insert into test_time(c) values ('0000-00-00');&lt;br /&gt;insert into test_time(c) values ('2008-02-31');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT DATE_ADD('2006-05-00',INTERVAL 1 DAY);&lt;br /&gt;-- datetime function:&lt;br /&gt;-- ref:&lt;br /&gt;--   http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/*************** mysql func() testing ***************/&lt;br /&gt;/* sys */&lt;br /&gt;/*&lt;br /&gt;select version();&lt;br /&gt;select database();&lt;br /&gt;select user(), charset(user()), collation(user());&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* date */&lt;br /&gt;/*&lt;br /&gt;select curdate(), current_date(), &lt;br /&gt;curtime(), current_time(),&lt;br /&gt;now(), current_timestamp();&lt;br /&gt;select concat(year(now()),'-',month(now()),'-',day(now()),' ',hour(now()),':',minute(now()),':',second(now()));&lt;br /&gt;&lt;br /&gt;select date_format(now(),get_format(datetime,'internal'));&lt;br /&gt;select date_format(now(),get_format(datetime,'eur'));&lt;br /&gt;select date_format(now(),'%Y-%m-%d %H.%i.%s');&lt;br /&gt;select date_format('2003-10-03 23:59:59',get_format(datetime,'eur'));&lt;br /&gt;select str_to_date(now(),get_format(datetime,'iso')), str_to_date(date_format(now(),get_format(datetime,'eur')),get_format(datetime,'eur'));&lt;br /&gt;select str_to_date('10.31.2003',get_format(date,'usa'));&lt;br /&gt;&lt;br /&gt;select makedate(2008,200), maketime(8,6,20);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* null */&lt;br /&gt;/*&lt;br /&gt;select isnull(null), isnull(0), isnull(1), isnull('');&lt;br /&gt;select ifnull(null,'is null'), ifnull(null,'is null');&lt;br /&gt;select concat('a','b'), concat('a',null,'b');&lt;br /&gt;select if(null,'true','false'), if(isnull(null),'true','false');&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* math */&lt;br /&gt;/*&lt;br /&gt;select truncate(1/7,9), 1/7, round(1/7,4), truncate(1/7,4), ceiling(1/7), floor(1/7), abs(-1/7);&lt;br /&gt;select sign(1/7), sign(-1/7), sign(0);&lt;br /&gt;select sin(0), cos(0), tan(0);&lt;br /&gt;select pi(), degrees(pi()), radians(180);&lt;br /&gt;create table test_std (&lt;br /&gt;  no int;&lt;br /&gt;);&lt;br /&gt;insert into t1 values (1),(2),(3);&lt;br /&gt;select std(c1) from test_std;&lt;br /&gt;&lt;br /&gt;## use with bulkInsert user defined function.&lt;br /&gt;#A-Z, char(65)-char(90),&lt;br /&gt;#a-z, char(97)-char(122),&lt;br /&gt;truncate table t1;&lt;br /&gt;truncate table t2;&lt;br /&gt;call bulkInsert('t1','char(floor(rand()*26)+65),ceiling(rand()*27)',100);&lt;br /&gt;call bulkInsert('t2','char(floor(rand()*26)+96),ceiling(rand()*27)',100);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* others */&lt;br /&gt;/*&lt;br /&gt;select repeat('*',20);&lt;br /&gt;select least(1,3,-2,4,6,0), least('de','abc','x','a','yz','ghi');&lt;br /&gt;select greatest(1,3,-2,4,6,0), greatest('de','abc','x','a','yz','ghi');&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* flow control */&lt;br /&gt;/*&lt;br /&gt;select if(1&amp;gt;0,'yes','no');&lt;br /&gt;select interval(5,2,3,7,8,3,2,0); -- ans. 2 =&amp;gt; 7&amp;gt;5, then return the index of '3' (2);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* string */&lt;br /&gt;/*&lt;br /&gt;select instr('Alice and Bob', 'and'), locate('and', 'Alice and Bob'), position('and' in 'Alice and Bob');&lt;br /&gt;select length('MySQL'), char_length('MySQL');&lt;br /&gt;select length(convert('MySQL' using ucs2)), char_length(convert('MySQL' using ucs2));&lt;br /&gt;select concat('to','see','is','to','believe');&lt;br /&gt;select concat_ws(' ','to','see','is','to','believe');&lt;br /&gt;select substring('George and Mary',0), substring('George and Mary',1), substring('George and Mary',8,3);&lt;br /&gt;select substring('George and Mary',-4), substring('George and Mary',-8,3);&lt;br /&gt;select substring_index('George and Mary','and',1), substring_index('George and Mary','and',0), substring_index('George and Mary','and',-1);&lt;br /&gt;select substring_index('a b c d e',' ',1);  -- a&lt;br /&gt;select substring_index('a b c d e',' ',2);  -- a b&lt;br /&gt;select substring_index('a b c d e',' ',3);  -- a b c&lt;br /&gt;select substring_index('a b c d e',' ',-1); -- e&lt;br /&gt;select substring_index('a b c d e',' ',-2); -- d e&lt;br /&gt;select substring_index('a b c d e',' ',-3); -- c d e&lt;br /&gt;select left('George and Mary',6), right('George and Mary',4);&lt;br /&gt;select concat('&amp;lt;',trim(' and '),'&amp;gt;'), concat('&amp;lt;',ltrim(' and '),'&amp;gt;'), concat('&amp;lt;',rtrim(' and '),'&amp;gt;');&lt;br /&gt;select trim(leading '0' from '01');&lt;br /&gt;select replace('01', '0', '');&lt;br /&gt;select insert('2359', 3, 0, ':'), insert('23____59', 3, 4, ':'); -- insert before posi 3, and 0 chars to be replaced; insert before posi 3, and 4 chars to be replaced.&lt;br /&gt;select strcmp('abc','def'), strcmp('def','def'), strcmp('ghi','def');&lt;br /&gt;select 'abc'='def', 'def'='def', 'ghi'='def';&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/*************** mysql func() testing ***************/&lt;br /&gt;&lt;br /&gt;/* &lt;br /&gt;-- drop database test; create database test;&lt;br /&gt;-- drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table test (&lt;br /&gt;  c nchar(10) default null,&lt;br /&gt;  a int default null&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;-- drop database joseph; create database joseph;&lt;br /&gt;-- drop database if exists joseph;&lt;br /&gt;create database if not exists joseph;&lt;br /&gt;use joseph;&lt;br /&gt;create table test (&lt;br /&gt;  c nchar(10) default null,&lt;br /&gt;  a int default null&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;insert into test.test values ('a',1);&lt;br /&gt;insert into test.test values ('a',2);&lt;br /&gt;insert into test.test values ('b',3);&lt;br /&gt;insert into test.test values ('b',7);&lt;br /&gt;insert into test.test values ('b',8);&lt;br /&gt;insert into test.test values ('c',9);&lt;br /&gt;insert into test.test values ('c',1);&lt;br /&gt;insert into test.test values ('c',1);&lt;br /&gt;insert into test.test values (NULL,NULL), (null,null);&lt;br /&gt;select * from test.test;&lt;br /&gt;&lt;br /&gt;insert into joseph.test values ('a',1);&lt;br /&gt;insert into joseph.test values ('a',3);&lt;br /&gt;insert into joseph.test values ('b',5);&lt;br /&gt;insert into joseph.test values ('b',7);&lt;br /&gt;insert into joseph.test values ('c',2);&lt;br /&gt;insert into joseph.test values ('c',4);&lt;br /&gt;insert into joseph.test values ('d',7);&lt;br /&gt;insert into joseph.test values ('d',7);&lt;br /&gt;insert into test.test values (NULL,NULL), (null,null);&lt;br /&gt;select * from joseph.test;&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;  *&lt;br /&gt;from&lt;br /&gt;  test.test s,&lt;br /&gt;  joseph.test  j&lt;br /&gt;where s.a=j.a&lt;br /&gt;order by 1&lt;br /&gt;limit 0,5;&lt;br /&gt;## limit not support sub-query or vairable.&lt;br /&gt;##   mysql &amp;gt; select * from t limit ( select count(*) from t where i='a' );&lt;br /&gt;##   mysql &amp;gt;&lt;br /&gt;##   mysql &amp;gt; set @a=1;&lt;br /&gt;##   mysql &amp;gt; select * from t limt @a;&lt;br /&gt; &lt;br /&gt;select distinct&lt;br /&gt;  *&lt;br /&gt;from &lt;br /&gt;  test.test s,&lt;br /&gt;  joseph.test  j&lt;br /&gt;where s.a=j.a&lt;br /&gt;order by 1&lt;br /&gt;limit 0,5;&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;  c, a, count(1) -- count(1), psedo column with value 1; count(a) will lost count if the value of a is null.&lt;br /&gt;from test&lt;br /&gt;where 1=1&lt;br /&gt;  and c is not null&lt;br /&gt;  and a is not null&lt;br /&gt;group by c,a&lt;br /&gt;with rollup;&lt;br /&gt;&lt;br /&gt;create database if not exists test;&lt;br /&gt;create table test.fromTable (ino int);&lt;br /&gt;insert into test.fromTable values (1),(2),(3);&lt;br /&gt;create table test.toTable as select * from test.fromTable;&lt;br /&gt;truncate table test.fromTable;&lt;br /&gt;select * from test.fromTable;&lt;br /&gt;insert into test.fromTable select * from test.toTable;&lt;br /&gt;select * from test.fromTable;&lt;br /&gt;select * from test.toTable;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* create database */&lt;br /&gt;/*&lt;br /&gt;create database test;&lt;br /&gt;create database if exists test;&lt;br /&gt;drop database test;&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database Inno2 character set UTF8 collate UTF8_bin;&lt;br /&gt;&lt;br /&gt;## test drop database fail...&lt;br /&gt;create database dropDBFail;&lt;br /&gt;system pfexec su - mysql -c "touch /usr/local/mysql/data/dropDBFail/dropDBFail.txt";&lt;br /&gt;drop database dropDBFail;&lt;br /&gt;show errors;&lt;br /&gt;show databases like 'dropDBFail';&lt;br /&gt;system pfexec su - mysql -c "rm usr/local/mysql/data/dropDBFail/dropDBFail.txt";&lt;br /&gt;drop database dropDBFail;&lt;br /&gt;show databases like 'dropDBFail';&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* create table */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;&lt;br /&gt;-- enable MyISAM table to store checksum value, &lt;br /&gt;-- to let "mysql&amp;gt; checksum table table_name;" to be faster.&lt;br /&gt;-- Otherwise, it needs to do a full table scan to checksum table.&lt;br /&gt;create table checkSumTable ( no int )&lt;br /&gt;engine=MyISAM checksum=1;&lt;br /&gt;&lt;br /&gt;-- temporary table&lt;br /&gt;create temporary table tmpTable ( no int ); # visible only on current session and will be dropped when connection is closed.&lt;br /&gt;drop temporary table tmpTable;&lt;br /&gt;&lt;br /&gt;drop table if exists student;&lt;br /&gt;create table student (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  name varchar(32) unique,&lt;br /&gt;  chi int not null,&lt;br /&gt;  eng int not null,&lt;br /&gt;  math int not null,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;insert into student (name,chi,eng,math) values ('Tom',100,100,100);&lt;br /&gt;insert into student values (10,'Mary',90,90,90);&lt;br /&gt;insert into student (name,chi,eng,math) values ('John',80,80,80);&lt;br /&gt;insert into student values (5,'christy',70,70,70);&lt;br /&gt;insert into student (name,chi,eng,math) values ('Mike',60,60,60);&lt;br /&gt;select * from student;&lt;br /&gt;delete from student where id = 12;&lt;br /&gt;insert into student (name,chi,eng,math) values ('David',50,50,50);&lt;br /&gt;select * from student;&lt;br /&gt;&lt;br /&gt;create table selectStudent as select * from student; -- create table with default engine, and also insert data.&lt;br /&gt;create table likeStudent like student;               -- create table with the same engine.&lt;br /&gt;alter table selectStudent add column location varchar(32) default 'Yilan' comment 'The location of students';&lt;br /&gt;select * from selectStudent;&lt;br /&gt;alter table selectStudent change location loc varchar(48); -- change column name and datatype.&lt;br /&gt;alter table selectStudent modify loc varchar(32); -- change column datatype.&lt;br /&gt;select * from selectStudent;&lt;br /&gt;alter table selectStudent drop column loc;&lt;br /&gt;&lt;br /&gt;alter table selectStudent rename to renameStudent;&lt;br /&gt;rename table renameStudent to selectStudent;&lt;br /&gt;rename table selectStudent to s, likeStudent to l;&lt;br /&gt;select * from s,l;&lt;br /&gt;&lt;br /&gt;-- eliminate duplicated data with create table as select&lt;br /&gt;create table abc (i int);&lt;br /&gt;insert into abc values (1),(2),(2),(3),(3),(3),(NULL),(NULL),(NULL),(NULL);&lt;br /&gt;select * from abc;&lt;br /&gt;create table cba&lt;br /&gt;as select distinct * from abc;&lt;br /&gt;drop table abc;&lt;br /&gt;rename table cba to abc;&lt;br /&gt;&lt;br /&gt;-- row format, for MyISAM engine&lt;br /&gt;use test;&lt;br /&gt;&lt;br /&gt;# create dynamic row &lt;br /&gt;create table dynamicRow(id int, name varchar(32)) engine=MyISAM row_format=dynamic;&lt;br /&gt;call bulkInsert('dynamicRow','rand()*100,repeat("a",rand()*32)',100);&lt;br /&gt;show table status like 'dynamicRow';&lt;br /&gt;&lt;br /&gt;# create fixed row &lt;br /&gt;create table fixedRow(id int, name varchar(32)) engine=MyISAM row_format=fixed;&lt;br /&gt;insert into fixedRow select * from dynamicRow;&lt;br /&gt;show table status like 'fixedRow';&lt;br /&gt;&lt;br /&gt;# create compressed table for dynamic row&lt;br /&gt;create table compressedDynamicRow(id int, name varchar(32)) engine=MyISAM row_format=dynamic;&lt;br /&gt;insert into compressedDynamicRow select * from dynamicRow;&lt;br /&gt;system pfexec myisampack $MySQLDataDir/test/compressedDynamicRow;&lt;br /&gt;system pfexec myisamchk -rq $MySQLDataDir/test/compressedDynamicRow;&lt;br /&gt;&lt;br /&gt;# create compressed table for fixed row&lt;br /&gt;create table compressedFixedRow(id int, name varchar(32)) engine=MyISAM row_format=fixed;&lt;br /&gt;insert into compressedFixedRow select * from dynamicRow;&lt;br /&gt;system pfexec myisampack $MySQLDataDir/test/compressedFixedRow;&lt;br /&gt;system pfexec myisamchk -rq $MySQLDataDir/test/compressedFixedRow;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* primary key */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;&lt;br /&gt;create table t1 (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  no int,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;create table t2 (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  no int&lt;br /&gt;);&lt;br /&gt;alter table t2 add primary key (id);&lt;br /&gt;&lt;br /&gt;-- how to modify primary key: a. drop old one; b. create new one;&lt;br /&gt;-- drop primary key: alter table table_name drop primary key;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;insert into t1 (no) values (1),(2),(3);&lt;br /&gt;insert into t2 (no) values (1),(2),(3);&lt;br /&gt;&lt;br /&gt;explain t1\G&lt;br /&gt;desc t1\G&lt;br /&gt;explain t2\G&lt;br /&gt;desc t2\G&lt;br /&gt;explain select * from t1 where id=1;&lt;br /&gt;desc select * from t1 where id=1;&lt;br /&gt;explain select * from t1 where no=1;&lt;br /&gt;desc select * from t1 where no=1;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* foreign key */&lt;br /&gt;/*&lt;br /&gt;mysql&amp;gt; set foreign_key_checks=0; -- It's useful while need to manage data and ignore constraints.&lt;br /&gt;mysql&amp;gt; set unique_checks=0; -- It's useful while need to enhance performance to load mass data. -- unique check =&amp;gt; check constraints row by row.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysql&amp;gt; create table a(id int) engine=innodb;&lt;br /&gt;Query OK, 0 rows affected (0.11 sec)&lt;br /&gt;&lt;br /&gt;mysql&amp;gt; create table b(id int, p int, foreign key(p) a(id)) engine=innodb;&lt;br /&gt;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a(id)) engine=innodb' at line 1&lt;br /&gt;mysql&amp;gt; create table b(id int, p int) engine=innodb;&lt;br /&gt;Query OK, 0 rows affected (0.10 sec)&lt;br /&gt;&lt;br /&gt;mysql&amp;gt; alter table b add foreign key(p) references a(id);&lt;br /&gt;ERROR 1005 (HY000): Can't create table 'test.#sql-5f3_3' (errno: 150)&lt;br /&gt;mysql&amp;gt; show errors;&lt;br /&gt;+-------+------+---------------------------------------------------+&lt;br /&gt;| Level | Code | Message                                           |&lt;br /&gt;+-------+------+---------------------------------------------------+&lt;br /&gt;| Error | 1005 | Can't create table 'test.#sql-5f3_3' (errno: 150) |&lt;br /&gt;+-------+------+---------------------------------------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;=&amp;gt; 150, source column must be indexed!&lt;br /&gt;&lt;br /&gt;mysql&amp;gt; alter table a add key(id);&lt;br /&gt;Query OK, 0 rows affected (0.10 sec)&lt;br /&gt;Records: 0  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;mysql&amp;gt; alter table b add foreign key(p) references a(id);&lt;br /&gt;Query OK, 0 rows affected (0.13 sec)&lt;br /&gt;Records: 0  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt; */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;&lt;br /&gt;create table country (&lt;br /&gt;  code int not null auto_increment,&lt;br /&gt;  name varchar(32) not null,&lt;br /&gt;  sname char(2) not null,&lt;br /&gt;  primary key (code)&lt;br /&gt;) engine=InnoDB; -- InnoDB implement the foreign key.&lt;br /&gt;&lt;br /&gt;create table nPop (&lt;br /&gt;  pop int not null,&lt;br /&gt;  primary key (pop)&lt;br /&gt;) engine=InnoDB; -- InnoDB implement the foreign key.&lt;br /&gt;&lt;br /&gt;create table sCityName (&lt;br /&gt;  no int not null auto_increment,&lt;br /&gt;  name varchar(32) unique,&lt;br /&gt;  primary key (no)&lt;br /&gt;) engine=InnoDB;&lt;br /&gt;&lt;br /&gt;create table city (&lt;br /&gt;  id int not null auto_increment,&lt;br /&gt;  name varchar(32) not null,&lt;br /&gt;  cc int not null,&lt;br /&gt;  pop int default 0,&lt;br /&gt;  primary key (id),&lt;br /&gt;  foreign key (name)&lt;br /&gt;    references sCityName (name)&lt;br /&gt;    on delete no action,&lt;br /&gt;  foreign key (cc)&lt;br /&gt;    references country (code)&lt;br /&gt;    on delete cascade,&lt;br /&gt;  foreign key (pop)&lt;br /&gt;    references nPop (pop)&lt;br /&gt;    on delete set null&lt;br /&gt;) engine=InnoDB; -- InnoDB implement the foreign key.&lt;br /&gt;&lt;br /&gt;-- how to modify foreign key: a. drop old one; b. create new on;&lt;br /&gt;-- drop foreign key: alter table table_name drop foreign key foreign_key_name;&lt;br /&gt;&lt;br /&gt;insert into country values \&lt;br /&gt; (null, 'Taiwan', 'TW') \&lt;br /&gt;,(null, 'Japan', 'JP') \&lt;br /&gt;,(null, 'China', 'CN') \&lt;br /&gt;,(null, 'America', 'US') \&lt;br /&gt;,(null, 'England', 'UK') \&lt;br /&gt;,(null, 'French', 'FR');&lt;br /&gt;&lt;br /&gt;insert into nPop values \&lt;br /&gt;(100),(200),(300),(400),(500),(600);&lt;br /&gt;&lt;br /&gt;insert into sCityName (name) \&lt;br /&gt;values('Taipei'),('Tokyo'),('NewYork'),('Tainan'),('Washington'),('Paris');&lt;br /&gt;&lt;br /&gt;insert into city values (null, 'Taipei', 1, 200);&lt;br /&gt;insert into city values (null, 'Tokyo', 2, 400);&lt;br /&gt;insert into city values (null, 'NewYork', 4, 600);&lt;br /&gt;insert into city values (null, 'Tainan', 10, 200); // out of country code&lt;br /&gt;insert into city values (null, 'Washington', 20, 800); // out of country code, nPop&lt;br /&gt;insert into city values (null, 'Paris', 6, 1000); //out of country code, nPop,&lt;br /&gt;&lt;br /&gt;select * from country;&lt;br /&gt;select * from nPop;&lt;br /&gt;select * from city;&lt;br /&gt;&lt;br /&gt;delete from country where name='Taiwan';&lt;br /&gt;delete from nPop where pop=400;&lt;br /&gt;delete from sCityName where name='NewYork';&lt;br /&gt;&lt;br /&gt;select * from country;&lt;br /&gt;select * from nPop;&lt;br /&gt;select * from city;&lt;br /&gt;&lt;br /&gt;truncate table nPop;&lt;br /&gt;select * from country;&lt;br /&gt;select * from nPop;&lt;br /&gt;select * from city;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* delete */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table delTable (&lt;br /&gt;  no int&lt;br /&gt;);&lt;br /&gt;insert into delTable values (1),(1),(2),(2),(3),(3),(4),(4);&lt;br /&gt;select * from delTable;&lt;br /&gt;delete from delTable where no=1 limit 1; -- delete from delTable order by no limit 1;&lt;br /&gt;delete from delTable where no=2 limit 1;&lt;br /&gt;delete from delTable where no=3 limit 1;&lt;br /&gt;delete from delTable where no=4 limit 1; -- delete from delTable order by no desc limit 1;&lt;br /&gt;select * from delTable;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* update */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table people (&lt;br /&gt;  id int not null,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  age int,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;insert into people values (2,'Victor',21),(3,'Susan',15),(4,'Victor',31);&lt;br /&gt;select * from people;&lt;br /&gt;update people set id=id-1;                  -- success.&lt;br /&gt;select * from people;&lt;br /&gt;update people set id=id+1;                  -- fail, when 1+1=2, 2 already exists, pk constraint error.&lt;br /&gt;select * from people;&lt;br /&gt;update people set id=id+1 order by id desc; -- success.&lt;br /&gt;select * from people;&lt;br /&gt;&lt;br /&gt;## update multi-table&lt;br /&gt;use test;&lt;br /&gt;drop table if exists t1,t2;&lt;br /&gt;create table t1(n varchar(32),i int);&lt;br /&gt;create table t2(n varchar(32),i int);&lt;br /&gt;insert into t1 values('a',2);&lt;br /&gt;insert into t1 values('b',4);&lt;br /&gt;insert into t1 values('c',6);&lt;br /&gt;insert into t2 values('a',7);&lt;br /&gt;insert into t2 values('b',8);&lt;br /&gt;insert into t2 values('d',9);&lt;br /&gt;#&lt;br /&gt;update t1 inner join t2 on t1.n=t2.n set t1.i=1, t2.i=1 where t1.n='a';&lt;br /&gt;# update t1 inner join t2 using(n) set t1.i=1, t2.i=1 where t1.n='a'; # the same&lt;br /&gt;select * from t1;&lt;br /&gt;select * from t2;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* replace */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table people (&lt;br /&gt;  id int not null,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  age int,&lt;br /&gt;  count int default 1,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;insert into people (id,name,age) values (2,'Victor',21),(3,'Susan',15),(4,'Victor',31);&lt;br /&gt;select * from people;&lt;br /&gt;replace into people (id,name,age) values (2,'V2',25);&lt;br /&gt;select * from people;&lt;br /&gt;replace into people (id,name,age) values (5,'V3',28);&lt;br /&gt;select * from people;&lt;br /&gt;create table people2 as select * from people;&lt;br /&gt;update people2 set id=id+10;&lt;br /&gt;replace into people select * from people2;&lt;br /&gt;&lt;br /&gt;insert into people (id,name,age) values (2,'V2',25) on duplicate key update count=count+1;&lt;br /&gt;insert into people (id,name,age) values (2,'V2',25) on duplicate key update count=count+1;&lt;br /&gt;insert into people (id,name,age) values (2,'V2',25) on duplicate key update count=count+1;&lt;br /&gt;insert into people (id,name,age) values (2,'V2',25) on duplicate key update count=count+1;&lt;br /&gt;&lt;br /&gt;select * from people;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* union */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;create table test_union1 (&lt;br /&gt;  id int increment,&lt;br /&gt;  no in&lt;br /&gt;);&lt;br /&gt;create table test_union2 (&lt;br /&gt;  id int increment,&lt;br /&gt;  no in&lt;br /&gt;);&lt;br /&gt;insert into test_union(no) values (1),(1),(2),(3),(4),(4),(5),(6),(7),(8),(9);&lt;br /&gt;insert into test_union(no) values (2),(3),(8),(1),(4),(4),(5),(0),(0),(0),(0);&lt;br /&gt;select * from t1 union selecct * from t2;&lt;br /&gt;select * from t1 unionall selecct * from t2;&lt;br /&gt;select * from t1 minus select * from t2; -- not supported&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* transaction */&lt;br /&gt;/*&lt;br /&gt;-- save point&lt;br /&gt;set @@autocommit=0;&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database test;&lt;br /&gt;use test;&lt;br /&gt;create table a (&lt;br /&gt;  no int &lt;br /&gt;) engine=InnoDB;&lt;br /&gt;&lt;br /&gt;start transaction;&lt;br /&gt;  insert into a values (1);&lt;br /&gt;  select * from a;&lt;br /&gt;  savepoint s1;&lt;br /&gt;&lt;br /&gt;  insert into a values (2);&lt;br /&gt;  select * from a;&lt;br /&gt;  savepoint s2;&lt;br /&gt;&lt;br /&gt;  insert into a values (3);&lt;br /&gt;  select * from a;&lt;br /&gt;  savepoint s3;&lt;br /&gt;&lt;br /&gt;  rollback to savepoint s2;&lt;br /&gt;  select * from a;&lt;br /&gt;&lt;br /&gt;  rollback;&lt;br /&gt;  select * from a;&lt;br /&gt;commit;&lt;br /&gt;&lt;br /&gt;-- transaction&lt;br /&gt;create table people (&lt;br /&gt;  id int not null,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  age int,&lt;br /&gt;  count int default 1,&lt;br /&gt;  primary key (id)&lt;br /&gt;) engine=InnoDB;&lt;br /&gt;&lt;br /&gt;---- show engines information.&lt;br /&gt;show engines;&lt;br /&gt;create database if not exits test_engine;&lt;br /&gt;use test_engine;&lt;br /&gt;create table t1 (&lt;br /&gt;  id int&lt;br /&gt;) engine=MEMORY;&lt;br /&gt;create table t2 (&lt;br /&gt;  id int&lt;br /&gt;);&lt;br /&gt;create temporary table t3 (&lt;br /&gt;  id int&lt;br /&gt;) engine=MEMORY;&lt;br /&gt;create temporary table t4 (&lt;br /&gt;  id int&lt;br /&gt;);&lt;br /&gt;insert into t1 values (1),(2),(3);&lt;br /&gt;insert into t2 values (1),(2),(3);&lt;br /&gt;insert into t3 values (1),(2),(3);&lt;br /&gt;insert into t4 values (1),(2),(3);&lt;br /&gt;&lt;br /&gt;---- set current autocommit off.&lt;br /&gt;set autocommit = off;&lt;br /&gt;set session autocommit = off;&lt;br /&gt;set @@autocommit := 0;&lt;br /&gt;&lt;br /&gt;---- start mysqld with default autocommit off.&lt;br /&gt;---try ...&lt;br /&gt;-- shell&amp;gt;mysqld -u root init-connect="set autocommit := off"&lt;br /&gt;-- or modify my.conf ( not work for root )&lt;br /&gt;&lt;br /&gt;insert into people (id,name,age) values (1,'Tom',10);&lt;br /&gt;select * from people;&lt;br /&gt;rollback;&lt;br /&gt;select * from people;&lt;br /&gt;&lt;br /&gt;start transaction;&lt;br /&gt;insert into people (id,name,age) values (2,'Victor',21),(3,'Susan',15),(4,'Victor',31);&lt;br /&gt;select * from people;&lt;br /&gt;rollback;&lt;br /&gt;select * from people;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* join */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table t1 (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  no int,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;create table t2 (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  no int,&lt;br /&gt;  addr varchar(32),&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;insert into t1 (no, name) values (1,'Tom'),(2,'Joseph'),(3,'Chantelle'),(4,'Christy');&lt;br /&gt;insert into t2 (no, addr) values (1,'Taipei'),(2,'Taizhong'),(3,'Yilan'),(5,'Tainan');&lt;br /&gt;&lt;br /&gt;-- caresian product.&lt;br /&gt;select * from t1,t2;&lt;br /&gt;select * from t1 cross join t2;&lt;br /&gt;&lt;br /&gt;-- inner join.&lt;br /&gt;select * from t1 join t2 on t1.no=t2.no;&lt;br /&gt;select * from t1 inner join t2 using (no);&lt;br /&gt;select * from t1,t2 where ( select no from t2 where t1.no=t2.no ) = ( select no from t1 where t2.no=t1.no);&lt;br /&gt;select * from t1 inner join t2 on t1.no &amp;lt; t2.no;&lt;br /&gt;select * from t1 inner join t2 on t1.id between t1.no and t2.no;&lt;br /&gt;&lt;br /&gt;-- outer join.&lt;br /&gt;select * from t1 left join t2 on t1.no=t2.no;  -- major in left (must show left list), and join from right.&lt;br /&gt;select * from t1 left outer join t2 on t1.no=t2.no;  -- major in left (must show left list), and join from right.&lt;br /&gt;select * from t1 right join t2 on t1.no=t2.no; -- major in right (must show right list), and join from left.&lt;br /&gt;select * from t1 right outer join t2 on t1.no=t2.no; -- major in right (must show right list), and join from left.&lt;br /&gt;&lt;br /&gt;-- joins in update and delete statements.&lt;br /&gt;update t1&lt;br /&gt;inner join t2&lt;br /&gt;on t1.no = t2.no&lt;br /&gt;set t1.id=t1.id+10,&lt;br /&gt;    t2.id=t2.id+100; -- can update t2, so rare!&lt;br /&gt;&lt;br /&gt;select * from t1;&lt;br /&gt;select * from t2;&lt;br /&gt;select * from t1 join t2 using (no);&lt;br /&gt;&lt;br /&gt;select * from t1 where exists (select null from t2 where t1.no=t2.no);&lt;br /&gt;select * from t1 where t1.no in (select no from t2);&lt;br /&gt;select * from t1 where t1.no = any (select no from t2);&lt;br /&gt;select * from t1 where t1.no = some (select no from t2);&lt;br /&gt;&lt;br /&gt;## test natural join&lt;br /&gt;drop table if exists i,j,k;&lt;br /&gt;create table t1(i int,j int,k int);&lt;br /&gt;create table t2(j int,k int,l int);&lt;br /&gt;insert into t1 values (1,2,3),(1,2,4);&lt;br /&gt;insert into t2 values (2,3,7),(2,8,9);&lt;br /&gt;select * from t1 natural join t2;&lt;br /&gt;# =&amp;gt; select * from t1 inner join t2 using(j,k);&lt;br /&gt;# =&amp;gt; select j, k, i, l from t1, t2 where t1.j=t2.j and t1.k=t2.k; &lt;br /&gt;# result:&lt;br /&gt;# +------+------+------+------+&lt;br /&gt;# | j    | k    | i    | l    |&lt;br /&gt;# +------+------+------+------+&lt;br /&gt;# |    2 |    3 |    1 |    7 |&lt;br /&gt;# +------+------+------+------+&lt;br /&gt;# 1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;## test cross join&lt;br /&gt;select * from t1 cross join t2;&lt;br /&gt;# result: &lt;br /&gt;# +------+------+------+------+------+------+&lt;br /&gt;# | i    | j    | k    | j    | k    | l    |&lt;br /&gt;# +------+------+------+------+------+------+&lt;br /&gt;# |    1 |    2 |    3 |    2 |    3 |    7 | &lt;br /&gt;# |    1 |    2 |    4 |    2 |    3 |    7 | &lt;br /&gt;# |    1 |    2 |    3 |    2 |    8 |    9 | &lt;br /&gt;# |    1 |    2 |    4 |    2 |    8 |    9 | &lt;br /&gt;# +------+------+------+------+------+------+&lt;br /&gt;# 4 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* view */&lt;br /&gt;/*&lt;br /&gt;-- cannot link trigger on view.&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table city (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  pop int,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;create table cityMayer (&lt;br /&gt;  cityName varchar(32),&lt;br /&gt;  mayerName varchar(32),&lt;br /&gt;  primary key (cityName)&lt;br /&gt;);&lt;br /&gt;insert into city (name, pop) values ('Taipei',300);&lt;br /&gt;insert into city (name, pop) values ('Tainan',200);&lt;br /&gt;insert into city (name, pop) values ('Yilan',100);&lt;br /&gt;insert into cityMayer values ('Taipei','John');&lt;br /&gt;insert into cityMayer values ('Tainan','Mary');&lt;br /&gt;insert into cityMayer values ('Taizhong','Tom');&lt;br /&gt;&lt;br /&gt;-- create view.&lt;br /&gt;create or replace view cityView (city, mayer, pop) as&lt;br /&gt;select name, mayerName, pop&lt;br /&gt;from city, cityMayer&lt;br /&gt;where 1=1&lt;br /&gt;  and city.name=cityMayer.cityName&lt;br /&gt;  and pop &amp;gt; 100&lt;br /&gt;with check option;&lt;br /&gt;&lt;br /&gt;-- select view.&lt;br /&gt;select * from cityView;&lt;br /&gt;&lt;br /&gt;---- update view.&lt;br /&gt;-- update cityView&lt;br /&gt;-- set city='TaipeiCity'&lt;br /&gt;-- where city='Taipei';&lt;br /&gt;update cityView&lt;br /&gt;set pop=10;&lt;br /&gt;select * from city; -- update fail with check option.&lt;br /&gt;update cityView&lt;br /&gt;set pop=1000;&lt;br /&gt;select * from city; -- success.&lt;br /&gt;&lt;br /&gt;-- but how to create readonly view?????, grant read pri to user.&lt;br /&gt;&lt;br /&gt;select * from cityMayer;&lt;br /&gt;select * from cityView;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## test view with create/replace.&lt;br /&gt;create view v as select * from m; # table m exists&lt;br /&gt;drop table m;&lt;br /&gt;show create view v;                     # view exist&lt;br /&gt;create or replace v as select * from n; # table n exists&lt;br /&gt;create or replace v as select * from t; # table t doesnot exist&lt;br /&gt;show create view v;                     # view exist with old syntax&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## with cascaded/local check option;&lt;br /&gt;drop table if exists testCheckOption;&lt;br /&gt;create table testCheckOption( t int );&lt;br /&gt;create or replace view v1 as select * from testCheckOption where t&amp;lt;10;&lt;br /&gt;create or replace view v2 as select * from v1 where t&amp;gt;0 with cascaded check option;&lt;br /&gt;create or replace view v3 as select * from v1 where t&amp;gt;0 with local check option;&lt;br /&gt;insert into v1 values(10); # success&lt;br /&gt;insert into v2 values(20); # fail, even v1 doesnot have check option, v2 will cascaded checking v1 where cause.&lt;br /&gt;insert into v3 values(30); # success&lt;br /&gt;select * from testCheckOption;&lt;br /&gt;select * from v1;&lt;br /&gt;select * from v2;&lt;br /&gt;select * from v3;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## priv&lt;br /&gt;drop table if exists testViewPriv;&lt;br /&gt;create table testViewPriv( n int );&lt;br /&gt;create definer='christy'@'localhost' sql security definer view v_testViewPriv as select * from testViewPriv;&lt;br /&gt;grant update on stanley.testViewPriv to 'christy'@'localhost';&lt;br /&gt;grant update on stanley.v_testViewPriv to 'chantelle'@'localhost';&lt;br /&gt;insert into testViewPriv values (1),(2),(3);&lt;br /&gt;&lt;br /&gt;drop table if exists testViewPriv2;&lt;br /&gt;create table testViewPriv2( n int );&lt;br /&gt;create sql security invoker view v_testViewPriv2 as select * from testViewPriv2;&lt;br /&gt;grant update on stanley.testViewPriv2 to 'chantelle'@'localhost';&lt;br /&gt;grant update on stanley.v_testViewPriv2 to 'chantelle'@'localhost';&lt;br /&gt;insert into testViewPriv2 values (1),(2),(3);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* prepare statement */&lt;br /&gt;/*&lt;br /&gt;-- prepare statement is session base.&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table city (&lt;br /&gt;  pop int&lt;br /&gt;);&lt;br /&gt;insert into city values (100),(200),(300),(400),(500);&lt;br /&gt;&lt;br /&gt;prepare my_stmt from 'select * from city where pop &amp;gt; ?';&lt;br /&gt;set @pop=200;&lt;br /&gt;execute my_stmt using @pop;&lt;br /&gt;deallocate prepare my_stmt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* export/import file */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table t (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  no int,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;insert into t (no) values (1), (2), (3), (4), (5), (6);&lt;br /&gt;select * from test.t;&lt;br /&gt;select * into outfile '/tmp/data/t.txt'&lt;br /&gt;fields&lt;br /&gt;  terminated by ','&lt;br /&gt;  enclosed by '"'&lt;br /&gt;  lines terminated by '\n'&lt;br /&gt;from test.t; -- default in /opt/mysql/mysql/data, if file exists then error return, how to overwrite it?????, no solution.... &lt;br /&gt;&lt;br /&gt;truncate table t;&lt;br /&gt;load data infile '/tmp/data/t.txt'&lt;br /&gt;into table t&lt;br /&gt;fields&lt;br /&gt;  terminated by ','&lt;br /&gt;  enclosed by '"'&lt;br /&gt;  lines terminated by '\n';&lt;br /&gt;select * from t;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;shell&amp;gt;&lt;br /&gt;mysqldump -uroot test   &amp;gt; /tmp/mysql/data/test.sql&lt;br /&gt;mysqldump -uroot test t &amp;gt; /tmp/mysql/data/test.t.sql&lt;br /&gt;mysqldump -d -uroot test t &amp;gt; /tmp/mysql/data/test.t.schema_only.sql&lt;br /&gt;mysql -u root &amp;lt; /tmp/mysql/data/test.sql&lt;br /&gt;mysql -u root &amp;lt; /tmp/mysql/data/test.t.sql&lt;br /&gt;&lt;br /&gt;shell&amp;gt;&lt;br /&gt;mysql -u root &amp;lt;&amp;lt;EOF&lt;br /&gt;truncate table test.t;&lt;br /&gt;EOF&lt;br /&gt;mysqlimport --fields-terminated-by=, --fields-enclosed-by='"' \&lt;br /&gt;            --lines-terminated-by="\n" --ignore \&lt;br /&gt;            test /tmp/data/t.txt &lt;br /&gt;## '--ignore/--replace' contain unique key values already in the table, 'test' is database name, 't' is the tablename.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* stored routines */&lt;br /&gt;/*&lt;br /&gt;## change stored routine characteristics, (3 characters)&lt;br /&gt;## 1. SQL SECURITY:&lt;br /&gt;##    alter procedure p sql security [definer/invoker];&lt;br /&gt;## 2. Data Use:&lt;br /&gt;##    alter procedure p [contains sql/no sql/reads sql data/modifies sql data];&lt;br /&gt;## 3. COMMENT:&lt;br /&gt;##    alter procedure p comment 'This is comment...'&lt;br /&gt;##&lt;br /&gt;## create sample:&lt;br /&gt;delimiter //&lt;br /&gt;## cannot use the syntax: create procedure if not exists p()..., will fail!&lt;br /&gt;drop procedure if exists p//&lt;br /&gt;create procedure p()&lt;br /&gt;no sql&lt;br /&gt;sql security invoker&lt;br /&gt;comment 'hello'&lt;br /&gt;begin&lt;br /&gt;  select 'NULL';&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* pattern of delimiter. */&lt;br /&gt;/*&lt;br /&gt;delimiter //&lt;br /&gt;create procedure/function ...&lt;br /&gt;begin&lt;br /&gt;  ...&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;delimiter ;&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table t1 (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  no int,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;create table t2 (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  no int,&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;insert into t1 (no) values (1),(2),(2);&lt;br /&gt;insert into t2 (no) values (1),(1),(2),(2),(3),(3);&lt;br /&gt;&lt;br /&gt;delimiter //&lt;br /&gt;create procedure test_t_count(out nReturn int, inout nIO int, in no2 int)&lt;br /&gt;begin&lt;br /&gt;  select @nSes, nReturn, nIO, @no2 as no1;&lt;br /&gt;  if no2 = 1&lt;br /&gt;  then&lt;br /&gt;    select count(1) from test.t1;&lt;br /&gt;  elseif no2 = 2&lt;br /&gt;  then&lt;br /&gt;    select count(1) from test.t2;&lt;br /&gt;  else&lt;br /&gt;    select 'not match any case';&lt;br /&gt;  end if;&lt;br /&gt;  set @nSes=4, nReturn=5, nIO=6, no2=33;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;-- test for update data with cursor&lt;br /&gt;drop procedure if exists t;&lt;br /&gt;delimiter //&lt;br /&gt;create procedure t()&lt;br /&gt;begin&lt;br /&gt;  declare done1 int default 0;&lt;br /&gt;  declare fet int default 0;&lt;br /&gt;  declare c cursor for select * from test.n;&lt;br /&gt;  declare continue handler for not found set done1=1;&lt;br /&gt;  open c;&lt;br /&gt;  lr:repeat&lt;br /&gt;    fetch c into fet;&lt;br /&gt;    if not done1 then&lt;br /&gt;      update test.n set n=fet+10 where n=fet;&lt;br /&gt;    end if;&lt;br /&gt;  until done1 end repeat;&lt;br /&gt;  close c;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;drop procedure t;&lt;br /&gt;&lt;br /&gt;-- test for use procedure to delete function/procedure, create succ, but call fail...&lt;br /&gt;drop procedure if exists t;&lt;br /&gt;delimiter //&lt;br /&gt;drop procedure if exists t;&lt;br /&gt;create procedure t()&lt;br /&gt;begin&lt;br /&gt;  declare done1 int default 0;&lt;br /&gt;  declare db1 varchar(32) default '';&lt;br /&gt;  declare name1 varchar(32) default '';&lt;br /&gt;  declare type1 varchar(32) default '';&lt;br /&gt;  declare c cursor for select db,name,type from mysql.proc;&lt;br /&gt;  declare continue handler for not found set done1=1;&lt;br /&gt;  set @cmd2=''; -- must put after declare.&lt;br /&gt;  open c;&lt;br /&gt;  lr:repeat&lt;br /&gt;    fetch c into db1,name1,type1;&lt;br /&gt;    if not done1 then&lt;br /&gt;      select concat('drop ',type1,' ',db1,'.',name1) into @cmd2;&lt;br /&gt;      prepare my_stmt from @cmd2; -- drop function/procedure not support prepare statement yet.&lt;br /&gt;      execute my_stmt; -- prepare fail, so never reach this line&lt;br /&gt;    end if;&lt;br /&gt;  until done1 end repeat;&lt;br /&gt;  close c;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;call t();&lt;br /&gt;drop procedure t;&lt;br /&gt;&lt;br /&gt;## call bulkInsert('m','1,1,1',0);            # unlimited insert&lt;br /&gt;## call bulkInsert('m','1,1,1',100);          # insert 100 recoreds&lt;br /&gt;## call bulkInsert('m','NULL,NULL,NULL',100); # insert 100 recoreds for all NULL&lt;br /&gt;## call bulkInsert('test_partition_np','NULL,NULL,date_add(\'1995-01-01\', interval ceiling(rand()*5843) day)',1000000); ## sample&lt;br /&gt;&lt;br /&gt;delimiter //&lt;br /&gt;drop procedure if exists bulkInsert//&lt;br /&gt;CREATE PROCEDURE bulkInsert(in sTableName varchar(32), in sValues varchar(256), in nCounts int)&lt;br /&gt;begin&lt;br /&gt;  declare i int default 0;&lt;br /&gt;  #declare null_not_allowed condition for sqlstate '23000';&lt;br /&gt;  #declare null_not_allowed condition for 1048;&lt;br /&gt;  #declare continue handler for null_not_allowed begin end;&lt;br /&gt;  #declare continue handler for sqlstate '23000' begin end;&lt;br /&gt;  #declare continue handler for 1048 begin end;&lt;br /&gt;&lt;br /&gt;  #set @sPrepare='';&lt;br /&gt;  select concat('insert into ',sTableName,' values(',sValues,')') into @sPrepare;&lt;br /&gt;  #select @sPrepare;&lt;br /&gt;  prepare sCmd from @sPrepare;&lt;br /&gt;  repeat&lt;br /&gt;    execute sCmd;&lt;br /&gt;    set i=i+1;&lt;br /&gt;    -- select i as counter;&lt;br /&gt;  until i=nCounts end repeat;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;## call bulkInsert2('m','id',0,0);            # unlimited insert&lt;br /&gt;## call bulkInsert2('m','id',1,100);          # insert 100 recoreds, begin from 1&lt;br /&gt;delimiter //&lt;br /&gt;drop procedure if exists bulkInsert2//&lt;br /&gt;CREATE PROCEDURE bulkInsert2(in sTableName varchar(32), in sColumn varchar(256), in nBegin int, in nCounts int)&lt;br /&gt;begin&lt;br /&gt;  declare i int default 0; &lt;br /&gt;  #declare null_not_allowed condition for sqlstate '23000';&lt;br /&gt;  #declare null_not_allowed condition for 1048;&lt;br /&gt;  #declare continue handler for null_not_allowed begin end;&lt;br /&gt;  #declare continue handler for sqlstate '23000' begin end;&lt;br /&gt;  #declare continue handler for 1048 begin end;&lt;br /&gt;&lt;br /&gt;  foo:loop&lt;br /&gt;    if i&amp;gt;=nCounts then&lt;br /&gt;      leave foo;&lt;br /&gt;    else&lt;br /&gt;      set @sPrepare='';&lt;br /&gt;      select concat('insert into ',sTableName,'(',sColumn,') values(',nBegin,')') into @sPrepare;&lt;br /&gt;      prepare sCmd from @sPrepare;&lt;br /&gt;      execute sCmd;&lt;br /&gt;      set i=i+1;&lt;br /&gt;      set nBegin=nBegin+1;&lt;br /&gt;      -- select i as counter;&lt;br /&gt;    end if;&lt;br /&gt;  end loop;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## test recursive procedure&lt;br /&gt;## mysql&amp;gt; set @@max_sp_recursion_depth=1000;&lt;br /&gt;## mysql&amp;gt; set @maxLoop=100;&lt;br /&gt;## mysql&amp;gt; call recursivePorcedure(@maxLoop);&lt;br /&gt;delimiter //&lt;br /&gt;drop procedure if exists recursiveProcedure;&lt;br /&gt;create procedure recursiveProcedure(inout n int)&lt;br /&gt;begin&lt;br /&gt;  #select 'a' into @a;&lt;br /&gt;  ## select * from t;            # can select&lt;br /&gt;  ## call t();                   # can call another procedure&lt;br /&gt;  ## call recursiveProcedure(n); # can call resursive procedure, but have to set @@max_sp_recursion_depth first, default=0&lt;br /&gt;.&lt;br /&gt;&lt;br /&gt;  select n;&lt;br /&gt;  set n=n-1;&lt;br /&gt;&lt;br /&gt;  if n &amp;gt; 0 then&lt;br /&gt;    call recursiveProcedure(n);&lt;br /&gt;  end if;&lt;br /&gt;&lt;br /&gt;  #if n=0 then&lt;br /&gt;  # return; #exit; #quit; #leave; ## not working, how to quit procedure??????&lt;br /&gt;  #end if;&lt;br /&gt;  #&lt;br /&gt;  #The generic way to exit a block is the LEAVE statement:&lt;br /&gt;  #create procedure myproc()&lt;br /&gt;  #MAIN_BLOCK: begin&lt;br /&gt;  #  declare v_panic bool default false&lt;br /&gt;  #  ..&lt;br /&gt;  #  ..&lt;br /&gt;  #  if v_panic then&lt;br /&gt;  #    leave MAIN_BLOCK;&lt;br /&gt;  #  end if;&lt;br /&gt;  #  ..&lt;br /&gt;  #  ..&lt;br /&gt;  #end MAIN_BLOCK;   &lt;br /&gt;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;show create procedure test.test_t_count;&lt;br /&gt;show procedure status;&lt;br /&gt;show procedure status where Db='test';&lt;br /&gt;&lt;br /&gt;drop procedure if exists test_t_count; &lt;br /&gt;&lt;br /&gt;set @nSes=1, @nReturn=2, @nIO=3, @no1=11, @no2=22;&lt;br /&gt;select @nSes, @nReturn, @nIO, @no1, @no2;&lt;br /&gt;call test_t_count(@nReturn, @nIO, @no1);&lt;br /&gt;select @nSes, @nReturn, @nIO, @no1, @no2;&lt;br /&gt;&lt;br /&gt;delimiter //&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;create function table_count(column_no int)&lt;br /&gt;returns int&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare nReturn int default 0;&lt;br /&gt;  declare nCount1 int default 0;&lt;br /&gt;  declare nCount2 int default 0;&lt;br /&gt;&lt;br /&gt;  if column_no = 1&lt;br /&gt;  then&lt;br /&gt;    select count(distinct id) into nCount1 from t1;&lt;br /&gt;    select count(distinct id) into nCount2 from t2;&lt;br /&gt;  elseif column_no = 2&lt;br /&gt;  then&lt;br /&gt;    select count(distinct no) into nCount1 from t1;&lt;br /&gt;    select count(distinct no) into nCount2 from t2;&lt;br /&gt;  else&lt;br /&gt;    set nCount1=0;&lt;br /&gt;    set nCount2=0;&lt;br /&gt;  end if;&lt;br /&gt;&lt;br /&gt;  set nReturn=nCount1+nCount2;&lt;br /&gt;  set @nT=nReturn;&lt;br /&gt;  return @nT;&lt;br /&gt;  -- return nCount1+nCount2;&lt;br /&gt;  -- return nReturn;&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;## function can call function, insert/update/delete table&lt;br /&gt;## when use binlog, have to declare the function modify data or not, (use "NO SQL") or set global log_bin_trust_function_creators=1 (default 0)&lt;br /&gt;delimiter //&lt;br /&gt;drop function if exists upTable//&lt;br /&gt;create function upTable()&lt;br /&gt;returns int&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  insert into m values (2);&lt;br /&gt;  return 0;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;delimiter //&lt;br /&gt;drop function if exists seTable//&lt;br /&gt;create function seTable()&lt;br /&gt;returns int&lt;br /&gt;no sql&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare nReturn int default 0;&lt;br /&gt;  select count(1) into nReturn from m;&lt;br /&gt;  return nReturn;&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;create function seTable(i int) ## create fail, function name exist!&lt;br /&gt;returns int&lt;br /&gt;no sql&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare nReturn int default 0;&lt;br /&gt;  select count(1) into nReturn from m;&lt;br /&gt;  return nReturn;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;delimiter //&lt;br /&gt;drop function if exists t;&lt;br /&gt;create function t()&lt;br /&gt;returns int&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  set @n=1; -- set @n&lt;br /&gt;  return 2;&lt;br /&gt;  set @m=3; -- never reach here.&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;set @nT=0;&lt;br /&gt;select table_count(3);&lt;br /&gt;select table_count(2);&lt;br /&gt;select table_count(1);&lt;br /&gt;select @nT;&lt;br /&gt;set @nT=null;&lt;br /&gt;&lt;br /&gt;show create function test.table_count;&lt;br /&gt;show function status;&lt;br /&gt;show function status where Db='test';&lt;br /&gt;&lt;br /&gt;drop function if exists table_count; &lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* flow control */&lt;br /&gt;/*&lt;br /&gt;delimiter ;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* if */&lt;br /&gt;/*&lt;br /&gt;&lt;br /&gt;## select if&lt;br /&gt;select if(i=0,0,1) from m;&lt;br /&gt;&lt;br /&gt;drop function if exists testIF;&lt;br /&gt;delimiter //&lt;br /&gt;create function testIF(n int)&lt;br /&gt;returns varchar(32)&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  if n=1&lt;br /&gt;  then&lt;br /&gt;    return 'true';&lt;br /&gt;  else&lt;br /&gt;    return 'false';&lt;br /&gt;  end if;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;select testIF(0);&lt;br /&gt;select testIF(1);&lt;br /&gt;drop function testIF;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* case */&lt;br /&gt;/*&lt;br /&gt;## select case...&lt;br /&gt;select&lt;br /&gt;case month when "01" then "January"&lt;br /&gt;when "02" then "February"&lt;br /&gt;when "03" then "March"&lt;br /&gt;when "04" then "April"&lt;br /&gt;when "05" then "May"&lt;br /&gt;when "06" then "June"&lt;br /&gt;when "07" then "July"&lt;br /&gt;when "08" then "August"&lt;br /&gt;when "09" then "September"&lt;br /&gt;when "10" then "October"&lt;br /&gt;when "11" then "November"&lt;br /&gt;when "12" then "December"&lt;br /&gt;end # not 'end case' here, when use select case ...&lt;br /&gt;from calendar where year = "2005" order by month;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;drop function if exists testCase;&lt;br /&gt;delimiter //&lt;br /&gt;create function testCase1(n int)&lt;br /&gt;returns varchar(32)&lt;br /&gt;no sql&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  case n&lt;br /&gt;  when 1 then&lt;br /&gt;    return '1';&lt;br /&gt;  when 2 then&lt;br /&gt;    return '2';&lt;br /&gt;  else&lt;br /&gt;    return 'no match';&lt;br /&gt;  end case;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;select testCase1(1);&lt;br /&gt;select testCase1(2);&lt;br /&gt;select testCase1(3);&lt;br /&gt;drop function testCase1;&lt;br /&gt;&lt;br /&gt;drop function if exists testCase2;&lt;br /&gt;delimiter //&lt;br /&gt;create function testCase2(n int)&lt;br /&gt;returns varchar(32)&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  case&lt;br /&gt;  when n = 1 then&lt;br /&gt;    return '1';&lt;br /&gt;  when n = 2  then&lt;br /&gt;    return '2';&lt;br /&gt;  else&lt;br /&gt;    return 'not match';&lt;br /&gt;  end case;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;select testCase2(1);&lt;br /&gt;select testCase2(2);&lt;br /&gt;select testCase2(3);&lt;br /&gt;drop function testCase2;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* repeat */&lt;br /&gt;/*&lt;br /&gt;drop function if exists testRepeat;&lt;br /&gt;delimiter //&lt;br /&gt;create function testRepeat(n int)&lt;br /&gt;returns int&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare nCount1 int default 0;&lt;br /&gt;  declare nCount2 int default 0;&lt;br /&gt;  repeat&lt;br /&gt;    set nCount1 = nCount1 + 1;&lt;br /&gt;    set nCount2 = nCount1 * nCount1;&lt;br /&gt;  -- until nCount1 &amp;gt;= n -- cannot left ';' here.&lt;br /&gt;  -- end repeat;&lt;br /&gt;  until nCount1 &amp;gt;= n end repeat; -- best practice.&lt;br /&gt;  return nCount2;&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;delimiter ;&lt;br /&gt;select testRepeat(1);&lt;br /&gt;select testRepeat(2);&lt;br /&gt;select testRepeat(3);&lt;br /&gt;drop function testRepeat;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* while */&lt;br /&gt;/*&lt;br /&gt;drop function if exists testWhile;&lt;br /&gt;delimiter //&lt;br /&gt;create function testWhile(n int)&lt;br /&gt;returns int&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare nCount int default 1;&lt;br /&gt;  while nCount &amp;lt; n&lt;br /&gt;  do&lt;br /&gt;    set nCount = nCount + 1;&lt;br /&gt;  end while;&lt;br /&gt;  return nCount;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;select testWhile(1);&lt;br /&gt;select testWhile(2);&lt;br /&gt;select testWhile(3);&lt;br /&gt;drop function testWhile;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* loop */&lt;br /&gt;/*&lt;br /&gt;drop function if exists testLoop;&lt;br /&gt;delimiter //&lt;br /&gt;create function testLoop(n int)&lt;br /&gt;returns int&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  declare nCount int default 1;&lt;br /&gt;  -- loop usually within label, and use leave label to exit loop.&lt;br /&gt;  mylabel:loop&lt;br /&gt;    if nCount &amp;gt;= n&lt;br /&gt;    then&lt;br /&gt;      leave mylabel;&lt;br /&gt;    else&lt;br /&gt;      set nCount=nCount+1;&lt;br /&gt;      iterate mylabel;&lt;br /&gt;    end if;&lt;br /&gt;    -- never reach here...&lt;br /&gt;    set nCount=1000;&lt;br /&gt;  end loop mylabel;&lt;br /&gt;  return nCount;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;select testLoop(1);&lt;br /&gt;select testLoop(2);&lt;br /&gt;select testLoop(3);&lt;br /&gt;drop function testLoop;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* condition &amp; handler */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database test;&lt;br /&gt;use test;&lt;br /&gt;create table d_table (&lt;br /&gt;  n int,&lt;br /&gt;  primary key (n)&lt;br /&gt;);&lt;br /&gt;delimiter //&lt;br /&gt;create procedure dohandler(in n int, out x int)&lt;br /&gt;begin&lt;br /&gt;  declare nCount int default 1;                         -- variable and condition declaration must before cursor and handler.&lt;br /&gt;  declare dup_keys condition for sqlstate '23000';      -- variable and condition declaration must before cursor and handler.&lt;br /&gt;  -- declare c cursor for select * from test.testCursor1; -- must declare before handler -- sample only&lt;br /&gt;  -- declare continue handler for not found set done=1; -- sample only&lt;br /&gt;  declare continue handler for dup_keys set @garbage=1; -- declare handler for contidion.&lt;br /&gt;  truncate table test.d_table;&lt;br /&gt;  set @garbage=0;&lt;br /&gt;  while nCount &amp;lt;= n&lt;br /&gt;  do&lt;br /&gt;    set x = nCount;&lt;br /&gt;    insert into test.d_table values (1);&lt;br /&gt;    set nCount = nCount + 1;&lt;br /&gt;  end while;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;call dohandler(1,@x);&lt;br /&gt;select @garbage, @x;&lt;br /&gt;call dohandler(2,@x);&lt;br /&gt;select @garbage, @x;&lt;br /&gt;call dohandler(3,@x);&lt;br /&gt;select @garbage, @x;&lt;br /&gt;drop procedure dohandler;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* cursor */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database test;&lt;br /&gt;use test;&lt;br /&gt;create table test.testCursor1 (&lt;br /&gt;  no int&lt;br /&gt;);&lt;br /&gt;create table test.testCursor2 like test.testCursor1;&lt;br /&gt;insert into test.testCursor1 values (1),(2),(3),(4),(5);&lt;br /&gt;delimiter //&lt;br /&gt;&lt;br /&gt;## test cursor scope.&lt;br /&gt;drop procedure if exists testCursorScope//&lt;br /&gt;create procedure testCursorScope()&lt;br /&gt;begin&lt;br /&gt;  begin&lt;br /&gt;    declare dup_key condition for sqlstate '23000';&lt;br /&gt;    declare c cursor for select * from test.m;&lt;br /&gt;    declare continue handler for dup_key set @x=1;&lt;br /&gt;    open c;&lt;br /&gt;  end;&lt;br /&gt;  begin&lt;br /&gt;    declare n int default 0;&lt;br /&gt;    fetch c into n;&lt;br /&gt;  end;&lt;br /&gt;end//&lt;br /&gt;## result::&lt;br /&gt;#mysql&amp;gt; source /tmp/t.sql&lt;br /&gt;#Query OK, 0 rows affected, 1 warning (0.00 sec)&lt;br /&gt;#ERROR 1324 (42000): Undefined CURSOR: c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## test cursor scope2.&lt;br /&gt;## nothing to see, because open cursor not lock table? it's rare...&lt;br /&gt;drop procedure if exists testCursorScope2//&lt;br /&gt;create procedure testCursorScope2()&lt;br /&gt;begin&lt;br /&gt;  begin&lt;br /&gt;    declare i int default 0;&lt;br /&gt;    declare j int default 0;&lt;br /&gt;    declare not_null_allowed condition for sqlstate '23000';&lt;br /&gt;    declare c cursor for select * from test.m;&lt;br /&gt;    declare d cursor for select * from test.n;&lt;br /&gt;    declare continue handler for not_null_allowed set @x=1;&lt;br /&gt;&lt;br /&gt;    ## case 1:&lt;br /&gt;    open c;&lt;br /&gt;    fetch c into i;&lt;br /&gt;    open d;&lt;br /&gt;    fetch d into j;&lt;br /&gt;    select "case 1:";&lt;br /&gt;    select "use following command to check table status:";&lt;br /&gt;    select "  show open tables;";&lt;br /&gt;    select "  flush tables;";&lt;br /&gt;    select "  show open tables;";&lt;br /&gt;    select sleep(20);&lt;br /&gt;&lt;br /&gt;    ## case 2:&lt;br /&gt;    close c;&lt;br /&gt;    select "case 2:";&lt;br /&gt;    select "use following command to check table status:";&lt;br /&gt;    select "  flush tables;";&lt;br /&gt;    select "  show open tables;";&lt;br /&gt;    select sleep(20);&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;  ## case 3:&lt;br /&gt;  select "case 3:";&lt;br /&gt;  select "use following command to check table status:";&lt;br /&gt;  select "  flush tables;";&lt;br /&gt;  select "  show open tables;";&lt;br /&gt;  select sleep(20);&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;## test cursor insensitive&lt;br /&gt;## steps:&lt;br /&gt;## 1. create procedure testCursorInsensitive.&lt;br /&gt;##    &amp;gt; copy and paste with following procedure.&lt;br /&gt;## 2. create table m with values 1,2,3.&lt;br /&gt;##    &amp;gt; create table m (i int); insert into m values(1),(2),(3); select * from m; # =&amp;gt; 1,2,3&lt;br /&gt;## 3. call procedure testCursorInsensitive.&lt;br /&gt;##    &amp;gt; call testCursorInsensitive();&lt;br /&gt;## 4. open another session and modify data.&lt;br /&gt;##    &amp;gt; insert into m values(7); delete from m where i=2; update m set i=0 where i=1; select * from m; # =&amp;gt; 0,3,7&lt;br /&gt;## 5. wait the procedure return.&lt;br /&gt;##    =&amp;gt; 1,2,3&lt;br /&gt;## Result:&lt;br /&gt;##    The cursor does not see the change after the cursor is opened.&lt;br /&gt;&lt;br /&gt;delimiter // &lt;br /&gt;drop procedure if exists testCursorInsensitive//&lt;br /&gt;create procedure testCursorInsensitive()&lt;br /&gt;begin&lt;br /&gt;  declare v int default NULL;&lt;br /&gt;  declare done int default 0;&lt;br /&gt;  declare dup_key condition for sqlstate '23000';&lt;br /&gt;  declare my_not_found condition for sqlstate '02000';&lt;br /&gt;  declare c cursor for select * from test.m;&lt;br /&gt;  declare continue handler for dup_key begin end;&lt;br /&gt;  declare continue handler for not found set done=1;    # shorthand&lt;br /&gt;  declare continue handler for my_not_found set done=1; # with my declare condition&lt;br /&gt;  open c;&lt;br /&gt;  select sleep(20);&lt;br /&gt;  repeat&lt;br /&gt;    fetch c into v;&lt;br /&gt;    if done != 1&lt;br /&gt;    then&lt;br /&gt;      select v;&lt;br /&gt;    end if;&lt;br /&gt;  until done = 1 end repeat;&lt;br /&gt;  close c;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;delimiter //&lt;br /&gt;drop procedure if exists testCursor//&lt;br /&gt;create procedure testCursor() &lt;br /&gt;begin&lt;br /&gt;  declare done int default 0;&lt;br /&gt;  declare n int default 0;&lt;br /&gt;  declare c cursor for select * from test.testCursor1; -- must declare before handler&lt;br /&gt;  declare continue handler for not found set done=1;&lt;br /&gt;  open c;&lt;br /&gt;  repeat&lt;br /&gt;    fetch c into n;&lt;br /&gt;    if not done then&lt;br /&gt;      insert into test.testCursor2 values (n);&lt;br /&gt;      -- if n=3 then&lt;br /&gt;      --   set done=1;&lt;br /&gt;      -- end if;&lt;br /&gt;    end if;&lt;br /&gt;  until done end repeat;&lt;br /&gt;  close c;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;call testCursor();&lt;br /&gt;select t1.no t1, t2.no t2&lt;br /&gt;from test.testCursor1 t1&lt;br /&gt;     left join testCursor2 t2&lt;br /&gt;     on t1.no=t2.no;&lt;br /&gt;drop table testCursor1;&lt;br /&gt;drop table testCursor2;&lt;br /&gt;drop procedure testCursor;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* trigger */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;&lt;br /&gt;create table t1 (&lt;br /&gt;  id int auto_increment,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;create table i1 (&lt;br /&gt;  id int,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;create table d1 (&lt;br /&gt;  id int,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  primary key (id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;create table u1 (&lt;br /&gt;  old_id int,&lt;br /&gt;  old_name varchar(32),&lt;br /&gt;  new_id int,&lt;br /&gt;  new_name varchar(32)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;-- insert trigger&lt;br /&gt;create trigger t1_i1&lt;br /&gt;after insert&lt;br /&gt;on t1&lt;br /&gt;for each row&lt;br /&gt;insert into i1 values (new.id, new.name);&lt;br /&gt;&lt;br /&gt;-- delete trigger&lt;br /&gt;create trigger t1_d1&lt;br /&gt;after delete&lt;br /&gt;on t1&lt;br /&gt;for each row&lt;br /&gt;insert into d1 values (old.id, old.name);&lt;br /&gt;&lt;br /&gt;-- update trigger&lt;br /&gt;create trigger t1_u1&lt;br /&gt;after update&lt;br /&gt;on t1&lt;br /&gt;for each row&lt;br /&gt;insert into u1 values(old.id, old.name, new.id, new.name);&lt;br /&gt;&lt;br /&gt;-- PS. the foreign key with cascade action, not active trigger.&lt;br /&gt;insert into t1 (name) values ('Tom'),('John'),('Mary');&lt;br /&gt;update t1 set id=id+10;&lt;br /&gt;delete from t1;&lt;br /&gt;&lt;br /&gt;select * from t1;&lt;br /&gt;select * from i1;&lt;br /&gt;select * from d1;&lt;br /&gt;select * from u1;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- table declaration&lt;br /&gt;drop table if exists p;&lt;br /&gt;create table if not exists p (id int, no int);&lt;br /&gt;drop table if exists c;&lt;br /&gt;create table if not exists c (cid int, pid int, name varchar(32));&lt;br /&gt;drop table if exists old_p;&lt;br /&gt;create table if not exists old_p(id int, no int);&lt;br /&gt;drop table if exists old_c;&lt;br /&gt;create table if not exists old_c(cid int, pid int, name varchar(32));&lt;br /&gt;-- end table declaration&lt;br /&gt;&lt;br /&gt;-- trigger declaration&lt;br /&gt;delimiter //&lt;br /&gt;&lt;br /&gt;-- create succ, but run fail, ERROR 1442 (HY000): Can't update table 'p' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.&lt;br /&gt;--&lt;br /&gt;-- drop trigger if exists ai_p//&lt;br /&gt;-- create trigger ai_p after insert on p&lt;br /&gt;-- for each row&lt;br /&gt;-- begin&lt;br /&gt;--   if new.id is null then&lt;br /&gt;--     delete from p where id is null;&lt;br /&gt;--   end if;&lt;br /&gt;-- end//&lt;br /&gt;&lt;br /&gt;drop trigger if exists ad_p//&lt;br /&gt;create trigger ad_p after delete on p&lt;br /&gt;for each row&lt;br /&gt;begin&lt;br /&gt;  insert into old_p values (old.id, old.no);&lt;br /&gt;  delete from c where pid=old.id;&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;drop trigger if exits ad_c//&lt;br /&gt;create trigger ad_c after delete on c&lt;br /&gt;for each row&lt;br /&gt;begin&lt;br /&gt;  insert into old_c values (old.cid, old.pid, old.name);&lt;br /&gt;end//&lt;br /&gt;&lt;br /&gt;insert into p values (1,1),(2,2),(3,3);&lt;br /&gt;insert into c values (1,1,'tom'),(2,2,'joseph'),(3,3,'christy'),(4,4,'chantelle');&lt;br /&gt;&lt;br /&gt;delimiter ;&lt;br /&gt;-- end trigger declaration&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* lock table */&lt;br /&gt;/*&lt;br /&gt;set sql_mode='';&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table t1 (&lt;br /&gt;  no int&lt;br /&gt;);&lt;br /&gt;create table t2 (&lt;br /&gt;  no int&lt;br /&gt;);&lt;br /&gt;create table t3 (&lt;br /&gt;  no int&lt;br /&gt;);&lt;br /&gt;insert into t1 values (1),(2),(3);&lt;br /&gt;insert into t2 values (1),(2),(3);&lt;br /&gt;insert into t3 values (1),(2),(3);&lt;br /&gt;lock tables t1 write, t2 read, t3 write, t3 as t3_4r read;&lt;br /&gt;&lt;br /&gt;select * from t1; -- success&lt;br /&gt;insert into t1 values (4),(5),(6); -- success&lt;br /&gt;select * from t1; -- success&lt;br /&gt;&lt;br /&gt;select * from t2; -- success&lt;br /&gt;insert into t2 values (4),(5),(6); -- fail. if run command by stdin, will exit program.&lt;br /&gt;select * from t2; -- success&lt;br /&gt;&lt;br /&gt;select * from t3;&lt;br /&gt;insert into t3 select * from t3;&lt;br /&gt;select * from t3;&lt;br /&gt;insert into t3 select * from t3 as t3_4r;&lt;br /&gt;select * from t3;&lt;br /&gt;unlock tables;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* cache */&lt;br /&gt;/*&lt;br /&gt;use test;&lt;br /&gt;set global test_cache.key_buffer_size=128*1024;&lt;br /&gt;cache index t1,t2 in test_cache;&lt;br /&gt;load index into cache t1,t2;&lt;br /&gt;load index into cache t1,t2 ignore leaves;&lt;br /&gt;set global test_cache.key_buffer_size=0;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* partitiion table */&lt;br /&gt;/*&lt;br /&gt;-- partitions must be integer or trsnfer to integer by func.&lt;br /&gt;-- supports MyISAM, InnoDB, Archive storage engines.&lt;br /&gt;show variables like '%have_partitioning%';&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;&lt;br /&gt;CREATE TABLE ti (id INT, amount DECIMAL(7,2), tr_date DATE)&lt;br /&gt;    ENGINE=INNODB&lt;br /&gt;    PARTITION BY HASH( MONTH(tr_date) )&lt;br /&gt;    PARTITIONS 6;&lt;br /&gt;&lt;br /&gt;create table tl (&lt;br /&gt;  id int&lt;br /&gt;) engine=MyISAM&lt;br /&gt;  partition by list(id) &lt;br /&gt;  (&lt;br /&gt;    partition p0 values in (0,2,4,6,8),&lt;br /&gt;    partition p1 values in (1,3,5,7,9)&lt;br /&gt;  );&lt;br /&gt;&lt;br /&gt;create table tk1 (&lt;br /&gt;  id int,&lt;br /&gt;  tr_date date,&lt;br /&gt;  primary key (id)&lt;br /&gt;) engine=InnoDB&lt;br /&gt;  partition by key()&lt;br /&gt;  partitions 10;&lt;br /&gt;&lt;br /&gt;create table tk2 (&lt;br /&gt;  id int not null, -- must have not null&lt;br /&gt;  tr_date date,&lt;br /&gt;  unique key (id)&lt;br /&gt;) engine=InnoDB&lt;br /&gt;  partition by key()&lt;br /&gt;  partitions 10;&lt;br /&gt;&lt;br /&gt;create table tk3 (&lt;br /&gt;  id int,&lt;br /&gt;  tr_date date,&lt;br /&gt;  primary key (id)&lt;br /&gt;) engine=InnoDB&lt;br /&gt;  partition by key(id)&lt;br /&gt;  partitions 10;&lt;br /&gt;&lt;br /&gt;create table tk4 (&lt;br /&gt;  id int,&lt;br /&gt;  tr_date date&lt;br /&gt;) engine=InnoDB&lt;br /&gt;  partition by linear key(id)&lt;br /&gt;  partitions 10;&lt;br /&gt;&lt;br /&gt;explain partition select * from tk4 where id=1;&lt;br /&gt;&lt;br /&gt;-- range&lt;br /&gt;drop table tr1;&lt;br /&gt;create table tr1 (&lt;br /&gt;  id int&lt;br /&gt;) engine = InnoDB&lt;br /&gt;  partition by range (id) &lt;br /&gt;  (&lt;br /&gt;    partition p0 values less than (10),&lt;br /&gt;    partition p1 values less than (20),&lt;br /&gt;    partition pm values less than (maxvalue)&lt;br /&gt;  );&lt;br /&gt;&lt;br /&gt;drop table tr2;&lt;br /&gt;create table tr2 (&lt;br /&gt;  id int&lt;br /&gt;) engine = InnoDB&lt;br /&gt;  partition by range (id) &lt;br /&gt;  (&lt;br /&gt;    partition p0 values less than (10),&lt;br /&gt;    partition p1 values less than (20)&lt;br /&gt;  );&lt;br /&gt;&lt;br /&gt;mysql&amp;gt; insert into tr2 values (30);&lt;br /&gt;ERROR 1526 (HY000): Table has no partition for value 30&lt;br /&gt;mysql&amp;gt;&lt;br /&gt;&lt;br /&gt;## convert from partition table to normal table&lt;br /&gt;alter table tr2 remove partitioning;&lt;br /&gt;## convert from normal table to partition table&lt;br /&gt;alter table tr2 &lt;br /&gt;  partition by range (id) &lt;br /&gt;  (&lt;br /&gt;    partition p0 values less than (10),&lt;br /&gt;    partition p1 values less than (20)&lt;br /&gt;  );&lt;br /&gt;## drop partition data.&lt;br /&gt;alter table tr2 drop partition p0;&lt;br /&gt;*/&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;-- subpartition&lt;br /&gt;drop table ts1;&lt;br /&gt;create table ts1 (&lt;br /&gt;  id int,&lt;br /&gt;  no int&lt;br /&gt;) engine=InnoDB&lt;br /&gt;  partition by list (mod(id,2))&lt;br /&gt;  subpartition by hash (no)&lt;br /&gt;  subpartitions 2 (&lt;br /&gt;    partition p0 values in (0),&lt;br /&gt;    partition p1 values in (1)&lt;br /&gt;  );&lt;br /&gt;&lt;br /&gt;drop table ts2;&lt;br /&gt;CREATE TABLE ts2 (id INT, purchased DATE)&lt;br /&gt;    PARTITION BY RANGE( YEAR(purchased) )&lt;br /&gt;    SUBPARTITION BY HASH( TO_DAYS(purchased) ) &lt;br /&gt;    (&lt;br /&gt;        PARTITION p0 VALUES LESS THAN (1990)&lt;br /&gt;        (&lt;br /&gt;            SUBPARTITION s0,&lt;br /&gt;            SUBPARTITION s1&lt;br /&gt;        ),&lt;br /&gt;        PARTITION p1 VALUES LESS THAN (2000)&lt;br /&gt;        (&lt;br /&gt;            SUBPARTITION s2,&lt;br /&gt;            SUBPARTITION s3&lt;br /&gt;        ),&lt;br /&gt;        PARTITION p2 VALUES LESS THAN (MAXVALUE)&lt;br /&gt;        (&lt;br /&gt;            SUBPARTITION s4,&lt;br /&gt;            SUBPARTITION s5&lt;br /&gt;--            ,SUBPARTITION s6 -- error with not mismatch sub partitions&lt;br /&gt;        )&lt;br /&gt;    )&lt;br /&gt;    ;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* storage engine merge */&lt;br /&gt;/*&lt;br /&gt;########################### ??? create merge fail, recheck again...&lt;br /&gt;## can use a mix of compressed and uncompressed tables.&lt;br /&gt;#drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;drop table t1,t2,t3,total1,total2;&lt;br /&gt;CREATE TABLE t1 (&lt;br /&gt;  a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;  message VARCHAR(20)&lt;br /&gt;) ENGINE=MyISAM;&lt;br /&gt;CREATE TABLE t2 (&lt;br /&gt;  a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;  message VARCHAR(20)&lt;br /&gt;) ENGINE=MyISAM;&lt;br /&gt;CREATE TABLE t3 (&lt;br /&gt;  a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;  message VARCHAR(20)&lt;br /&gt;) ENGINE=MyISAM;&lt;br /&gt;call bulkInsert('t1','NULL,\"t1\"',1000);&lt;br /&gt;call bulkInsert('t2','NULL,\"t2\"',1000);&lt;br /&gt;call bulkInsert('t3','NULL,\"t3\"',1000);&lt;br /&gt;#INSERT INTO t1 (message) VALUES ('Testing'),('table'),('t1');&lt;br /&gt;#INSERT INTO t2 (message) VALUES ('Testing'),('table'),('t2');&lt;br /&gt;#INSERT INTO t3 (message) VALUES ('Testing'),('table'),('t3');&lt;br /&gt;&lt;br /&gt;system pfexec myisampack $MySQLDataDir/test/t3&lt;br /&gt;CREATE TABLE total1 (&lt;br /&gt;  a INT NOT NULL AUTO_INCREMENT,&lt;br /&gt;  message CHAR(20),&lt;br /&gt;  INDEX(a)&lt;br /&gt;) ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;&lt;br /&gt;CREATE TABLE total2 (&lt;br /&gt;  a INT NOT NULL AUTO_INCREMENT,&lt;br /&gt;  message CHAR(20),&lt;br /&gt;  INDEX(a)&lt;br /&gt;) ENGINE=MERGE UNION=(t1,t3) INSERT_METHOD=LAST;&lt;br /&gt;&lt;br /&gt;select * from total1;&lt;br /&gt;select * from total2;&lt;br /&gt;##ERROR 1168 (HY000): Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;INSERT INTO total1 (message) VALUES ('Testing'),('table'),('total1');&lt;br /&gt;INSERT INTO total2 (message) VALUES ('Testing'),('table'),('total2');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* case sensitive */&lt;br /&gt;/*&lt;br /&gt;drop database if exists test;&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table case_cs_test (&lt;br /&gt;  word VARCHAR(10)&lt;br /&gt;) CHARACTER SET latin1 COLLATE latin1_general_cs; -- use _cs to case sensitive.&lt;br /&gt;insert into case_cs_test values ('A'),('a'),('B'),('b'),('C'),('c');&lt;br /&gt;select *&lt;br /&gt;from case_cs_test &lt;br /&gt;where word rlike '[A-Z]';&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* create user */&lt;br /&gt;/*&lt;br /&gt;-- if joseph not exists, create it.&lt;br /&gt;-- if joseph exists, change his password to 'new_password'.&lt;br /&gt;create user joseph@localhost identified by 'new_password';&lt;br /&gt;grant select on world.* to joseph@localhost identified by '123';&lt;br /&gt;grant all on test.* to 'joseph'@'localhost' identified by '123'&lt;br /&gt;with&lt;br /&gt;max_user_connections 1234&lt;br /&gt;max_connections_per_hour 1235&lt;br /&gt;max_queries_per_hour 1236&lt;br /&gt;max_updates_per_hour 1237;&lt;br /&gt;select * from world.City;&lt;br /&gt;revoke select on world.* from joseph@localhost;&lt;br /&gt;&lt;br /&gt;-- create user by clone someone priv.&lt;br /&gt;drop user 'joe'@'localhost';&lt;br /&gt;system rm /tmp/t.sql; ## \! rm /tmp/t.sql;&lt;br /&gt;select * into outfile '/tmp/t.sql' from mysql.user where user='stanley' and host='localhost';&lt;br /&gt;system perl -pi -e "s/localhost\tstanley/localhost\tjoe/" /tmp/t.sql;&lt;br /&gt;load data infile '/tmp/t.sql' into table mysql.user;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* federated engine */&lt;br /&gt;/*&lt;br /&gt;-- not support by default, must start mysqld with option --federated&lt;br /&gt;drop database if exists world;&lt;br /&gt;create database if not exists world;&lt;br /&gt;use world;&lt;br /&gt;&lt;br /&gt;CREATE TABLE City (&lt;br /&gt;  ID int(11) NOT NULL AUTO_INCREMENT,&lt;br /&gt;  Name char(35) NOT NULL DEFAULT '',&lt;br /&gt;  CountryCode char(3) NOT NULL DEFAULT '',&lt;br /&gt;  District char(20) NOT NULL DEFAULT '',&lt;br /&gt;  Population int(11) NOT NULL DEFAULT '0',&lt;br /&gt;  PRIMARY KEY (ID)&lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;&lt;br /&gt;grant select on world.City to 'bob'@'localhost' identified by '123';&lt;br /&gt;&lt;br /&gt;CREATE TABLE FedCity (&lt;br /&gt;  ID int(11) NOT NULL AUTO_INCREMENT,&lt;br /&gt;  Name char(35) NOT NULL DEFAULT '',&lt;br /&gt;  CountryCode char(3) NOT NULL DEFAULT '',&lt;br /&gt;  District char(20) NOT NULL DEFAULT '',&lt;br /&gt;  Population int(11) NOT NULL DEFAULT '0',&lt;br /&gt;  PRIMARY KEY (ID)&lt;br /&gt;) ENGINE=FEDERATED&lt;br /&gt;CONNECTION='mysql://bob:123@localhost/world/City';&lt;br /&gt;&lt;br /&gt;insert into City(Name,CountryCode,District,Population) values ('Tom','TW','Taipei',100);&lt;br /&gt;insert into City(Name,CountryCode,District,Population) values ('Joseph','TW','Taipei',100);&lt;br /&gt;insert into City(Name,CountryCode,District,Population) values ('Christy','TW','Taipei',100);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* create user */&lt;br /&gt;/*&lt;br /&gt;## create user with clear text password&lt;br /&gt;create user bob identified by '123';&lt;br /&gt;create user joseph@localhost identified by '123';&lt;br /&gt;&lt;br /&gt;## update password with clear text&lt;br /&gt;set password for 'bob'@'localhost' = password('789');&lt;br /&gt;set password = password('abc'); -- set the password of non-anonymous client.&lt;br /&gt;update mysql.user set password=password('456') where user='bob';&lt;br /&gt;&lt;br /&gt;## update password with encypted text&lt;br /&gt;set password for 'stanley'@'localhost' = '*2FCDC0F13666DF2E09612610C2987BE092AB473D'; -- set the password with encrypted password by command "set password".&lt;br /&gt;update mysql.user set password='*2FCDC0F13666DF2E09612610C2987BE092AB473D' where user='stanley' and host='localhost'; -- set the password with encrypted password by update "mysql.user" data table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;###################################### priv_types:&lt;br /&gt;## 1. table priv_type:&lt;br /&gt;##    alter, create view, create, delete, drop, grant option, index, insert, select, show view, and update&lt;br /&gt;grant all on *.* to 'bob'@'%'; -- auto create user. use sql_mod='no_auto_create_user' to avoid auto create user.&lt;br /&gt;grant all on *.* to 'bob'@'%' identified by 'abc'; -- although use sql_mod='no_auto_create_user', still create user. (***)&lt;br /&gt;grant all on *.* to 'bob'@'localhost';&lt;br /&gt;grant select on *.* to 'bob'@'localhost';&lt;br /&gt;grant all on mysql.* to 'bob'@'localhost';&lt;br /&gt;grant select on mysql.* to 'bob'@'localhost';&lt;br /&gt;grant all on mysql.user to 'bob'@'localhost';&lt;br /&gt;grant select on mysql.user to 'bob'@'localhost';&lt;br /&gt;##&lt;br /&gt;## 1.x show grants:&lt;br /&gt;show grants for 'bob'@'localhost';&lt;br /&gt;&lt;br /&gt;## 2. column priv_type:&lt;br /&gt;##    insert, select, and update&lt;br /&gt;grant select (col1), insert (col1, col2) on mysql.user to 'bob'@'localhost';&lt;br /&gt;&lt;br /&gt;## 3. routine priv_type:&lt;br /&gt;##    alter routine, create routine, execute, and grant option&lt;br /&gt;grant create routine on mysql.* to 'bob'@'localhost';&lt;br /&gt;grant execute on procedure on mysql.proc to 'bob'@'localhost';&lt;br /&gt;&lt;br /&gt;## 4. with grant option:&lt;br /&gt;grant select on world.* to 'bob'@'localhost' with grant option;&lt;br /&gt;##&lt;br /&gt;## 4.x revoke with grant option:&lt;br /&gt;## revoke grant option on world.* from 'bob'@'localhost';&lt;br /&gt;&lt;br /&gt;############ security.&lt;br /&gt;## over ssl&lt;br /&gt;grant all privileges on test.* to 'bob'@'localhost'&lt;br /&gt;  identified by 'bob123' require ssl;&lt;br /&gt;&lt;br /&gt;## limit login host&lt;br /&gt;#grant all privileges on test.* to 'bob'@&lt;br /&gt;#1. '%'&lt;br /&gt;#2. '%.sun.com'&lt;br /&gt;#3. '192.168.1.0/255.255.255.0'&lt;br /&gt;#3. '192.168.1._' -- .0~.9&lt;br /&gt;&lt;br /&gt;## limit connect, query per hour&lt;br /&gt;grant all on world.*&lt;br /&gt;to 'bob'@'localhost'&lt;br /&gt;with &lt;br /&gt;max_user_connections 1&lt;br /&gt;max_connections_per_hour 10&lt;br /&gt;max_queries_per_hour 50&lt;br /&gt;max_updates_per_hour 20;&lt;br /&gt;&lt;br /&gt;show grants;&lt;br /&gt;show grants for current_user();&lt;br /&gt;&lt;br /&gt;## check user&lt;br /&gt;ex.&lt;br /&gt;mysql&amp;gt; select user(), current_user();&lt;br /&gt;+----------------+----------------+&lt;br /&gt;| user()         | current_user() |&lt;br /&gt;+----------------+----------------+&lt;br /&gt;| bob@a.b.c.d    | bob@%          | &lt;br /&gt;+----------------+----------------+&lt;br /&gt;&lt;br /&gt;drop user test;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* create index */&lt;br /&gt;/*&lt;br /&gt;create table ttt (&lt;br /&gt;  id int,&lt;br /&gt;  no int,&lt;br /&gt;  grade int,&lt;br /&gt;  name varchar(32),&lt;br /&gt;  index idx_ttt_id (id) -- key idx_ttt_id(id)&lt;br /&gt;) engine=MyISAM;&lt;br /&gt;create index idx_ttt_id on ttt(id);&lt;br /&gt;create index idx_ttt_no on ttt(no);&lt;br /&gt;create index idx_ttt_grade on ttt(grade);&lt;br /&gt;create index idx_per_name on ttt(name(10)); -- create prefix index.&lt;br /&gt;create index idx_pre_name1 on ttt(left(name,10)); -- not work, not support functional index.&lt;br /&gt;create index idx_pre_name2 on ttt(name(10)); -- only use the index with conditon name='test'; not left(name,8)='test.&lt;br /&gt;show index from ttt;&lt;br /&gt;-- using index ( like oracle hint )&lt;br /&gt;SELECT * FROM ttt USE INDEX (idx_ttt_id,idx_ttt_no)&lt;br /&gt;  WHERE col1=1 AND col2=2 AND col3=3;&lt;br /&gt;SELECT * FROM ttt IGNORE INDEX (idx_ttt_grade)&lt;br /&gt;  WHERE col1=1 AND col2=2 AND col3=3;&lt;br /&gt;&lt;br /&gt;# syntax: &lt;br /&gt;#   create index index_name type on table_name(columns);&lt;br /&gt;#   alter table table_name add index type(columns);&lt;br /&gt;# type:&lt;br /&gt;#   using btree|hash|rtree&lt;br /&gt;create index hash1 using hash on t(i,j);&lt;br /&gt;alter table t add index using hash(i,j);&lt;br /&gt;&lt;br /&gt;drop table if exists testIndex;&lt;br /&gt;create table testIndex(i int, j int, index idx1(i,j), index idx2(j));&lt;br /&gt;insert into testIndex values (1,1),(2,2);&lt;br /&gt;## use index&lt;br /&gt;explain select * from testIndex use index (idx1)\G&lt;br /&gt;explain select * from testIndex use index (idx2)\G&lt;br /&gt;explain select * from testIndex use index (idx1,idx2)\G&lt;br /&gt;&lt;br /&gt;## ignore index&lt;br /&gt;explain select * from testIndex ignore index (idx1)\G&lt;br /&gt;## ignore index is equivalent the combination of hints:&lt;br /&gt;## 1. explain select * from testIndex ignore index for join (idx1)\G&lt;br /&gt;## 2. explain select * from testIndex ignore index for order by (idx1)\G&lt;br /&gt;## 3. explain select * from testIndex ignore index for group by (idx1)\G&lt;br /&gt;explain select * from testIndex ignore index (idx2)\G&lt;br /&gt;explain select * from testIndex ignore index (idx1,idx2)\G&lt;br /&gt;&lt;br /&gt;## force index&lt;br /&gt;explain select * from testIndex force index (idx1)\G&lt;br /&gt;##However, it is an error to mix USE INDEX and FORCE INDEX for the same table:&lt;br /&gt;##SELECT * FROM t1 USE INDEX FOR JOIN (i1) FORCE INDEX FOR JOIN (i2);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- predict prefix&lt;br /&gt;create table t ( name varchar(32));&lt;br /&gt;insert into t values ('this'),('is'),('a'),('dog'),('that'),('is'),('a'),('cat'),('good'),('morning'),('mr'),('li'),('good'),('morning'),('good'),('afternoon'),('good'),('evening'),('good'),('night');&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;  count(*) as 'Total Rows',&lt;br /&gt;  count(distinct name) as 'Distinct Values',&lt;br /&gt;  count(*) - count(distinct name) as 'Duplicate Values'&lt;br /&gt;from t;&lt;br /&gt;&lt;br /&gt;set @n=2;&lt;br /&gt;select&lt;br /&gt;  count(distinct left(name,@n)) as 'Distinct Prefix Values',&lt;br /&gt;  count(*) - count(distinct left(name,@n)) as 'Duplicate Prefix Values'&lt;br /&gt;from t;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- fulltext index&lt;br /&gt;create table fulltext_sample (&lt;br /&gt;  id int,&lt;br /&gt;  name varchar(8),&lt;br /&gt;  addr varchar(32)&lt;br /&gt;);&lt;br /&gt;alter table fulltext_sample add fulltext fulltext_name(name);&lt;br /&gt;#alter table t3 add fulltext tf(i);&lt;br /&gt;select * from fulltext_sample where match(name) against('tom');&lt;br /&gt;&lt;br /&gt;-- special index&lt;br /&gt;create table lookup (id int) engine=memory;&lt;br /&gt;create index idx_lookup_id using btree on lookup(id);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* max rows */&lt;br /&gt;/*&lt;br /&gt;## specifying MyISAM Maximum Row Count.&lt;br /&gt;## Note that, despite the name MAX_ROWS does not enforce a maximun number of rows for table. The option value is only used to calculate the pointer size. Not force, but also no warning!!&lt;br /&gt;## [mysqld]&lt;br /&gt;## myisam_data_pointer_size=7 ## default: 6&lt;br /&gt;&lt;br /&gt;## case 1:&lt;br /&gt;## the fixed-length is not need avg_row_length.&lt;br /&gt;create table t1(id int) engine=MyISAM max_rows=2; &lt;br /&gt;alter table t1 max_rows=4;&lt;br /&gt;insert into t1 values (1),(2),(3),(4),(5);&lt;br /&gt;&lt;br /&gt;select * from t;&lt;br /&gt;## case 2:&lt;br /&gt;create table t2(name varchar(32) engine=MyISAM avg_row_length=16 max_rows=4000000;&lt;br /&gt;alter table t2 avg_row_length=24 max_rows=3000000;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* table maintenance */&lt;br /&gt;/*&lt;br /&gt;check table t;    -- for MyISAM, InnoDB. also update index status and view definition.&lt;br /&gt;repair table t;   -- for MyISAM only.&lt;br /&gt;analyze table t;  -- for MyISAM, InnoDB. analyze the key values of the table.&lt;br /&gt;optimize table t; -- for MyISAM, InnoDB. clean up MyISAM by defragment, sort index pages, update index statistics. update InnoDB index statistics and free space in the clustered index.&lt;br /&gt;checksum table t; -- for MyISAM, ???&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* profiling */&lt;br /&gt;/*&lt;br /&gt;select @@profiling;&lt;br /&gt;set profiling=1;&lt;br /&gt;select * from mysq.user;&lt;br /&gt;create database test_profiling;&lt;br /&gt;use test_profiling;&lt;br /&gt;create table p1 ( name varchar(32));&lt;br /&gt;insert into p1 values ('Tom'),('Christy');&lt;br /&gt;select * from p1 where name='Tom';&lt;br /&gt;--&lt;br /&gt;show profile;&lt;br /&gt;show profiles; &lt;br /&gt;show profile for query 1; -- get query id from show profiles.&lt;br /&gt;show profile cpu for query 1;&lt;br /&gt;--&lt;br /&gt;set profiling=0;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* dangerous */&lt;br /&gt;/*&lt;br /&gt;create database if not exist test;&lt;br /&gt;use test;&lt;br /&gt;create table if not exist aInt ( n int );&lt;br /&gt;create table if not exist bVar ( n varchar(2));&lt;br /&gt;insert into aInt values (1),(2),(3);&lt;br /&gt;insert into bVar values ('1a'),('2b'),('3c');&lt;br /&gt;select * from aInt a, bVar b where a.n=b.n;&lt;br /&gt;set sql_mode=oracle;      -- not work.&lt;br /&gt;select * from aInt a, bVar b where a.n=b.n;&lt;br /&gt;set sql_mode=traditional; -- not work. &lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* tee */&lt;br /&gt;/*&lt;br /&gt;tee /tmp/tee.log;&lt;br /&gt;select * from information_schema.tables&lt;br /&gt;where table_name=user;&lt;br /&gt;notee;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* group_concat */&lt;br /&gt;/*&lt;br /&gt;select 'call group_concat.................';&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table if not exists testGroupConcat (i int, v varchar(32));&lt;br /&gt;insert into testGroupConcat values (1,'a'),(1,'b'),(2,'z'),(2,'y'),(2,'x'),(3,'i'),(3,NULL),(3,'j'),(NULL,'p'),(NULL,'q'),(NULL,'r');&lt;br /&gt;select * from testGroupConcat;&lt;br /&gt;select i, group_concat(v) from testGroupConcat;&lt;br /&gt;select i, group_concat(v order by (v)) from testGroupConcat;&lt;br /&gt;select i, group_concat('-', v order by (v)) from testGroupConcat;&lt;br /&gt;select i, group_concat('-', v order by (v) separator ':') from testGroupConcat;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* purge binary log */&lt;br /&gt;/*&lt;br /&gt;## purge binary logs&lt;br /&gt;purge binary logs to 'mysql-bin.010';&lt;br /&gt;purge binary logs before '2009-05-31 23:59:59';&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* functions */&lt;br /&gt;/*&lt;br /&gt;## sleep&lt;br /&gt;select sleep(10); # sleep 10 sec, then return 0.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* manipulating table data */&lt;br /&gt;/*&lt;br /&gt;## update multi-tables&lt;br /&gt;update m inner join n using(i)&lt;br /&gt;set m.i=4, n.i=4;&lt;br /&gt;## delete multi-tables&lt;br /&gt;delete m,n from m,n where m.i=n.i;       # success deleting from m,n&lt;br /&gt;delete from m,n using m,n where m.i=n.i; # success deleting from m,n&lt;br /&gt;delete from m inner join n using(i);     # success deleting from m,n&lt;br /&gt;delete m,n from m join n on m.i=n.i;     # success deleting from m,n &lt;br /&gt;delete m from n where m.i=n.i;           # ERROR 1109 (42S02): Unknown table 'm' in MULTI DELETE&lt;br /&gt;delete t1,t3 from t1,t2,t3 &lt;br /&gt;where  t1.id=t2.id and t3.id=t2.id;      # success deleting from t1,t3&lt;br /&gt;delete t1,t3 from t1&lt;br /&gt;inner join t2 using(id)&lt;br /&gt;inner join t3 using(id);                 # success deleting from t1,t3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;use test;&lt;br /&gt;drop table if exists gc;&lt;br /&gt;drop table if exists c;&lt;br /&gt;drop table if exists p;&lt;br /&gt;create table p (id int primary key) engine=innodb;&lt;br /&gt;create table c (id int primary key, pid int, foreign key (pid) references p(id)) engine=innodb;&lt;br /&gt;create table gc (id int primary key, pid int, foreign key (pid) references c(id)) engine=innodb;&lt;br /&gt;insert into p values (1),(2);&lt;br /&gt;insert into c values (1,1),(2,1),(3,2);&lt;br /&gt;insert into gc values (1,1),(2,1),(3,1),(4,2),(5,2),(6,3);&lt;br /&gt;############################################### all delete methods fail...&lt;br /&gt;delete p,c,gc&lt;br /&gt;from p&lt;br /&gt;  inner join c on c.pid = p.id&lt;br /&gt;  inner join gc on gc.pid = c.id&lt;br /&gt;;&lt;br /&gt;delete gc,c,p&lt;br /&gt;from p&lt;br /&gt;  inner join c on c.pid = p.id&lt;br /&gt;  inner join gc on gc.pid = c.id&lt;br /&gt;;&lt;br /&gt;delete gc,c,p&lt;br /&gt;from gc&lt;br /&gt;  inner join c on gc.pid = c.id&lt;br /&gt;  inner join p on c.pid = p.id&lt;br /&gt;;&lt;br /&gt;############################################### all delete methods fail...&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* replication */&lt;br /&gt;/*&lt;br /&gt;## refer to test_createReplication.txt&lt;br /&gt;start/stop slave;&lt;br /&gt;start/stop slave io_thread;&lt;br /&gt;start/stop slave sql_thread;&lt;br /&gt;&lt;br /&gt;## for my.cnf&lt;br /&gt;####################################################### replication&lt;br /&gt;## @master server, set bin log database&lt;br /&gt;#binlog-do-db=db1&lt;br /&gt;#binlog-do-db=db2&lt;br /&gt;#binlog-do-db=db3&lt;br /&gt;## @slaver server1, set replicated database&lt;br /&gt;#replicate-do-db=db1&lt;br /&gt;#replicate-do-db=db2&lt;br /&gt;## @slaver server2, set replicated database&lt;br /&gt;#replicate-do-db=db2&lt;br /&gt;#replicate-do-db=db3&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;/* event */&lt;br /&gt;/*&lt;br /&gt;set global event_scheduler=on;  # default is off&lt;br /&gt;grant event on stanley.* to 'bob'@'localhost'; &lt;br /&gt;create&lt;br /&gt;definer='stanley'@'localhost'   # defualt is CURRENT_USER&lt;br /&gt;event if not exists event_name&lt;br /&gt;on schedule every 10 second&lt;br /&gt;on completion preserve          # default is not preserve&lt;br /&gt;enable                          # default is enable, enable/disable/disable on slave&lt;br /&gt;comment 'put comments here'&lt;br /&gt;do&lt;br /&gt;select now() into outfile '/tmp/now.txt'&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* grant */&lt;br /&gt;/*&lt;br /&gt;## the grant target is signature, so the target doesnot have to exist.&lt;br /&gt;## ex. table ttt.yyy doesnot exist. but still can be granted,&lt;br /&gt;##     except funcion/procedure.&lt;br /&gt;##     mysql&amp;gt; grant all on ttt.yyy to 'guest'@'localhost';&lt;br /&gt;##     mysql&amp;gt; grant all on function db.func_must_exist to 'guest'@'localhost';&lt;br /&gt;##&lt;br /&gt;## grant/revoke all with grant option.&lt;br /&gt;## ex.&lt;br /&gt;##     mysql&amp;gt; grant all on *.* to 'guest'@'localhost' with grant option;&lt;br /&gt;##     mysql&amp;gt; revoke all, grant option on *.* from 'guest'@'localhost';&lt;br /&gt;## &lt;br /&gt;&lt;br /&gt;## user level&lt;br /&gt;#grant all          on *.* to 'guest'@'localhost';&lt;br /&gt;grant select,update on *.* to 'guest'@'localhost';&lt;br /&gt;select * &lt;br /&gt;from mysql.user &lt;br /&gt;where 1=1&lt;br /&gt;  and user='guest' &lt;br /&gt;  and host='localhost'&lt;br /&gt;  and select_priv='y'&lt;br /&gt;  and update_priv='y'\G&lt;br /&gt;&lt;br /&gt;## database level&lt;br /&gt;#grant all          on world.* to 'guest'@'localhost';&lt;br /&gt;grant select,update on world.* to 'guest'@'localhost';&lt;br /&gt;select * &lt;br /&gt;from mysql.db &lt;br /&gt;where 1=1 &lt;br /&gt;  and user='guest' &lt;br /&gt;  and host='localhost' &lt;br /&gt;  and db='world'&lt;br /&gt;  and select_priv='y'&lt;br /&gt;  and update_priv='y'\G&lt;br /&gt;&lt;br /&gt;## table level&lt;br /&gt;#grant all          on world.City to 'guest'@'localhost';&lt;br /&gt;grant select,update on world.City to 'guest'@'localhost';&lt;br /&gt;select * &lt;br /&gt;from mysql.tables_priv &lt;br /&gt;where 1=1 &lt;br /&gt;  and user='guest' &lt;br /&gt;  and host='localhost' &lt;br /&gt;  and db='world'&lt;br /&gt;  and table_priv = 'select,update'\G&lt;br /&gt;&lt;br /&gt;## column level, will also update mysql.tables_priv&lt;br /&gt;grant select(ID,Name), update(Name) on world.City to 'guest'@'localhost';&lt;br /&gt;select * &lt;br /&gt;from mysql.columns_priv &lt;br /&gt;where 1=1 &lt;br /&gt;  and user='guest' &lt;br /&gt;  and host='localhost' &lt;br /&gt;  and db='world' &lt;br /&gt;  and table_name='City' &lt;br /&gt;  and (&lt;br /&gt;        (column_name='ID'   and column_priv='select') or&lt;br /&gt;        (column_name='Name' and column_priv='select,update')&lt;br /&gt;      )\G&lt;br /&gt;&lt;br /&gt;select * &lt;br /&gt;from mysql.tables_priv &lt;br /&gt;where 1=1 &lt;br /&gt;  and user='guest' &lt;br /&gt;  and host='localhost' &lt;br /&gt;  and db='world'&lt;br /&gt;  and column_priv = 'select,update'\G&lt;br /&gt;&lt;br /&gt;## proc level&lt;br /&gt;delimiter //&lt;br /&gt;drop procedure if exists world.testProc;&lt;br /&gt;create procedure world.testProc()&lt;br /&gt;no sql&lt;br /&gt;begin&lt;br /&gt;  select '1';&lt;br /&gt;end//&lt;br /&gt;drop function if exists world.testFunc;&lt;br /&gt;create function world.testFunc()&lt;br /&gt;returns int&lt;br /&gt;no sql&lt;br /&gt;deterministic&lt;br /&gt;begin&lt;br /&gt;  return 1;&lt;br /&gt;end//&lt;br /&gt;delimiter ;&lt;br /&gt;#grant all     on procedure world.testProc to 'guest'@'localhost';&lt;br /&gt;grant execute on procedure world.testProc to 'guest'@'localhost';&lt;br /&gt;#grant alter   on procedure world.testProc to 'guest'@'localhost';&lt;br /&gt;grant all     on function  world.testFunc to 'guest'@'localhost';&lt;br /&gt;#grant execute on function  world.testFunc to 'guest'@'localhost';&lt;br /&gt;#grant alter   on function  world.testFunc to 'guest'@'localhost';&lt;br /&gt;select *&lt;br /&gt;from mysql.procs_priv&lt;br /&gt;where 1=1&lt;br /&gt;  and user='guest'&lt;br /&gt;  and host='localhost'&lt;br /&gt;  and db='world'&lt;br /&gt;  and (&lt;br /&gt;        (routine_name='testProc' and routine_type='PROCEDURE' and proc_priv='execute') or&lt;br /&gt;        (routine_name='testFunc' and routine_type='FUNCTION' and proc_priv='execute,alter routine')&lt;br /&gt;      )\G &lt;br /&gt;## the column "routine_type" is case sensitive,&lt;br /&gt;## the column "proc_priv" value is&lt;br /&gt;##   'execute' if only execute priv&lt;br /&gt;##   'alter routine' if only alter priv&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;&lt;br /&gt;## drop user and also delete above priv data.&lt;br /&gt;drop user 'guest'@'localhost';&lt;br /&gt;select * from mysql.user where user='guest';&lt;br /&gt;select * from mysql.db where user='guest';&lt;br /&gt;select * from mysql.tables_priv where user='guest';&lt;br /&gt;select * from mysql.columns_priv where user='guest';&lt;br /&gt;select * from mysql.procs_priv where user='guest';&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* change user password */&lt;br /&gt;/*&lt;br /&gt;grant usage on *.* to 'guest'@'localhost' identified by 'new_password';&lt;br /&gt;grant usage on *.* to 'guest'@'localhost' identified by password '*0913BF2E2CE20CE21BFB1961AF124D4920458E5F'; # *0913... ( encrypted password )&lt;br /&gt;set password for 'guest'@'localhost' = password ('new_password');&lt;br /&gt;update mysql.user set password=password('new_password');&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* status */&lt;br /&gt;/*&lt;br /&gt;## connection information.&lt;br /&gt;show status like 'Connections';&lt;br /&gt;show status like 'Aborted_connects';&lt;br /&gt;show status like 'Aborted_clients';&lt;br /&gt;show status like 'Threads_connected';&lt;br /&gt;##&lt;br /&gt;## 1. Connections&lt;br /&gt;## 2. Aborted_connects&lt;br /&gt;## 3. Connections - Aborted_connects&lt;br /&gt;## 4. Aborted_clients&lt;br /&gt;## 5. Connections - Aborted_connects - Aborted_clients&lt;br /&gt;## 6. Threads_connected&lt;br /&gt;##&lt;br /&gt;&lt;br /&gt;## Com variables give you a breakdown of the number of statements &lt;br /&gt;## that the server has executed by statement type.&lt;br /&gt;show global status like 'Com%';&lt;br /&gt;&lt;br /&gt;## open tables;&lt;br /&gt;show status like 'Opened_tables';&lt;br /&gt;&lt;br /&gt;## amount of traffic&lt;br /&gt;show status like 'Bytes_received';&lt;br /&gt;show status like 'Bytes_sent';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## server load&lt;br /&gt;## case 1: Questions/Uptime, how many queries per second the server has processed.&lt;br /&gt;show global status like 'Questions';&lt;br /&gt;show global status like 'Uptime';&lt;br /&gt;## case2: slow queries&lt;br /&gt;show global status like 'slow_queries';&lt;br /&gt;&lt;br /&gt;## case3: show process&lt;br /&gt;show processlist;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* select */&lt;br /&gt;/*&lt;br /&gt;# default elements: 256, default memory: 8192&lt;br /&gt;select * from table_name procedure analyse(max_elements, [max_memory]);&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* character set */&lt;br /&gt;/*&lt;br /&gt;set names utf8;&lt;br /&gt;CREATE TABLE a ( a VARCHAR(32)) CHARACTER SET='BIG5' COLLATE='BIG5_BIN'; &lt;br /&gt;ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;&lt;br /&gt;ALTER TABLE t MODIFY latin1_text_col TEXT CHARACTER SET utf8;&lt;br /&gt;ALTER TABLE t MODIFY latin1_varchar_col VARCHAR(M) CHARACTER SET utf8;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* connection, kill session */&lt;br /&gt;/*&lt;br /&gt;kill connection 5;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;import data skip foreign key constraint check:&lt;br /&gt;mysql&amp;gt; SET foreign_key_checks = 0;&lt;br /&gt;mysql&amp;gt; SOURCE dump_file_name;&lt;br /&gt;mysql&amp;gt; SET foreign_key_checks = 1;&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8206115378655489253?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8206115378655489253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-testing-notes-for-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8206115378655489253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8206115378655489253'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-testing-notes-for-mysql.html' title='[Level 1] Testing notes for MySQL. (sql commands)'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7846678333917366099</id><published>2012-01-16T00:47:00.001+08:00</published><updated>2012-01-16T00:47:27.788+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Benchmark'/><title type='text'>[Level 3] Benchmark in MySQL</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash&lt;br /&gt;#mysqlslap -a -c100 i10 -u root -p --engine=InnoDB,MyISAM,MEMORY,ARCHIVE&lt;br /&gt;mysqlslap -a --only-print&lt;br /&gt;&lt;br /&gt;## ref.@@pseudo_thread_id to get different values of thread.&lt;br /&gt;# mysqlslap --create="CREATE TABLE A (a int);INSERT INTO A values (@@pseudo_thread_id)"&lt;br /&gt;# --query="SELECT * FROM A" --concurrency=50 --iterations=200&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7846678333917366099?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7846678333917366099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-benchmark-in-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7846678333917366099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7846678333917366099'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-benchmark-in-mysql.html' title='[Level 3] Benchmark in MySQL'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3886595359970611763</id><published>2012-01-16T00:45:00.001+08:00</published><updated>2012-01-16T00:46:09.237+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Transaction'/><title type='text'>[Level 3] Transaction in MySQL.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash -vx&lt;br /&gt;MYSQL_HOME=/opt/mysql/mysql&lt;br /&gt;mysql -uroot -proot_pwd &amp;lt;&amp;lt;EOF&lt;br /&gt;create database if not exists test;&lt;br /&gt;use test;&lt;br /&gt;create table if not exists test (id int) engine=InnoDB;&lt;br /&gt;alter table test engine=Innodb;&lt;br /&gt;truncate table test;&lt;br /&gt;insert into test values (1),(2),(3);&lt;br /&gt;&lt;br /&gt;system cp $MYSQL_HOME/data/test/test.ibd $MYSQL_HOME/data/test/test.ibd.bak&lt;br /&gt;&lt;br /&gt;start transaction;&lt;br /&gt;insert into test values (4);&lt;br /&gt;system cp $MYSQL_HOME/data/test/test.ibd $MYSQL_HOME/data/test/test.ibd.tran1;&lt;br /&gt;rollback;&lt;br /&gt;system cp $MYSQL_HOME/data/test/test.ibd $MYSQL_HOME/data/test/test.ibd.rollback;&lt;br /&gt;system diff $MYSQL_HOME/data/test/test.ibd.tran1 $MYSQL_HOME/data/test/test.ibd.rollback &amp;gt; ./diff_tran1_rollback;&lt;br /&gt;&lt;br /&gt;start transaction;&lt;br /&gt;insert into test values (4);&lt;br /&gt;system cp $MYSQL_HOME/data/test/test.ibd $MYSQL_HOME/data/test/test.ibd.tran2&lt;br /&gt;commit;&lt;br /&gt;system cp $MYSQL_HOME/data/test/test.ibd $MYSQL_HOME/data/test/test.ibd.commit&lt;br /&gt;system diff $MYSQL_HOME/data/test/test.ibd.tran2 $MYSQL_HOME/data/test/test.ibd.commit &amp;gt; ./diff_tran2_commit&lt;br /&gt;&lt;br /&gt;EOF&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3886595359970611763?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3886595359970611763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-transaction-in-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3886595359970611763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3886595359970611763'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-transaction-in-mysql.html' title='[Level 3] Transaction in MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-368616182314105480</id><published>2012-01-16T00:42:00.002+08:00</published><updated>2012-01-16T00:42:51.300+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>[Level 3] XML in MySQL.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash&lt;br /&gt;createTable() {&lt;br /&gt;  mysql -ujoseph &amp;lt;&amp;lt;EOF&lt;br /&gt;CREATE TABLE persons (&lt;br /&gt;id int auto_increment primary key,&lt;br /&gt;data text&lt;br /&gt;);&lt;br /&gt;EOF&lt;br /&gt;}&lt;br /&gt;#createTable&lt;br /&gt;&lt;br /&gt;createUsers(){&lt;br /&gt;  mysql -ujoseph &amp;lt;&amp;lt;EOF&lt;br /&gt;INSERT INTO persons(data) values &lt;br /&gt;('&lt;br /&gt;&amp;lt;person&amp;gt;&lt;br /&gt;  &amp;lt;name&amp;gt;stanley&amp;lt;/name&amp;gt;&lt;br /&gt;  &amp;lt;sex&amp;gt;m&amp;lt;/sex&amp;gt;&lt;br /&gt;  &amp;lt;addr&amp;gt;taipei&amp;lt;/addr&amp;gt;&lt;br /&gt;  &amp;lt;tels&amp;gt;&lt;br /&gt;    &amp;lt;tel&amp;gt;12340001&amp;lt;/tel&amp;gt;&lt;br /&gt;    &amp;lt;tel&amp;gt;12340002&amp;lt;/tel&amp;gt;&lt;br /&gt;    &amp;lt;tel&amp;gt;12340003&amp;lt;/tel&amp;gt;&lt;br /&gt;  &amp;lt;/tels&amp;gt;&lt;br /&gt;&amp;lt;/person&amp;gt;&lt;br /&gt;'),&lt;br /&gt;('&lt;br /&gt;&amp;lt;person&amp;gt;&lt;br /&gt;  &amp;lt;name&amp;gt;joseph&amp;lt;/name&amp;gt;&lt;br /&gt;  &amp;lt;sex&amp;gt;m&amp;lt;/sex&amp;gt;&lt;br /&gt;  &amp;lt;addr&amp;gt;taipei&amp;lt;/addr&amp;gt;&lt;br /&gt;  &amp;lt;tels&amp;gt;&lt;br /&gt;    &amp;lt;tel&amp;gt;12350001&amp;lt;/tel&amp;gt;&lt;br /&gt;    &amp;lt;tel&amp;gt;12350002&amp;lt;/tel&amp;gt;&lt;br /&gt;    &amp;lt;tel&amp;gt;12350003&amp;lt;/tel&amp;gt;&lt;br /&gt;  &amp;lt;/tels&amp;gt;&lt;br /&gt;&amp;lt;/person&amp;gt;&lt;br /&gt;')&lt;br /&gt;;&lt;br /&gt;EOF&lt;br /&gt;}&lt;br /&gt;#createUsers&lt;br /&gt;&lt;br /&gt;queryUserTels() {&lt;br /&gt;  mysql -ujoseph &amp;lt;&amp;lt;EOF&lt;br /&gt;select&lt;br /&gt;ExtractValue(data,'//person/tels/tel[1]'),&lt;br /&gt;ExtractValue(data,'/person/tels/tel[2]'),&lt;br /&gt;ExtractValue(data,'person/tels/tel[3]')&lt;br /&gt;from persons&lt;br /&gt;where id=1;&lt;br /&gt;EOF&lt;br /&gt;}&lt;br /&gt;#queryUserTels&lt;br /&gt;&lt;br /&gt;updateXML() {&lt;br /&gt;  mysql -ujoseph &amp;lt;&amp;lt;EOF&lt;br /&gt;select&lt;br /&gt;data,&lt;br /&gt;ExtractValue(data,'//person/name'),&lt;br /&gt;UpdateXML(data,'//person/name','&amp;lt;name&amp;gt;christy&amp;lt;/name&amp;gt;'),&lt;br /&gt;ExtractValue(UpdateXML(data,'//person/name','&amp;lt;name&amp;gt;christy&amp;lt;/name&amp;gt;'),'//person/name')&lt;br /&gt;from persons&lt;br /&gt;where id=1;&lt;br /&gt;EOF&lt;br /&gt;}&lt;br /&gt;#updateXML&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-368616182314105480?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/368616182314105480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-xml-in-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/368616182314105480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/368616182314105480'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-xml-in-mysql.html' title='[Level 3] XML in MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4225978797189617914</id><published>2012-01-16T00:37:00.002+08:00</published><updated>2012-01-16T00:38:47.729+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to delete duplicate data in MySQL.</title><content type='html'>&lt;pre class="prettyprint lang-sql linenums:1"&gt;drop table if exists abc;&lt;br /&gt;create table abc (i int DEFAULT NULL);&lt;br /&gt;insert into abc values (1),(2),(2),(3),(3),(3),(NULL),(NULL),(NULL),(NULL);&lt;br /&gt;-- insert into abc values (),(),(),(); -- work&lt;br /&gt;-- insert into abc values (1),(),(),(),(); -- not work&lt;br /&gt;-- ERROR 1136 (21S01): Column count doesn't match value count at row 2&lt;br /&gt;&lt;br /&gt;-- case 1:&lt;br /&gt;delete abc from abc, (select * from abc group by i having count(*)&gt;1) as xyz where abc.i=xyz.i or (abc.i is NULL and xyz.i is NULL) limit 1;&lt;br /&gt;-- case 2:&lt;br /&gt;delete abc from abc, (select * from abc group by i having count(*)&gt;1) as xyz where abc.i=xyz.i or (abc.i is NULL and xyz.i is NULL);&lt;br /&gt;&lt;br /&gt;/* result:&lt;br /&gt;mysql&gt; -- case 1:&lt;br /&gt;mysql&gt; delete abc from abc, (select * from abc group by i having count(*)&gt;1) as xyz where abc.i=xyz.i or (abc.i is NULL and xyz.i is NULL) limit 1;&lt;br /&gt;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 1' at line 1&lt;br /&gt;mysql&gt; -- case 2:&lt;br /&gt;mysql&gt; delete abc from abc, (select * from abc group by i having count(*)&gt;1) as xyz where abc.i=xyz.i or (abc.i is NULL and xyz.i is NULL);&lt;br /&gt;Query OK, 9 rows affected (0.00 sec)&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;easy way to delete duplicate data.&lt;br /&gt;create table cba as select distinct from abc;&lt;br /&gt;drop table abc;&lt;br /&gt;rename table cba to abc;&lt;br /&gt;*/&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4225978797189617914?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4225978797189617914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-how-to-delete-duplicate-data-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4225978797189617914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4225978797189617914'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-how-to-delete-duplicate-data-in.html' title='[Level 2] How to delete duplicate data in MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-371863399307275782</id><published>2012-01-16T00:34:00.002+08:00</published><updated>2012-01-16T00:34:54.165+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] mysqlshow notes for MySQL.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash -vx&lt;br /&gt;read -p "Enter Password: " p&lt;br /&gt;c="mysqlshow -uroot -p$p"&lt;br /&gt;case1() {&lt;br /&gt;  c1="$c"&lt;br /&gt;  c2="$c1 mysql"&lt;br /&gt;  c3="$c2 user"&lt;br /&gt;  c4="$c3 host"&lt;br /&gt;  echo $c1 &amp;&amp; $c1&lt;br /&gt;  echo $c2 &amp;&amp; $c2&lt;br /&gt;  echo $c3 &amp;&amp; $c3&lt;br /&gt;  echo $c4 &amp;&amp; $c4&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;case2() {&lt;br /&gt;  c1="$c"&lt;br /&gt;  c2="$c1 m%"&lt;br /&gt;  c3="$c1 mysql t%"&lt;br /&gt;  c4="$c1 mysql time_zone_transition Tr%"&lt;br /&gt;  echo $c1 &amp;&amp; $c1&lt;br /&gt;  echo $c2 &amp;&amp; $c2&lt;br /&gt;  echo $c3 &amp;&amp; $c3&lt;br /&gt;  echo $c4 &amp;&amp; $c4&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;case2&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-371863399307275782?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/371863399307275782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-mysqlshow-notes-for-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/371863399307275782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/371863399307275782'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-mysqlshow-notes-for-mysql.html' title='[Level 2] mysqlshow notes for MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1363581130022671072</id><published>2012-01-16T00:32:00.000+08:00</published><updated>2012-01-16T00:32:36.435+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><title type='text'>[Level 3] mysqldump/mysqlimport notes for MySQL.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash&lt;br /&gt;#dData=`dirname $0`/data&lt;br /&gt;dData=/tmp/data&lt;br /&gt;mkdir -p $dData &amp;&amp; cd $dData&lt;br /&gt;&lt;br /&gt;mysqldump -uroot test &amp;gt; $dData/test.sql&lt;br /&gt;mysqldump -uroot test t &amp;gt; $dData/test.t.sql&lt;br /&gt;&lt;br /&gt;#mysql -uroot &amp;lt; $dData/test.sql&lt;br /&gt;#mysql -uroot &amp;lt; $dData/test.t.sql&lt;br /&gt;&lt;br /&gt;exit&lt;br /&gt;exit&lt;br /&gt;exit&lt;br /&gt;&lt;br /&gt;--routines&lt;br /&gt;--triggers&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash&lt;br /&gt;#dData=`dirname $0`/data&lt;br /&gt;dData=/tmp/data&lt;br /&gt;mkdir -p $dData&lt;br /&gt;cd $dData&lt;br /&gt;&lt;br /&gt;mysql -uroot &amp;lt;&amp;lt;EOF&lt;br /&gt;use test;&lt;br /&gt;truncate table t;&lt;br /&gt;select * from t;&lt;br /&gt;EOF&lt;br /&gt;&lt;br /&gt;mysqlimport --fields-terminated-by=, --fields-enclosed-by='"' \&lt;br /&gt;            --lines-terminated-by="\n", --ignore \&lt;br /&gt;            test $dData/t.txt &lt;br /&gt;## '--ignore/--replace' contain unique key values already in the table, 'test' is database name, 't' is the tablename.&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1363581130022671072?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1363581130022671072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-mysqldumpmysqlimport-notes-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1363581130022671072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1363581130022671072'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-mysqldumpmysqlimport-notes-for.html' title='[Level 3] mysqldump/mysqlimport notes for MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1704645473812701285</id><published>2012-01-16T00:28:00.002+08:00</published><updated>2012-01-16T00:28:28.212+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Replication'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><title type='text'>[Level 3] Notes for MySQL replication</title><content type='html'>&lt;pre class="prettyprint lang-html"&gt;#################################################### master server&lt;br /&gt;set server_id=0; ## master server_id must be 0&lt;br /&gt;grant replication slave on *.* to 'slave'@'%' identified by 'slave';&lt;br /&gt;show master status;&lt;br /&gt;# +-----------------------+----------+--------------+------------------+&lt;br /&gt;# | File                  | Position | Binlog_Do_DB | Binlog_Ignore_DB |&lt;br /&gt;# +-----------------------+----------+--------------+------------------+&lt;br /&gt;# | Stanley-NB-bin.000103 |      377 |              |                  | &lt;br /&gt;# +-----------------------+----------+--------------+------------------+&lt;br /&gt;&lt;br /&gt;## in my.cnf&lt;br /&gt;[mysqld]&lt;br /&gt;server-id=0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#################################################### slaver server&lt;br /&gt;set server_id=1;&lt;br /&gt;# shell&gt; mysqldump -uroot -p test t1 &gt; /tmp/t.sql&lt;br /&gt;# mysql&gt; create database if not exist test;&lt;br /&gt;# mysql&gt; use test;&lt;br /&gt;# mysql&gt; source /tmp/t.sql&lt;br /&gt;change master to&lt;br /&gt;  master_host='192.168.1.100',&lt;br /&gt;  master_user='slave',&lt;br /&gt;  master_password='slave',&lt;br /&gt;  master_port=3306,&lt;br /&gt;  master_log_file='Stanley-NB-bin.000103',&lt;br /&gt;  master_log_pos=337;&lt;br /&gt;&lt;br /&gt;## in my.cnf&lt;br /&gt;[mysqld]&lt;br /&gt;server-id=1&lt;br /&gt;master-host=192.168.1.100&lt;br /&gt;master-user=slave&lt;br /&gt;master-password=slave&lt;br /&gt;master-port=3306&lt;br /&gt;&lt;br /&gt;#################################################### command&lt;br /&gt;start/stop slave;&lt;br /&gt;start/stop slave io_thread;&lt;br /&gt;start/stop slave sql_thread;&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1704645473812701285?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1704645473812701285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-notes-for-mysql-replication.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1704645473812701285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1704645473812701285'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-notes-for-mysql-replication.html' title='[Level 3] Notes for MySQL replication'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8203591856773525607</id><published>2012-01-16T00:26:00.000+08:00</published><updated>2012-01-16T00:26:23.265+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Storage Engine'/><title type='text'>[Level 2] CSV storage engine testing for MySQL.</title><content type='html'>For testing CSV storage engine for MySQL,&lt;br /&gt;I wrote a testing script as the following.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/bash -vx&lt;br /&gt;cat &gt; /tmp/test_csv.CSV &amp;lt;&amp;lt;EOF&lt;br /&gt;1,"Tom",90,90,80&lt;br /&gt;2,"Stanley",80,100,100&lt;br /&gt;3,"Joseph",70,80,90&lt;br /&gt;4,"Christy",80,80,100&lt;br /&gt;5,"Chantelle",60,60,60&lt;br /&gt;EOF&lt;br /&gt;mysql -uroot -p -e "create table test_csv ( no int not null, name varchar(32) not null, chi int not null, eng int not null, math int not null) engine=CSV;" world&lt;br /&gt;cp /tmp/test_csv.CSV /var/lib/mysql/world/test_csv.CSV&lt;br /&gt;mysql -uroot -p -e "flush table test_csv; select * from test_csv;" world&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8203591856773525607?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8203591856773525607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-csv-storage-engine-testing-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8203591856773525607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8203591856773525607'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-csv-storage-engine-testing-for.html' title='[Level 2] CSV storage engine testing for MySQL.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8637316433077745488</id><published>2012-01-16T00:21:00.001+08:00</published><updated>2012-01-16T00:21:59.160+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Packing MyISAM data table into readonly.</title><content type='html'>&lt;pre class="prettyprint lang-html"&gt;/*&lt;br /&gt;step 1: LOCK TABLE x FOR WRITE;&lt;br /&gt;step 2: FLUSH TABLE x;&lt;br /&gt;step 3: myisamchk -cFU -- fast check for pre-existing errors. Don't pack if errors exist. Ignore the warning of table "not closed" because this check will go ahead and closed the DB files.&lt;br /&gt;step 4: myisampack -f -- force overwrite of any preexisting .TMD file&lt;br /&gt;step 5: myisamchk -raqS -- rebuild the index after pack&lt;br /&gt;step 6: FLUSH TABLE x; -- force reload of info_schema data&lt;br /&gt;step 7: UNLOCK TABLES; -- Release the table.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;mysql -u mysql &amp;lt;&amp;lt;EOF&lt;br /&gt;use test;&lt;br /&gt;lock table x for write;&lt;br /&gt;flush table x;&lt;br /&gt;EOF&lt;br /&gt;&lt;br /&gt;cd /opt/mysql/mysql/data/test;&lt;br /&gt;myisamchk -cFU x;&lt;br /&gt;mysiampack -f x;&lt;br /&gt;myisamchk -raqS x;&lt;br /&gt;&lt;br /&gt;mysql -u mysql &amp;lt;&amp;lt;EOF&lt;br /&gt;flush table x;&lt;br /&gt;unlock tables;&lt;br /&gt;EOF&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8637316433077745488?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8637316433077745488/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-packing-myisam-data-table-into.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8637316433077745488'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8637316433077745488'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-packing-myisam-data-table-into.html' title='[Level 2] Packing MyISAM data table into readonly.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-536877030959067557</id><published>2012-01-12T20:58:00.000+08:00</published><updated>2012-01-12T20:58:18.100+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] Multithread in Python</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import os, sys&lt;br /&gt;import threading&lt;br /&gt;import random&lt;br /&gt;&lt;br /&gt;class ThreadClass (threading.Thread):&lt;br /&gt;    def __init__(self, function, seconds, threads):&lt;br /&gt;        self.function = function&lt;br /&gt;        self.seconds = seconds&lt;br /&gt;        threading.Thread.__init__(self)&lt;br /&gt;        threads.append(self)&lt;br /&gt;     &lt;br /&gt;    def run(self):&lt;br /&gt;        print 'run %s...' % self.seconds&lt;br /&gt;        self.function(self.seconds)&lt;br /&gt;        print 'run %s done!' % self.seconds&lt;br /&gt;&lt;br /&gt;class TestMultiThread(object):&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self.max_thread = 5 &lt;br /&gt;        self.threads = []&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    def task(self, seconds):&lt;br /&gt;        os.popen('sleep %s' % seconds).read()&lt;br /&gt;&lt;br /&gt;    def run(self):&lt;br /&gt;        for i in range(0, self.max_thread):&lt;br /&gt;            seconds = int(random.random() * 10) &lt;br /&gt;            ThreadClass(self.task, seconds, self.threads).start()&lt;br /&gt;&lt;br /&gt;        for t in self.threads:&lt;br /&gt;            t.join()&lt;br /&gt;&lt;br /&gt;        print 'Jobs done!'&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    tmt = TestMultiThread()&lt;br /&gt;    tmt.run()&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testMultiThread.py &lt;br /&gt;run 1...&lt;br /&gt;run 9...&lt;br /&gt;run 2...&lt;br /&gt;run 7...&lt;br /&gt;run 1...&lt;br /&gt;run 1 done!&lt;br /&gt;run 1 done!&lt;br /&gt;run 2 done!&lt;br /&gt;run 7 done!&lt;br /&gt;run 9 done!&lt;br /&gt;Jobs done!&lt;br /&gt;$&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-536877030959067557?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/536877030959067557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-multithread-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/536877030959067557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/536877030959067557'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-3-multithread-in-python.html' title='[Level 3] Multithread in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3296929818001555645</id><published>2012-01-09T22:44:00.000+08:00</published><updated>2012-01-09T22:44:54.176+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Flyweight in Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/env python&lt;br /&gt;import random&lt;br /&gt;&lt;br /&gt;class Black(object):&lt;br /&gt;    __instance = None&lt;br /&gt;    def __new__(cls):&lt;br /&gt;        if not cls.__instance:&lt;br /&gt;            cls.__instance = super(Black, cls).__new__(cls)&lt;br /&gt;        return cls.__instance&lt;br /&gt;&lt;br /&gt;    def __str__(self):&lt;br /&gt;        return 'black'&lt;br /&gt;&lt;br /&gt;class White(object):&lt;br /&gt;    __instance = None&lt;br /&gt;    def __new__(cls):&lt;br /&gt;        if not cls.__instance:&lt;br /&gt;            cls.__instance = super(White, cls).__new__(cls)&lt;br /&gt;        return cls.__instance&lt;br /&gt;&lt;br /&gt;    def __str__(self):&lt;br /&gt;        return 'white'&lt;br /&gt;&lt;br /&gt;class BlackAndWhite(object):&lt;br /&gt;    __black = Black()&lt;br /&gt;    __white = White()&lt;br /&gt;    def __new__(cls, index):&lt;br /&gt;        if index == 0:&lt;br /&gt;            return cls.__black&lt;br /&gt;        else:&lt;br /&gt;            return cls.__white&lt;br /&gt;&lt;br /&gt;    def __init__(self, index):&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;class Board(object):&lt;br /&gt;    def __init__(self, size):&lt;br /&gt;        self.__size = size&lt;br /&gt;        self.__planet = [ [ None for i in range(self.__size) ] for j in range(self.__size) ]&lt;br /&gt;&lt;br /&gt;    def setPlanet(self):&lt;br /&gt;        while True:&lt;br /&gt;            x = int(random.random() * self.__size)&lt;br /&gt;            y = int(random.random() * self.__size)&lt;br /&gt;            if self.__planet[x][y] != None:&lt;br /&gt;                continue&lt;br /&gt;            else:&lt;br /&gt;                z = int(random.random() * 2)&lt;br /&gt;                self.__planet[x][y] = BlackAndWhite(z)&lt;br /&gt;&lt;br /&gt;            if self.isCompleted():&lt;br /&gt;                break&lt;br /&gt;&lt;br /&gt;    def isCompleted(self):&lt;br /&gt;        for x in range(0, self.__size):&lt;br /&gt;            for y in range(0, self.__size):&lt;br /&gt;                if self.__planet[x][y] == None:&lt;br /&gt;                    return False&lt;br /&gt;        return True&lt;br /&gt;&lt;br /&gt;    def getPlanet(self):&lt;br /&gt;        self.setPlanet()&lt;br /&gt;        return self.__planet&lt;br /&gt;&lt;br /&gt;    def displayPlanet(self):&lt;br /&gt;        print [ [str(j) for j in i ] for i in self.getPlanet() ]&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    b = Board(4)&lt;br /&gt;    b.displayPlanet()&lt;br /&gt;    pass&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testFlyweight.py&lt;br /&gt;[['black', 'white', 'black', 'black'], ['white', 'black', 'white', 'black'], ['black', 'black', 'black', 'black'], ['white', 'black', 'white', 'white']]&lt;br /&gt;$&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3296929818001555645?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3296929818001555645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-flyweight-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3296929818001555645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3296929818001555645'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-flyweight-in-python.html' title='[Level 2] Flyweight in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1452338541433055391</id><published>2012-01-09T21:39:00.005+08:00</published><updated>2012-01-09T22:31:19.182+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Singleton in Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/env python&lt;br /&gt;class Singleton(object):&lt;br /&gt;    _instance = None&lt;br /&gt;    def __new__(cls, *args, **kwargs):&lt;br /&gt;        if not cls._instance:&lt;br /&gt;            cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)&lt;br /&gt;        return cls._instance&lt;br /&gt;&lt;br /&gt;print me&lt;br /&gt;print you &lt;br /&gt;&lt;br /&gt;print me == you        &lt;br /&gt;print id(me) == id(you)&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testSingleton.py&lt;br /&gt;True&lt;br /&gt;True&lt;br /&gt;$ &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You could also use metaclass to implement it.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/env python&lt;br /&gt;class Singleton(type):&lt;br /&gt;    def __init__(self, *args, **kwargs):&lt;br /&gt;        super(Singleton, self).__init__(*args, **kwargs)&lt;br /&gt;        self.__instance = None&lt;br /&gt;&lt;br /&gt;    def __call__(self, *args, **kwargs):&lt;br /&gt;        if self.__instance is None:&lt;br /&gt;            self.__instance = super(Singleton, self).__call__(*args, **kwargs)&lt;br /&gt;        return self.__instance&lt;br /&gt;&lt;br /&gt;class s(object):&lt;br /&gt;    __metaclass__ = Singleton&lt;br /&gt;    def __init__(self, size):&lt;br /&gt;        self.__size = size&lt;br /&gt;&lt;br /&gt;    def getSize(self):&lt;br /&gt;        return self.__size&lt;br /&gt;&lt;br /&gt;class n(object):&lt;br /&gt;    def __init__(self, size):&lt;br /&gt;        self.__size = size&lt;br /&gt;&lt;br /&gt;    def getSize(self):&lt;br /&gt;        return self.__size&lt;br /&gt;&lt;br /&gt;a = s(1)&lt;br /&gt;print a.getSize()&lt;br /&gt;b = s(2)&lt;br /&gt;print b.getSize()&lt;br /&gt;&lt;br /&gt;c = n(3)&lt;br /&gt;print c.getSize()&lt;br /&gt;d = n(4)&lt;br /&gt;print d.getSize()&lt;br /&gt;&lt;br /&gt;print a == b&lt;br /&gt;print c == d&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testMetaclassSingleton.py&lt;br /&gt;1&lt;br /&gt;1&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;True&lt;br /&gt;False&lt;br /&gt;$ &lt;/pre&gt;&lt;br /&gt;in Python 2.6 or later, you could use decorator to implement Singleton:&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def singleton(cls):&lt;br /&gt;    instances = {}&lt;br /&gt;    def getInstance(*args, **kwargs):&lt;br /&gt;        if cls not in instances:&lt;br /&gt;            instances[cls] = cls(*args, **kwargs)&lt;br /&gt;        return instances[cls]&lt;br /&gt;    return getInstance&lt;br /&gt;&lt;br /&gt;@singleton&lt;br /&gt;class s(object):&lt;br /&gt;    def __init__(self, size):&lt;br /&gt;        self.__size = size&lt;br /&gt;&lt;br /&gt;    def getSize(self):&lt;br /&gt;        return self.__size&lt;br /&gt;&lt;br /&gt;class n(object):&lt;br /&gt;    def __init__(self, size):&lt;br /&gt;        self.__size = size&lt;br /&gt;&lt;br /&gt;    def getSize(self):&lt;br /&gt;        return self.__size&lt;br /&gt;&lt;br /&gt;a = s(1)&lt;br /&gt;print a.getSize()&lt;br /&gt;b = s(2)&lt;br /&gt;print b.getSize()&lt;br /&gt;&lt;br /&gt;c = n(3)&lt;br /&gt;print c.getSize()&lt;br /&gt;d = n(4)&lt;br /&gt;print d.getSize()&lt;br /&gt;&lt;br /&gt;print a == b&lt;br /&gt;print c == d&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1452338541433055391?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1452338541433055391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-singleton-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1452338541433055391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1452338541433055391'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-singleton-in-python.html' title='[Level 2] Singleton in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2596660749305970087</id><published>2012-01-09T10:46:00.002+08:00</published><updated>2012-01-09T21:39:44.569+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 1] How to evaluate the string to boolean?</title><content type='html'>If you want to evaluate the string you could create a function like below.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def toBoolean(str):&lt;br /&gt;    return if str in ['True', '1']&lt;br /&gt;&lt;br /&gt;print toBoolean('True')&lt;br /&gt;print toBoolean('False')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But you could have an easier way to implement with native module called "ast.literal_eval()"&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;&amp;gt;&amp;gt;&amp;gt; import ast&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; help(ast.literal_eval)&lt;br /&gt;Help on function literal_eval in module ast:&lt;br /&gt;&lt;br /&gt;literal_eval(node_or_string)&lt;br /&gt;    Safely evaluate an expression node or a string containing a Python&lt;br /&gt;    expression.  The string or node provided may only consist of the following&lt;br /&gt;    Python literal structures: strings, numbers, tuples, lists, dicts, booleans,&lt;br /&gt;    and None.&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; ast.literal_eval('False')&lt;br /&gt;False&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; ast.literal_eval('True')&lt;br /&gt;True&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; ast.literal_eval('1')&lt;br /&gt;1&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; ast.literal_eval('0')&lt;br /&gt;0&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2596660749305970087?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2596660749305970087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-how-to-evaluate-string-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2596660749305970087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2596660749305970087'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-1-how-to-evaluate-string-to.html' title='[Level 1] How to evaluate the string to boolean?'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7077839652219369442</id><published>2012-01-03T21:03:00.000+08:00</published><updated>2012-01-03T21:03:01.684+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VPN'/><category scheme='http://www.blogger.com/atom/ns#' term='Juniper'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] Juniper vpn for ubuntu</title><content type='html'>If you need to setup the vpn on Ubuntu, you could refer to the following 2 links:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://http://mad-scientist.us/juniper.html"&gt;http://http://mad-scientist.us/juniper.html&lt;/a&gt;&lt;br /&gt;&lt;a href="http://holyarmy.org/2009/06/vpn-on-ubuntu-linux-with-juniper-network-connect/"&gt;http://holyarmy.org/2009/06/vpn-on-ubuntu-linux-with-juniper-network-connect/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7077839652219369442?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7077839652219369442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-juniper-vpn-for-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7077839652219369442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7077839652219369442'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2012/01/level-2-juniper-vpn-for-ubuntu.html' title='[Level 2] Juniper vpn for ubuntu'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7343271548207263537</id><published>2011-12-13T22:05:00.000+08:00</published><updated>2011-12-13T22:05:59.428+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Package management in Python. (pip)</title><content type='html'>pip is a tool for installing and managing Python packages,&lt;br /&gt;you could find more info &lt;a href="http://www.pip-installer.org/en/latest/index.html"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7343271548207263537?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7343271548207263537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/12/level-2-package-management-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7343271548207263537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7343271548207263537'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/12/level-2-package-management-in-python.html' title='[Level 2] Package management in Python. (pip)'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6232651476128416800</id><published>2011-11-29T00:53:00.000+08:00</published><updated>2011-11-29T00:53:59.764+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] MySQL security check with tcpdump.</title><content type='html'>you can check if MySQL data streams are encrypted or not by the following command:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# tcpdump -l -i eth0 -w - src or dst port 3306 | strings&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6232651476128416800?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6232651476128416800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-mysql-security-check-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6232651476128416800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6232651476128416800'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-mysql-security-check-with.html' title='[Level 2] MySQL security check with tcpdump.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3972761026295220174</id><published>2011-11-22T15:06:00.002+08:00</published><updated>2011-11-22T15:08:04.226+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Simulation'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] Pythonbrew, the Python environment management tool.</title><content type='html'>The more info, please click &lt;a href='https://github.com/utahta/pythonbrew'&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The Chinese resource from OpenFoundry, click &lt;a href="http://www.openfoundry.org/tw/tech-column/8516-pythons-virtual-environment-and-multi-version-programming-tools-virtualenv-and-pythonbrew#.Tss8Vv7VQRw.mailto"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3972761026295220174?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3972761026295220174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-pythonbrew-python-environment.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3972761026295220174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3972761026295220174'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-pythonbrew-python-environment.html' title='[Level 3] Pythonbrew, the Python environment management tool.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6534482271249153081</id><published>2011-11-21T14:21:00.001+08:00</published><updated>2011-11-21T14:27:07.796+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='JavaSE8'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>[Level 3] Slides from Devoxx talk on Language / Library / VM Co-Evolution.</title><content type='html'>Slides from Devoxx talk on Language / Library / VM Co-Evolution,&lt;br /&gt;more info, please click &lt;a href="http://blogs.oracle.com/briangoetz/entry/slides_from_devoxx_talk_on"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6534482271249153081?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6534482271249153081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-slides-from-devoxx-talk-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6534482271249153081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6534482271249153081'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-slides-from-devoxx-talk-on.html' title='[Level 3] Slides from Devoxx talk on Language / Library / VM Co-Evolution.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7916805132386949241</id><published>2011-11-21T14:16:00.000+08:00</published><updated>2011-11-21T14:16:37.021+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 3] The bonding info of Linux</title><content type='html'>The bonding info of Linux, click &lt;a href="http://www.linuxfoundation.org/collaborate/workgroups/networking/bonding"&gt;here&lt;/a&gt; for more detail.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7916805132386949241?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7916805132386949241/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-bonding-info-of-linux.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7916805132386949241'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7916805132386949241'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-bonding-info-of-linux.html' title='[Level 3] The bonding info of Linux'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2979146272272036031</id><published>2011-11-18T16:20:00.001+08:00</published><updated>2011-11-18T16:22:41.837+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Pydoc, the document of Python.</title><content type='html'>In Java, we have javadoc to generate the document,&lt;br /&gt;in Python, we have pydoc.&lt;br /&gt;More info, please click &lt;a href="http://lfw.org/python/pydoc.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The sample of pydoc as the following:&lt;br /&gt;&lt;br /&gt;The source code of testPyDoc.py&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/python&lt;br /&gt;&lt;br /&gt;"""&lt;br /&gt;This is a sample module to generate pydoc&lt;br /&gt;"""&lt;br /&gt;__author__ =  'Stanley Huang'&lt;br /&gt;__version__=  '1.0'&lt;br /&gt;&lt;br /&gt;class PyDoc:&lt;br /&gt;    """class docstrings"""&lt;br /&gt;    def __init__ (self, user='guest', addr='Taipei'):&lt;br /&gt;        """Set default attribute values only&lt;br /&gt;        Keyword arguments:&lt;br /&gt;        user -- name of user&lt;br /&gt;        addr -- addr of user&lt;br /&gt;        """&lt;br /&gt;        self.user = user&lt;br /&gt;        self.addr = addr&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ pydoc testPydoc&lt;br /&gt;Help on module testPyDoc:&lt;br /&gt;&lt;br /&gt;NAME&lt;br /&gt;    testPyDoc - This is a sample module to generate pydoc&lt;br /&gt;&lt;br /&gt;FILE&lt;br /&gt;    /tmp/testPyDoc.py&lt;br /&gt;&lt;br /&gt;CLASSES&lt;br /&gt;    PyDoc&lt;br /&gt;    &lt;br /&gt;    class PyDoc&lt;br /&gt;     |  class docstrings&lt;br /&gt;     |  &lt;br /&gt;     |  Methods defined here:&lt;br /&gt;     |  &lt;br /&gt;     |  __init__(self, user='guest', addr='Taipei')&lt;br /&gt;     |      Set default attribute values only&lt;br /&gt;     |      Keyword arguments:&lt;br /&gt;     |      user -- name of user&lt;br /&gt;     |      addr -- addr of user&lt;br /&gt;&lt;br /&gt;DATA&lt;br /&gt;    __author__ = 'Stanley Huang'&lt;br /&gt;    __version__ = '1.0'&lt;br /&gt;&lt;br /&gt;VERSION&lt;br /&gt;    1.0&lt;br /&gt;&lt;br /&gt;AUTHOR&lt;br /&gt;    Stanley Huang&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2979146272272036031?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2979146272272036031/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-pydoc-document-of-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2979146272272036031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2979146272272036031'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-pydoc-document-of-python.html' title='[Level 2] Pydoc, the document of Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4904444275867119537</id><published>2011-11-18T12:16:00.001+08:00</published><updated>2011-11-18T12:17:23.300+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] How to implement AES in Python.</title><content type='html'>A paper for how to implement AES in Python. Please click &lt;a href="http://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Another paper is &lt;a href="http://www.example-code.com/python/aes_pythonEncryptByteArray.asp"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4904444275867119537?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4904444275867119537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-how-to-implement-aes-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4904444275867119537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4904444275867119537'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-how-to-implement-aes-in-python.html' title='[Level 3] How to implement AES in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8825684022342224476</id><published>2011-11-16T23:22:00.001+08:00</published><updated>2011-11-16T23:23:50.116+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Design Pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] IoC/AOP in Python.</title><content type='html'>More Ioc info, please refer to &lt;a href="http://code.google.com/p/pinsor/"&gt;here&lt;/a&gt;.&lt;br /&gt;More AOP info, please refer to &lt;a href="http://www.cs.tut.fi/~ask/aspects/index.shtml"&gt;here&lt;/a&gt;.&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8825684022342224476?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8825684022342224476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-aop-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8825684022342224476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8825684022342224476'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-3-aop-in-python.html' title='[Level 3] IoC/AOP in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7508030037854732594</id><published>2011-11-16T12:41:00.007+08:00</published><updated>2011-11-16T12:54:11.895+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Grub'/><category scheme='http://www.blogger.com/atom/ns#' term='Boot'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 2] How to update Ubuntu boot menu (grub).</title><content type='html'>If you want to modify grub menu of Ubuntu,&lt;br /&gt;you have following steps to do:&lt;br /&gt;1. Modify default grub configuration file.&lt;br /&gt;# vi /etc/default/grub&lt;br /&gt;2. Update grub configuration.&lt;br /&gt;# update-grub&lt;br /&gt;Generating grub.cfg ...&lt;br /&gt;Found linux image: /boot/vmlinuz-2.6.38-12-generic&lt;br /&gt;Found initrd image: /boot/initrd.img-2.6.38-12-generic&lt;br /&gt;Found linux image: /boot/vmlinuz-2.6.38-8-generic&lt;br /&gt;Found initrd image: /boot/initrd.img-2.6.38-8-generic&lt;br /&gt;Found memtest86+ image: /boot/memtest86+.bin&lt;br /&gt;Found Windows Recovery Environment (loader) on /dev/sda1&lt;br /&gt;Found Windows 7 (loader) on /dev/sda2&lt;br /&gt;done&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;More info. please refer to &lt;a href="https://help.ubuntu.com/community/Grub2"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7508030037854732594?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7508030037854732594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-how-to-update-ubuntu-boot-menu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7508030037854732594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7508030037854732594'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-how-to-update-ubuntu-boot-menu.html' title='[Level 2] How to update Ubuntu boot menu (grub).'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-5269227140046263230</id><published>2011-11-11T14:18:00.002+08:00</published><updated>2011-11-11T14:44:11.054+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] classmethod, staticmethod, abstractmethod decorators in Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;from abc import *&lt;br /&gt;&lt;br /&gt;class p(object):&lt;br /&gt;    __metaclass__ = ABCMeta&lt;br /&gt;&lt;br /&gt;    @abstractmethod&lt;br /&gt;    def printz(self):&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    @abstractproperty&lt;br /&gt;    def x(self):&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;class o(p):&lt;br /&gt;    def __init__(self, n=10):&lt;br /&gt;        self._x = n &lt;br /&gt;&lt;br /&gt;    def printX(self):&lt;br /&gt;        print self._x&lt;br /&gt;&lt;br /&gt;    def printx(self):&lt;br /&gt;        print self.x&lt;br /&gt;&lt;br /&gt;    @classmethod&lt;br /&gt;    def printy(self):&lt;br /&gt;        print self.x&lt;br /&gt;&lt;br /&gt;    @staticmethod&lt;br /&gt;    def printz():&lt;br /&gt;        print 'x' &lt;br /&gt;&lt;br /&gt;    @property&lt;br /&gt;    def x(self):&lt;br /&gt;        return self._x&lt;br /&gt;&lt;br /&gt;    @x.setter&lt;br /&gt;    def x(self, times):&lt;br /&gt;        self._x = self._x * times&lt;br /&gt;&lt;br /&gt;    @x.getter&lt;br /&gt;    def x(self):&lt;br /&gt;        return self._x&lt;br /&gt;&lt;br /&gt;a = o(2)&lt;br /&gt;a.x = 5&lt;br /&gt;print a.x&lt;br /&gt;a.printX()&lt;br /&gt;a.printx()&lt;br /&gt;a.printy()&lt;br /&gt;a.printz()&lt;br /&gt;&lt;br /&gt;#o.printX() # error&lt;br /&gt;#o.printx() # error&lt;br /&gt;o.printy()&lt;br /&gt;o.printz()&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./t.py &lt;br /&gt;10&lt;br /&gt;10&lt;br /&gt;10&lt;br /&gt;&amp;lt;property object at 0x177a1b0&amp;gt;&lt;br /&gt;x&lt;br /&gt;&amp;lt;property object at 0x177a1b0&amp;gt;&lt;br /&gt;x&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-5269227140046263230?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/5269227140046263230/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-classmethod-staticmethod.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5269227140046263230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5269227140046263230'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-2-classmethod-staticmethod.html' title='[Level 2] classmethod, staticmethod, abstractmethod decorators in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8531757329375698387</id><published>2011-11-02T16:17:00.001+08:00</published><updated>2011-11-02T16:19:21.231+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='usb2com'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] Login server console with minicom on Ubuntu laptop.</title><content type='html'>If you want to use console to login server on Ubuntu laptop,&lt;br /&gt;you could try a useful app named "minicom".&lt;br /&gt;And you could download in by apt-get.&lt;br /&gt;# apt-get -y install minicom&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8531757329375698387?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8531757329375698387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-1-login-server-console-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8531757329375698387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8531757329375698387'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/11/level-1-login-server-console-with.html' title='[Level 1] Login server console with minicom on Ubuntu laptop.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-208148747783989909</id><published>2011-10-27T19:05:00.003+08:00</published><updated>2011-10-27T19:08:49.098+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='System'/><title type='text'>[Level 1] Get partition uuid on Ubuntu.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;# blkid&lt;br /&gt;/dev/sda1: UUID="05580ede-bec4-44ae-b1a5-8e8c7b2e7c58" TYPE="ext4" &lt;br /&gt;/dev/sda2: UUID="3df58602-322b-437a-b65c-de21293f6840" TYPE="swap" &lt;br /&gt;/dev/sda5: UUID="5417e3d4-4b7d-4a79-a58a-a53cbeab6112" TYPE="ext4"&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-208148747783989909?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/208148747783989909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-get-partition-uuid-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/208148747783989909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/208148747783989909'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-get-partition-uuid-on-ubuntu.html' title='[Level 1] Get partition uuid on Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4074939797010438127</id><published>2011-10-27T12:47:00.004+08:00</published><updated>2011-10-27T15:19:54.244+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='System'/><title type='text'>[Level 1] Backup directories by cpio.</title><content type='html'>&lt;pre class="prettyprint lang-sh linenums:1"&gt;#!/bin/bash&lt;br /&gt;source=$1&lt;br /&gt;target=$2&lt;br /&gt;(cd $source; find . -print | cpio -ocv) | (cd $target; cpio -icuvd)&lt;br /&gt;# cd $source; find . -print | cpio -ocv &gt; /tmp/tmp.cpio&lt;br /&gt;# cd $target; cpio -icuvd &lt; /tmp/tmp.cpio&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4074939797010438127?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4074939797010438127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-copy-directory-by-cpio.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4074939797010438127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4074939797010438127'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-copy-directory-by-cpio.html' title='[Level 1] Backup directories by cpio.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-5948459142008851431</id><published>2011-10-17T14:57:00.005+08:00</published><updated>2011-10-17T23:00:09.732+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Games'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 2] Rock-Paper-Scissors</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import random&lt;br /&gt;RPS = { 'Rock' : 1, 'Paper' : 2, 'Scissors' : 3 } &lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    comRPS = random.choice(RPS.keys())&lt;br /&gt;    com = RPS[comRPS]&lt;br /&gt;    youRPS = raw_input('Rock/Paper/Scissors: ')&lt;br /&gt;    you = RPS[youRPS]&lt;br /&gt;    print 'Com: %s' % comRPS&lt;br /&gt;    print 'You: %s' % youRPS&lt;br /&gt;    if com % len(RPS.keys()) ＋ 1 == you:&lt;br /&gt;        print 'You wins!'&lt;br /&gt;    elif you % len(RPS.keys()) ＋ 1 == com:&lt;br /&gt;        print 'Com win!'&lt;br /&gt;    else:&lt;br /&gt;        print 'Break even!'&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-5948459142008851431?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/5948459142008851431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-rock-paper-scissors.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5948459142008851431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5948459142008851431'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-rock-paper-scissors.html' title='[Level 2] Rock-Paper-Scissors'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8707047784628513391</id><published>2011-10-17T09:49:00.001+08:00</published><updated>2011-10-27T11:21:17.070+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] map, reduce and filter methods in Python</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;a = [1,2,3,4,5,6,7,8,9]&lt;br /&gt;b = [1,2,3,4]&lt;br /&gt;c = [5,6,7,8]&lt;br /&gt; &lt;br /&gt;print filter(lambda x: x&gt;5, a)&lt;br /&gt;print map(lambda x,y: x+y, b, c)&lt;br /&gt;print map(lambda x,y: bool(x) and bool(y), a, b)&lt;br /&gt;print map(lambda x,y: bool(x) or bool(y), b, a)&lt;br /&gt;print reduce(lambda x,y: x+y, a)&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ /tmp/t.py &lt;br /&gt;[6, 7, 8, 9]&lt;br /&gt;[6, 8, 10, 12]&lt;br /&gt;[True, True, True, True, False, False, False, False, False]&lt;br /&gt;[True, True, True, True, True, True, True, True, True]&lt;br /&gt;45&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8707047784628513391?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8707047784628513391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-map-reduce-and-filter-methods.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8707047784628513391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8707047784628513391'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-map-reduce-and-filter-methods.html' title='[Level 2] map, reduce and filter methods in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-67299437580426007</id><published>2011-10-16T20:51:00.000+08:00</published><updated>2011-10-16T20:51:14.381+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] The sample of functools.partial() in Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import functools&lt;br /&gt;try:&lt;br /&gt;print int('10')    ## equiv: print int('10', base=10)&lt;br /&gt;print int('10', 2) ## equiv: print int('10', base=2)&lt;br /&gt;int2 = functools.partial(int, 2) ## no default bonding parameter.&lt;br /&gt;print int2('10')   ## fail, must assign the value of base&lt;br /&gt;int2 = functools.partial(int, base=2) ## set default base to 2&lt;br /&gt;print int2('10')   ## equiv: print int2('10', base=2)&lt;br /&gt;print int2('10', 10) ## fail, TypeError: keyword parameter 'base' was given by position and by name&lt;br /&gt;print int2('10', base=10)&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-67299437580426007?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/67299437580426007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-sample-of-functoolspartial-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/67299437580426007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/67299437580426007'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-sample-of-functoolspartial-in.html' title='[Level 2] The sample of functools.partial() in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-9060210843328691335</id><published>2011-10-14T14:19:00.002+08:00</published><updated>2011-10-27T14:57:38.678+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to implement Enum in Python</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;class CreateRemove:&lt;br /&gt;    Create = 1&lt;br /&gt;    Remove = 2&lt;br /&gt;&lt;br /&gt;class AllowDeny:&lt;br /&gt;    Allow = 1&lt;br /&gt;    Deny = 2&lt;br /&gt;&lt;br /&gt;print CreateRemove.Create&lt;br /&gt;print AllowDeny.Deny&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-9060210843328691335?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/9060210843328691335/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-how-to-implement-enum-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9060210843328691335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9060210843328691335'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-how-to-implement-enum-in-python.html' title='[Level 2] How to implement Enum in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1887478273608880883</id><published>2011-10-14T14:02:00.000+08:00</published><updated>2011-10-14T14:02:36.924+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ssh'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><title type='text'>[Level 1] Restrict user login in ssh.</title><content type='html'>You can use AllowUsers/AllowGroups/DenyUsers/DenyGroups in sshd_config to limit user login.&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# cat /etc/ssh/sshd_config&lt;br /&gt;AllowUsers user1&lt;br /&gt;AllowGroups group1&lt;br /&gt;DenyUsers user2&lt;br /&gt;DenyGroups group2&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1887478273608880883?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1887478273608880883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-restrict-user-login-in-ssh.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1887478273608880883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1887478273608880883'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-restrict-user-login-in-ssh.html' title='[Level 1] Restrict user login in ssh.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6929643554354964528</id><published>2011-10-11T11:44:00.000+08:00</published><updated>2011-10-11T11:44:48.149+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to execute super() in Python</title><content type='html'>If you want to use parent method in Python,&lt;br /&gt;you could use 'super()' method.&lt;br /&gt;But it only support new style class,&lt;br /&gt;therefore, you need to inherit 'object' class when you create your own class.&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import os, sys &lt;br /&gt; &lt;br /&gt;def new_style():&lt;br /&gt;    class NewSystemTools(object):&lt;br /&gt;        def __init__(self):&lt;br /&gt;            pass&lt;br /&gt;        &lt;br /&gt;        def runCmd(self, sCmd):&lt;br /&gt;            return os.popen(sCmd).read()&lt;br /&gt;     &lt;br /&gt;    class MyNewSystemTools(NewSystemTools):&lt;br /&gt;        def __init__(self):&lt;br /&gt;            pass&lt;br /&gt;        &lt;br /&gt;        def runCmd(self, sCmd):&lt;br /&gt;            return super(MyNewSystemTools, self).runCmd(sCmd)&lt;br /&gt;&lt;br /&gt;    print '-- new style --' &lt;br /&gt;    mnst = MyNewSystemTools()&lt;br /&gt;    print mnst.runCmd('ls /')&lt;br /&gt; &lt;br /&gt;def old_style(): &lt;br /&gt;    class SystemTools:&lt;br /&gt;        def __init__(self):&lt;br /&gt;            pass&lt;br /&gt;    &lt;br /&gt;        def runCmd(self, sCmd):&lt;br /&gt;            return os.popen(sCmd).read()&lt;br /&gt;    &lt;br /&gt;    class MySystemTools(SystemTools):&lt;br /&gt;        def __init__(self):&lt;br /&gt;            pass&lt;br /&gt;    &lt;br /&gt;        def runCmd(self, sCmd):&lt;br /&gt;            return super(MySystemTools, self).runCmd(sCmd)&lt;br /&gt;    &lt;br /&gt;    print '-- old style --'&lt;br /&gt;    mst = MySystemTools()&lt;br /&gt;    print mst.runCmd('ls /')&lt;br /&gt; &lt;br /&gt;new_style()&lt;br /&gt;old_style()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;# /tmp/t.py &lt;br /&gt;-- new style --&lt;br /&gt;bin&lt;br /&gt;boot&lt;br /&gt;cdrom&lt;br /&gt;data&lt;br /&gt;dev&lt;br /&gt;etc&lt;br /&gt;filedb&lt;br /&gt;...&lt;br /&gt;-- old style --&lt;br /&gt;Traceback (most recent call last):&lt;br /&gt;  File "/tmp/t.py", line 17, in &lt;module&gt;&lt;br /&gt;    print mst.runCmd('ls /')&lt;br /&gt;  File "/tmp/t.py", line 14, in runCmd&lt;br /&gt;    return super(MySystemTools, self).runCmd(sCmd)&lt;br /&gt;TypeError: super() argument 1 must be type, not classobj&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6929643554354964528?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6929643554354964528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-how-to-execute-super-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6929643554354964528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6929643554354964528'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-how-to-execute-super-in-python.html' title='[Level 2] How to execute super() in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-9152477907329303053</id><published>2011-10-08T03:28:00.001+08:00</published><updated>2011-10-10T00:03:10.327+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[ Level 2] How to dump object to file in Python</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python    &lt;br /&gt;import os, sys &lt;br /&gt;&lt;br /&gt;import marshal&lt;br /&gt;a = [1,2,3]&lt;br /&gt;fd = open('/tmp/t.log', 'wb')&lt;br /&gt;marshal.dump(a, fd) &lt;br /&gt;fd.close()&lt;br /&gt;&lt;br /&gt;fd = open('/tmp/t.log', 'rb')&lt;br /&gt;b = marshal.load(fd)&lt;br /&gt;for i in b:&lt;br /&gt;    print i&lt;br /&gt;fd.close()&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-9152477907329303053?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/9152477907329303053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-write-sample-of-init-script.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9152477907329303053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9152477907329303053'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-write-sample-of-init-script.html' title='[ Level 2] How to dump object to file in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3737626944094695896</id><published>2011-10-08T01:52:00.000+08:00</published><updated>2011-10-08T01:52:25.034+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Vim'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Vim autocomplete for python.</title><content type='html'>If you want to use vim to writing python script.&lt;br /&gt;You could download vim autocomplete for python from &lt;a href="http://www.vim.org/scripts/script.php?script_id=1542"&gt;here&lt;/a&gt;&lt;br /&gt;And then, you could put pythoncomplete.vim in ~/.vim/autoload/&lt;br /&gt;When you writing python, you could use ctrl+p to autocomplete python syntax.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3737626944094695896?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3737626944094695896/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-vim-autocomplete-for-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3737626944094695896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3737626944094695896'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-2-vim-autocomplete-for-python.html' title='[Level 2] Vim autocomplete for python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8564165779871805097</id><published>2011-10-08T01:47:00.001+08:00</published><updated>2011-10-08T02:04:46.829+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Vim'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><title type='text'>[Level 1] Useful vim environment settings.</title><content type='html'>My current vim settings are below.&lt;br /&gt;You could get more sample in &lt;a href="http://www.kunli.info/2007/04/25/vimrc/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;set nu&lt;br /&gt;set ic&lt;br /&gt;:au BufReadPost * if line("'\"") &gt; 1 &amp;&amp; line("'\"") &lt;= line("$") | exe "normal! g'\"" | endif &lt;br /&gt;set nosmartindent&lt;br /&gt;set tabstop=4&lt;br /&gt;set shiftwidth=4&lt;br /&gt;set expandtab&lt;br /&gt;set hlsearch&lt;br /&gt;syntax on&lt;br /&gt;filetype indent plugin on&lt;br /&gt;set background=dark&lt;br /&gt;set modeline&lt;br /&gt;" filetype indent on&lt;br /&gt;" au FileType python setlocal tabstop=8 expandtab shiftwidth=4 softtabstop=4&lt;br /&gt;" au FileType python setlocal ts=8 et sw=4 sts=4&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8564165779871805097?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8564165779871805097/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-useful-vim-environment-settings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8564165779871805097'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8564165779871805097'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-useful-vim-environment-settings.html' title='[Level 1] Useful vim environment settings.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4202987275721399420</id><published>2011-10-05T10:02:00.002+08:00</published><updated>2011-10-05T10:04:49.390+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 1] Encoding in Python script.</title><content type='html'>If there are some wording not for ascii, you should add # -*- coding: (encoding) -*-&lt;br /&gt;to prevent compile error.&lt;br /&gt;example error message:&lt;br /&gt;File "./testEncoding.py", line 21&lt;br /&gt;SyntaxError: Non-ASCII character '\xe6' in file ./testForLoop_2.6.py on line 21, but no encoding declared; see &lt;a href="http://www.python.org/peps/pep-0263.html"&gt;http://www.python.org/peps/pep-0263.html&lt;/a&gt; for details&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/python2.6&lt;br /&gt;# -*- coding: utf8 -*-&lt;br /&gt;&lt;br /&gt;### chinese testing&lt;br /&gt;slang="有嘴說別人無嘴說自己"&lt;br /&gt;sword="嘴"&lt;br /&gt;&lt;br /&gt;## error with encoding&lt;br /&gt;#for i in slang:&lt;br /&gt;#  print i&lt;br /&gt;&lt;br /&gt;# use python shell to display encoding&lt;br /&gt;# ex.&lt;br /&gt;# &amp;gt;&amp;gt;&amp;gt; "有嘴說別人無嘴說自己"&lt;br /&gt;# '\xe6\x9c\x89\xe5\x98\xb4\xe8\xaa\xaa\xe5\x88\xa5\xe4\xba\xba\xef\xbc\x8c\xe7\x84\xa1\xe5\x98\xb4\xe8\xaa\xaa\xe8\x87\xaa\xe5\xb7\xb1\xe3\x80\x82'&lt;br /&gt;# &gt;&gt;&gt; "嘴"&lt;br /&gt;# '\xe5\x98\xb4'&lt;br /&gt;&lt;br /&gt;l=len(sword)&lt;br /&gt;h=0&lt;br /&gt;k=0&lt;br /&gt;count=0&lt;br /&gt;for item in slang:&lt;br /&gt;  k=0&lt;br /&gt;  f=1&lt;br /&gt;  while k&amp;lt;l:&lt;br /&gt;    if slang[h+k]==sword[k]:&lt;br /&gt;      k+=1&lt;br /&gt;      continue&lt;br /&gt;    else:&lt;br /&gt;      f=0&lt;br /&gt;      break&lt;br /&gt;  if f==1:&lt;br /&gt;    count+=1&lt;br /&gt;  h+=1&lt;br /&gt;  if h&amp;gt;=(len(slang)-l):&lt;br /&gt;    break&lt;br /&gt;print count&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testEncoding.py &lt;br /&gt;2&lt;br /&gt;$&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4202987275721399420?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4202987275721399420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-encoding-in-python-script.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4202987275721399420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4202987275721399420'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-encoding-in-python-script.html' title='[Level 1] Encoding in Python script.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3885817271234129937</id><published>2011-10-04T14:15:00.000+08:00</published><updated>2011-10-04T14:15:48.694+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 1] Install telnetd in Ubuntu 10.04</title><content type='html'>Install telnetd in Ubuntu 10.04:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# sudo su&lt;br /&gt;# apt-get install openbsd-inetd&lt;br /&gt;# echo "telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetd" &gt;&gt; /etc/inetd.conf&lt;br /&gt;# /etc/init.d/openbsd-inetd restart&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3885817271234129937?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3885817271234129937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-install-telnetd-in-ubuntu-1004.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3885817271234129937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3885817271234129937'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/10/level-1-install-telnetd-in-ubuntu-1004.html' title='[Level 1] Install telnetd in Ubuntu 10.04'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1755297621580188823</id><published>2011-09-29T12:40:00.013+08:00</published><updated>2012-01-12T21:19:05.596+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] More decorator samples.</title><content type='html'>There is a good website to demo decorator sample codes. &lt;a href="http://wiki.python.org/moin/PythonDecoratorLibrary"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@deprecated&lt;br /&gt;def func(): ...&lt;br /&gt;'''&lt;br /&gt;class deprecated:&lt;br /&gt;    def __init__(self, func):&lt;br /&gt;        self.func = func&lt;br /&gt;        self.__name__ = self.func.__name__&lt;br /&gt;        self.__doc__ = self.func.__doc__&lt;br /&gt;        self.__dict__.update(self.func.__dict__)&lt;br /&gt;        pass&lt;br /&gt;    &lt;br /&gt;    """This is a decorator which can be used to mark functions&lt;br /&gt;    as deprecated. It will result in a warning being emitted&lt;br /&gt;    when the function is used."""&lt;br /&gt;    def __call__(self, *args, **kwargs):&lt;br /&gt;        msg = "Call to deprecated function %s()." % self.func.__name__&lt;br /&gt;        ## Suppressing Warnings&lt;br /&gt;        warnings.simplefilter("ignore")&lt;br /&gt;        warnings.warn(msg, category=DeprecationWarning)&lt;br /&gt;        ## Delete ignore filter &lt;br /&gt;        del warnings.filters[0]&lt;br /&gt;        (tmpDebug2Console, libcommon.bDebug2Console) = (libcommon.bDebug2Console, False)&lt;br /&gt;        libcommon.debug(msg, logfile='deprecated.log')&lt;br /&gt;        libcommon.bDebug2Console = tmpDebug2Console&lt;br /&gt;        return self.func(*args, **kwargs)&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;#{case 1}&lt;br /&gt;libdecorator.func_state_flag_default = True/False/None&lt;br /&gt;libdecorator.func_state_flag_test = True/False/None&lt;br /&gt;libdecorator.func_state_flag = True/False/None&lt;br /&gt;@funcState()&lt;br /&gt;@funcState(func_set='test')&lt;br /&gt;@funcState(func_set='test', skip_return_value=True)&lt;br /&gt;def func(): ...&lt;br /&gt;&lt;br /&gt;#{case 2}&lt;br /&gt;@funcEnabled&lt;br /&gt;def func(): ...&lt;br /&gt;&lt;br /&gt;#{case 3}&lt;br /&gt;@funcDisabled&lt;br /&gt;def func(): ...&lt;br /&gt;&lt;br /&gt;#{case 4}&lt;br /&gt;@funcSkipped(True/False/...)&lt;br /&gt;def func(): ...&lt;br /&gt;'''&lt;br /&gt;#global func_state_flag&lt;br /&gt;#func_state_flag=None&lt;br /&gt;class funcState:&lt;br /&gt;    def __init__(self, func_set='default', skip_return_value=True):&lt;br /&gt;        self.func_set = func_set&lt;br /&gt;        self.skip_return_value = skip_return_value&lt;br /&gt;        &lt;br /&gt;    def __call__(self, func):            &lt;br /&gt;        if 'func_state_flag_%s' % self.func_set in locals():&lt;br /&gt;            self.func_state_flag = locals()['func_state_flag_%s' % self.func_set]&lt;br /&gt;        elif 'func_state_flag_%s' % self.func_set in globals():&lt;br /&gt;            self.func_state_flag = globals()['func_state_flag_%s' % self.func_set]&lt;br /&gt;        elif 'func_state_flag' in locals():&lt;br /&gt;            self.func_state_flag = locals()['func_state_flag']&lt;br /&gt;        elif 'func_state_flag' in globals():&lt;br /&gt;            self.func_state_flag = globals()['func_state_flag']&lt;br /&gt;        else:&lt;br /&gt;            self.func_state_flag = True&lt;br /&gt;        &lt;br /&gt;        self.func_enabled = funcEnabled()&lt;br /&gt;        self.func_disabled = funcDisabled(func.__name__)&lt;br /&gt;        self.func_skipped = funcSkipped(self.skip_return_value)&lt;br /&gt;&lt;br /&gt;        funcState = {True: self.func_enabled,&lt;br /&gt;                     False: self.func_disabled,&lt;br /&gt;                     None: self.func_skipped&lt;br /&gt;                     }[self.func_state_flag]&lt;br /&gt;&lt;br /&gt;        @funcState&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kwargs):&lt;br /&gt;            return func(*args, **kwargs)&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;class funcEnabled:&lt;br /&gt;    def __init__(self):&lt;br /&gt;        pass&lt;br /&gt;    &lt;br /&gt;    "This decorator enables the provided function, and does nothing."&lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        return func&lt;br /&gt;&lt;br /&gt;class funcDisabled:&lt;br /&gt;    def __init__(self, func_name=None):&lt;br /&gt;        self.func_name = func_name&lt;br /&gt;        pass&lt;br /&gt;    &lt;br /&gt;    "This decorator disables the provided function, and does nothing."&lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        func_name = self.func_name if self.func_name else func.__name__&lt;br /&gt;        assert False, 'function %s() is disabled!' % func_name&lt;br /&gt;&lt;br /&gt;class funcSkipped:&lt;br /&gt;    def __init__(self, return_value=True):&lt;br /&gt;        self.return_value = return_value&lt;br /&gt;        pass&lt;br /&gt;    &lt;br /&gt;    "This decorator skip the provided function, and return the specific value."&lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kwargs):&lt;br /&gt;            return self.return_value&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;#{case 1}&lt;br /&gt;libdecorator.bIgnoreYN = True/False&lt;br /&gt;self.bIgnoreYN = True/False&lt;br /&gt;@yn('Are these correct?', continue_flag='yes', exit_program=True, return_type=(yn/tf/value), continue_message='continue message!', exit_message='exit message!')&lt;br /&gt;def test():&lt;br /&gt;  print 'test()'&lt;br /&gt;  ## return True/'yes' for @libdecorator.yn()&lt;br /&gt;  return True/'yes'&lt;br /&gt;&lt;br /&gt;#{case 2}&lt;br /&gt;class ctest:&lt;br /&gt;  def __init__(self):&lt;br /&gt;    self.bIgnoreYN = False&lt;br /&gt;    pass&lt;br /&gt;&lt;br /&gt;  @yn('Are these correct?', continue_flag='yes', exit_program=True, return_type=(yn/tf/value), continue_message='continue message!', exit_message='exit message!')&lt;br /&gt;  def test(self):&lt;br /&gt;    print 'ctest.test()'&lt;br /&gt;    ## return True/'yes' for @libdecorator.yn()&lt;br /&gt;    return True/'yes'&lt;br /&gt;'''&lt;br /&gt;class yn:&lt;br /&gt;    def __init__(self, prompt, continue_flag='yes', exit_program=True, return_type='value', continue_message=None, exit_message=None):&lt;br /&gt;        self.prompt = prompt&lt;br /&gt;        self.continue_flag = continue_flag&lt;br /&gt;        self.exit_program = exit_program&lt;br /&gt;        self.return_type = return_type&lt;br /&gt;        self.continue_message = continue_message&lt;br /&gt;        self.exit_message = exit_message&lt;br /&gt;        &lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        yes = 'YES' if self.continue_flag.lower() == 'yes' else 'yes'&lt;br /&gt;        no = 'NO' if self.continue_flag.lower() == 'no' else 'no'&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kwargs):&lt;br /&gt;            sReturn = func(*args, **kwargs)&lt;br /&gt;&lt;br /&gt;            ## check attribute of instance&lt;br /&gt;            if args and isinstance(args[0], object) and hasattr(args[0], 'bIgnoreYN'):&lt;br /&gt;                o = args[0]&lt;br /&gt;                bIgnoreYN = o.bIgnoreYN&lt;br /&gt;            else:&lt;br /&gt;                ## check global/local variable&lt;br /&gt;                if 'bIgnoreYN' in locals():&lt;br /&gt;                    bIgnoreYN = locals()['bIgnoreYN']&lt;br /&gt;                elif 'bIgnoreYN' in globals():&lt;br /&gt;                    bIgnoreYN = globals()['bIgnoreYN']&lt;br /&gt;                else:&lt;br /&gt;                    bIgnoreYN = False&lt;br /&gt;            ## filter ignore flag and set default to False&lt;br /&gt;            if bIgnoreYN not in (True, False):&lt;br /&gt;                bIgnoreYN = False&lt;br /&gt;            &lt;br /&gt;            while not bIgnoreYN:&lt;br /&gt;                bh = libinterrupt.BreakHandler(-1)&lt;br /&gt;                bh.enable()&lt;br /&gt;                try:&lt;br /&gt;                    yn = raw_input('%s [%s/%s]: ' % (self.prompt, yes, no))&lt;br /&gt;                except EOFError:&lt;br /&gt;                    yn = None&lt;br /&gt;                bh.disable()&lt;br /&gt;                    &lt;br /&gt;                if yn.lower() in ('yes', 'no'):&lt;br /&gt;                    if yn.lower() == self.continue_flag.lower():&lt;br /&gt;                        if self.continue_message: print self.continue_message&lt;br /&gt;                    else:&lt;br /&gt;                        if self.exit_message: print self.exit_message&lt;br /&gt;                        if self.exit_program: exit(1)&lt;br /&gt;                    break&lt;br /&gt;                else:&lt;br /&gt;                    print 'Only accept %s/%s!' % (yes, no)&lt;br /&gt;            &lt;br /&gt;            if bIgnoreYN:&lt;br /&gt;                return sReturn&lt;br /&gt;            else:&lt;br /&gt;                if self.return_type.lower() == 'yn':&lt;br /&gt;                    sReturn = yn.lower()&lt;br /&gt;                elif self.return_type.lower() == 'tf':&lt;br /&gt;                    sReturn = True if yn.lower() == self.continue_flag else False&lt;br /&gt;                elif self.return_type.lower() == 'value':&lt;br /&gt;                    pass&lt;br /&gt;                else:&lt;br /&gt;                    assert False, 'Error return type(%s)!' % self.return_type&lt;br /&gt;                return sReturn&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@checkUnixPassword()&lt;br /&gt;@checkUnixPassword('success_message', 'fail_message', 'admin')&lt;br /&gt;def test(): ...&lt;br /&gt;'''&lt;br /&gt;class checkUnixPassword:&lt;br /&gt;    def __init__(self, success_message=None, fail_message=None, user=None):&lt;br /&gt;        self.success_message = success_message&lt;br /&gt;        self.fail_message = fail_message&lt;br /&gt;        self.user = user if user else libresourcemanager.getAccountName()&lt;br /&gt;&lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kwargs):&lt;br /&gt;            passwd = getpass.getpass("Please enter %s's password: " % self.user).rstrip()&lt;br /&gt;        &lt;br /&gt;            ## get password field from shadow file&lt;br /&gt;            sp = libcommon.shadowPassword()&lt;br /&gt;            sp.setPasswordField(self.user)&lt;br /&gt;        &lt;br /&gt;            ## get password from crypt algorithm&lt;br /&gt;            up = libcommon.unixPasswordEncryptor(passwd, sp.getPasswordEncryptType(), sp.getPasswordSalt())        &lt;br /&gt;            if not sp.getPasswordField(self.user) == up.getPasswordField():&lt;br /&gt;                if self.fail_message: print self.fail_message&lt;br /&gt;                exit(1)&lt;br /&gt;            else:&lt;br /&gt;                if self.success_message: print self.success_message&lt;br /&gt;                return func(*args, **kwargs)&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@checkCLIPassword()&lt;br /&gt;@checkCLIPassword('success_message', 'fail_message')&lt;br /&gt;def test(): ...&lt;br /&gt;'''&lt;br /&gt;class checkCLIPassword:&lt;br /&gt;    def __init__(self, success_message=None, fail_message=None):&lt;br /&gt;        self.success_message = success_message&lt;br /&gt;        self.fail_message = fail_message&lt;br /&gt;        self.ENABLE_PASSWORD_FLAG_FILE = '/opt/ruckuswireless/wsg/conf/enable_password.done'&lt;br /&gt;&lt;br /&gt;    def getEncyptCLIPasswd(self):&lt;br /&gt;        cmd = 'head -1 %s' % self.ENABLE_PASSWORD_FLAG_FILE&lt;br /&gt;        return os.popen(cmd).read().strip()&lt;br /&gt;&lt;br /&gt;    def encryptPasswd(self, plain_text):&lt;br /&gt;        return  hashlib.sha1(plain_text).hexdigest()&lt;br /&gt;&lt;br /&gt;    def isValidCLIPasswd(self, plain_text):&lt;br /&gt;        return self.getEncyptCLIPasswd() == self.encryptPasswd(plain_text)&lt;br /&gt;&lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kwargs):&lt;br /&gt;            passwd = getpass.getpass("Please enter cli password: ").rstrip()&lt;br /&gt;            &lt;br /&gt;            if not self.isValidCLIPasswd(passwd):&lt;br /&gt;                if self.fail_message: print self.fail_message&lt;br /&gt;                exit(1)&lt;br /&gt;            else:&lt;br /&gt;                if self.success_message: print self.success_message&lt;br /&gt;                return func(*args, **kwargs)&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;libdecorator.pek2c_enable_flag = True/False&lt;br /&gt;Usage:&lt;br /&gt;@pek2c() &lt;br /&gt;@pek2c(before_after='before/after', message='message') &lt;br /&gt;@pek2c(before_after='before/after', message='message', confirm_message='confirm_message') &lt;br /&gt;def test(): ...&lt;br /&gt;'''&lt;br /&gt;class pek2c:&lt;br /&gt;    def __init__(self, before_after='after', message='continue', confirm_message=''):&lt;br /&gt;        self.before_after = before_after&lt;br /&gt;        self.confirm_message = confirm_message&lt;br /&gt;        key = 'Enter "%s"' % self.confirm_message if self.confirm_message else 'Press Enter key'&lt;br /&gt;        self.message = '%s to %s... ' % (key, message)&lt;br /&gt;    &lt;br /&gt;    def runPek2c(self, message=''):&lt;br /&gt;        if 'pek2c_enable_flag' in locals():&lt;br /&gt;            pek2c_enable_flag = locals()['pek2c_enable_flag']&lt;br /&gt;        elif 'pek2c_enable_flag' in globals():&lt;br /&gt;            pek2c_enable_flag = globals()['pek2c_enable_flag']&lt;br /&gt;        else:&lt;br /&gt;            pek2c_enable_flag = True&lt;br /&gt;        &lt;br /&gt;        if pek2c_enable_flag:&lt;br /&gt;            while True:&lt;br /&gt;                bh = libinterrupt.BreakHandler(-1)&lt;br /&gt;                bh.enable()&lt;br /&gt;                try:&lt;br /&gt;                    x = raw_input(message)&lt;br /&gt;                except EOFError:&lt;br /&gt;                    x = None&lt;br /&gt;                bh.disable()&lt;br /&gt;                &lt;br /&gt;                if self.confirm_message and x != self.confirm_message:&lt;br /&gt;                    continue&lt;br /&gt;                else:&lt;br /&gt;                    break&lt;br /&gt;    &lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kwargs):&lt;br /&gt;            if self.before_after == 'before': self.runPek2c(self.message)&lt;br /&gt;            sReturn = func(*args, **kwargs)&lt;br /&gt;            if self.before_after == 'after' : self.runPek2c(self.message)&lt;br /&gt;            return sReturn&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@dumpArgs  &lt;br /&gt;def test(a, b, c): ...&lt;br /&gt;'''&lt;br /&gt;class dumpArgs:&lt;br /&gt;    def __init__(self, func):&lt;br /&gt;        self.func = func&lt;br /&gt;        "This decorator dumps out the arguments passed to a function before calling it"&lt;br /&gt;        self.argnames = func.func_code.co_varnames[:func.func_code.co_argcount]&lt;br /&gt;        self.fname = func.func_name&lt;br /&gt;        self.__name__ = func.__name__&lt;br /&gt;        self.__doc__ = func.__doc__&lt;br /&gt;        self.__dict__.update(func.__dict__)&lt;br /&gt;        &lt;br /&gt;    def __call__(self, *args, **kwargs):&lt;br /&gt;        print self.fname, ":", ', '.join(&lt;br /&gt;            '%s=%r' % entry&lt;br /&gt;            for entry in zip(self.argnames,args) + kwargs.items())&lt;br /&gt;        return self.func(*args, **kwargs)&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@retry()&lt;br /&gt;@retry(libdecorator.RetryException, nRetry=3, nDelay=3, nBackOff=2)&lt;br /&gt;def test(a, b, c):&lt;br /&gt;    raise retryException('retry')&lt;br /&gt;'''&lt;br /&gt;class RetryException(Exception):&lt;br /&gt;    def __init__(self, message=''):&lt;br /&gt;        self.__message = message&lt;br /&gt;    &lt;br /&gt;    def __str__(self):&lt;br /&gt;        return self.__message&lt;br /&gt;    pass&lt;br /&gt;&lt;br /&gt;class retry:&lt;br /&gt;    def __init__(self, ExceptionToCheck=RetryException, nRetry=3, nDelay=1, nBackOff=1):&lt;br /&gt;        self.ExceptionToCheck = ExceptionToCheck&lt;br /&gt;        self.nRetry = nRetry&lt;br /&gt;        self.nDelay = nDelay&lt;br /&gt;        self.nBackOff = nBackOff&lt;br /&gt;    &lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kwargs):&lt;br /&gt;            for i in range(1, self.nRetry+1):&lt;br /&gt;                try:&lt;br /&gt;                    sReturn = func(*args, **kwargs)&lt;br /&gt;                    return sReturn&lt;br /&gt;                except self.ExceptionToCheck, e:&lt;br /&gt;                    if i &lt; self.nRetry:&lt;br /&gt;                        print '%s %s time but fail, wait %s sec to continue' % ('Run' if i == 1 else 'Retry', i, self.nDelay)&lt;br /&gt;                        time.sleep(self.nDelay)&lt;br /&gt;                        self.nDelay = self.nDelay * self.nBackOff&lt;br /&gt;                    if i == self.nRetry:&lt;br /&gt;                        raise e&lt;br /&gt;                except Exception, e:&lt;br /&gt;                    raise e&lt;br /&gt;                else:&lt;br /&gt;                    break&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;from threading import Lock&lt;br /&gt;my_lock = Lock()&lt;br /&gt;@synchronized(my_lock)&lt;br /&gt;def test(a, b, c): ...&lt;br /&gt;'''&lt;br /&gt;class synchronized:&lt;br /&gt;    def __init__(self, lock):&lt;br /&gt;        self.lock = lock&lt;br /&gt;    &lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kw):&lt;br /&gt;            self.lock.acquire()&lt;br /&gt;            try:&lt;br /&gt;                return func(*args, **kw)&lt;br /&gt;            finally:&lt;br /&gt;                self.lock.release()&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@fileLockSynchronized('my_lock1')&lt;br /&gt;@fileLockSynchronized('my_lock2', 10, 1)&lt;br /&gt;def test(a, b, c): ...&lt;br /&gt;'''&lt;br /&gt;class fileLockSynchronized:&lt;br /&gt;    def __init__(self, lockfile, timeout=10, delay=1):&lt;br /&gt;        self.lockfile = lockfile&lt;br /&gt;        self.timeout = timeout&lt;br /&gt;        self.delay = delay&lt;br /&gt;    &lt;br /&gt;    def __call__(self, func):&lt;br /&gt;        @functools.wraps(func)&lt;br /&gt;        def wrapped_f(*args, **kw):&lt;br /&gt;            FileLock = libresourcemanager.FileLock(self.lockfile, self.timeout, self.delay)&lt;br /&gt;            try:&lt;br /&gt;                FileLock.acquire()&lt;br /&gt;                return func(*args, **kw)&lt;br /&gt;            finally:&lt;br /&gt;                FileLock.release()&lt;br /&gt;#        wrapped_f.__name__ = func.__name__&lt;br /&gt;#        wrapped_f.__doc__ = func.__doc__&lt;br /&gt;#        wrapped_f.__dict__.update(func.__dict__)&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@saveCurrentWorkingDirectory&lt;br /&gt;def func(): ...&lt;br /&gt;'''&lt;br /&gt;class saveCurrentWorkingDirectory:&lt;br /&gt;    def __init__(self, func):&lt;br /&gt;        self.func = func&lt;br /&gt;        self.__name__ = self.func.__name__&lt;br /&gt;        self.__doc__ = self.func.__doc__&lt;br /&gt;        self.__dict__.update(self.func.__dict__)&lt;br /&gt;        pass&lt;br /&gt;    &lt;br /&gt;    def __call__(self, *args, **kwargs):&lt;br /&gt;        cwd = os.getcwd()&lt;br /&gt;        sReturn = self.func(*args, **kwargs)&lt;br /&gt;        os.chdir(cwd)&lt;br /&gt;        return sReturn&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;Usage:&lt;br /&gt;@singleton&lt;br /&gt;class cls: ...&lt;br /&gt;'''&lt;br /&gt;&lt;br /&gt;'''&lt;br /&gt;def singleton(cls):&lt;br /&gt;    instances = {}&lt;br /&gt;    def getInstance(*args, **kwargs):&lt;br /&gt;        if cls not in instances:&lt;br /&gt;            instances[cls] = cls(*args, **kwargs)&lt;br /&gt;        return instances[cls]&lt;br /&gt;    return getInstance&lt;br /&gt;'''&lt;br /&gt;class singleton:&lt;br /&gt;    def __init__(self, cls):&lt;br /&gt;        self.instances = {}&lt;br /&gt;        self.cls = cls&lt;br /&gt;        pass&lt;br /&gt;    &lt;br /&gt;    def __call__(self, *args, **kwargs):&lt;br /&gt;        if self.cls not in self.instances:&lt;br /&gt;            self.instances[self.cls] = self.cls(*args, **kwargs)&lt;br /&gt;        return self.instances[self.cls]&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1755297621580188823?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1755297621580188823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-3-more-decorator-samples.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1755297621580188823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1755297621580188823'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-3-more-decorator-samples.html' title='[Level 3] More decorator samples.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4995648994008586258</id><published>2011-09-29T00:43:00.000+08:00</published><updated>2011-09-29T00:43:00.201+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 1] Compile python scripts.</title><content type='html'>If you want to compile python script manually, you could use following command.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;$ python -c "import compileall; compileall.compile_dir('./', force=1)"&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4995648994008586258?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4995648994008586258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-1-compile-python-scripts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4995648994008586258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4995648994008586258'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-1-compile-python-scripts.html' title='[Level 1] Compile python scripts.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8917388420464476566</id><published>2011-09-28T23:25:00.000+08:00</published><updated>2011-09-28T23:25:24.192+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] enumrate() in Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;aWeek = ['Sun', 'Mon','Tue','Wed', 'Thu', 'Fri', 'Sat']&lt;br /&gt;&lt;br /&gt;## without enumerate()&lt;br /&gt;print 'without enumerate()...'&lt;br /&gt;index = 0&lt;br /&gt;for day in aWeek:&lt;br /&gt;    print index, day&lt;br /&gt;    index += 1&lt;br /&gt;&lt;br /&gt;## without enumerate()&lt;br /&gt;print 'without enumerate()...'&lt;br /&gt;for index in range(len(aWeek)):&lt;br /&gt;    print index, aWeek[index]&lt;br /&gt;&lt;br /&gt;## with enumerate()&lt;br /&gt;print 'with enumerate()...'&lt;br /&gt;for (index, day) in enumerate(aWeek):&lt;br /&gt;    print index, day&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;without enumerate()...&lt;br /&gt;0 Sun&lt;br /&gt;1 Mon&lt;br /&gt;2 Tue&lt;br /&gt;3 Wed&lt;br /&gt;4 Thu&lt;br /&gt;5 Fri&lt;br /&gt;6 Sat&lt;br /&gt;without enumerate()...&lt;br /&gt;0 Sun&lt;br /&gt;1 Mon&lt;br /&gt;2 Tue&lt;br /&gt;3 Wed&lt;br /&gt;4 Thu&lt;br /&gt;5 Fri&lt;br /&gt;6 Sat&lt;br /&gt;with enumerate()...&lt;br /&gt;0 Sun&lt;br /&gt;1 Mon&lt;br /&gt;2 Tue&lt;br /&gt;3 Wed&lt;br /&gt;4 Thu&lt;br /&gt;5 Fri&lt;br /&gt;6 Sat&lt;br /&gt;&lt;/pre&gt;Use enumerate() would make code easier to read.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8917388420464476566?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8917388420464476566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-enumrate-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8917388420464476566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8917388420464476566'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-enumrate-in-python.html' title='[Level 2] enumrate() in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-5008592343040606640</id><published>2011-09-26T22:51:00.002+08:00</published><updated>2011-09-27T16:23:13.989+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Python Decorator Sample.</title><content type='html'>Another sample for Python decorator.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/env python&lt;br /&gt;class ServiceFee:&lt;br /&gt;  def __init__(self, f):&lt;br /&gt;    self.f = f&lt;br /&gt;    pass&lt;br /&gt;  def __call__(self, *args, **kargs):&lt;br /&gt;    return self.f(*args, **kargs)*1.1&lt;br /&gt;&lt;br /&gt;class TaxFee:&lt;br /&gt;  def __init__(self, f):&lt;br /&gt;    self.f = f&lt;br /&gt;    pass&lt;br /&gt;  def __call__(self, *args, **kargs):&lt;br /&gt;    return self.f(*args, **kargs)*1.05&lt;br /&gt;&lt;br /&gt;@ServiceFee&lt;br /&gt;@TaxFee&lt;br /&gt;def beef(pricePerKG, KG):&lt;br /&gt;  return pricePerKG*KG&lt;br /&gt;&lt;br /&gt;print 'Beef $10/KG, and buy 5KG=%s' % beef(10, 5)&lt;br /&gt;print 'Beef $20/KG, and buy 10KG=%s' % beef(20, 10)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./t.py&lt;br /&gt;Beef $10/KG, and buy 5KG=57.75&lt;br /&gt;Beef $20/KG, and buy 10KG=231.0&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-5008592343040606640?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/5008592343040606640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-python-decorator-sample.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5008592343040606640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5008592343040606640'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-python-decorator-sample.html' title='[Level 2] Python Decorator Sample.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-948381257370950927</id><published>2011-09-26T16:12:00.000+08:00</published><updated>2011-09-26T16:12:32.469+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Shell Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Join lines by sed commands.</title><content type='html'>If you want to join lines in shell script, you could use sed command.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/bash&lt;br /&gt;cat &amp;gt; /tmp/t.txt &amp;lt;&amp;lt;EOF&lt;br /&gt;eth0&lt;br /&gt;eth1&lt;br /&gt;eth2&lt;br /&gt;eth3&lt;br /&gt;eth4&lt;br /&gt;eth5&lt;br /&gt;eth6&lt;br /&gt;lo0&lt;br /&gt;EOF&lt;br /&gt;sed -e :a -e '$!N; s/\n/,/; ta' /tmp/t.txt&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./joinLinesBySed.sh&lt;br /&gt;eth0,eth1,eth2,eth3,eth4,eth5,eth6,lo0&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-948381257370950927?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/948381257370950927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-join-lines-by-sed-commands.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/948381257370950927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/948381257370950927'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-join-lines-by-sed-commands.html' title='[Level 2] Join lines by sed commands.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-391636520745760669</id><published>2011-09-26T15:18:00.003+08:00</published><updated>2011-09-27T16:34:41.303+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to implement decorator in Python (II).</title><content type='html'>Months ago, I wrote a simple decorator, without decorator parameters, implement in Python.&lt;br /&gt;&lt;a href="http://stanley-huang.blogspot.com/2011/03/level-2-how-to-implement-decorator-in.html"&gt;[Level 2] How to implement decorator in Python (I).&lt;/a&gt;&lt;br /&gt;Now, I'll show you how to implement decorator with parameter.&lt;br /&gt;&lt;br /&gt;The sample of Python decorator (1, by class): &lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;&lt;br /&gt;class Decorator:&lt;br /&gt;    def __init__(self, man, woman):&lt;br /&gt;        self.man = man &lt;br /&gt;        self.woman = woman&lt;br /&gt;        pass&lt;br /&gt;    def __call__(self, f): &lt;br /&gt;        def wrapped_f(*args, **kargs):&lt;br /&gt;            print 'hello %s' % self.man&lt;br /&gt;            f(*args, **kargs)&lt;br /&gt;            print 'world %s' % self.woman&lt;br /&gt;        return wrapped_f&lt;br /&gt;&lt;br /&gt;@Decorator('stanley', 'christy')&lt;br /&gt;def test(who):&lt;br /&gt;    print 'test(%s)' % who &lt;br /&gt;   &lt;br /&gt;test('joseph') &lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./test.py&lt;br /&gt;hello stanley&lt;br /&gt;test(joseph)&lt;br /&gt;world christy&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The sample of Python decorator (2, by wrap function): &lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def Decorator(man, woman):&lt;br /&gt;    def wrap(f):&lt;br /&gt;        def wrapped_f(*args, **kargs):&lt;br /&gt;            print 'hello %s' % man &lt;br /&gt;            f(*args, **kargs)&lt;br /&gt;            print 'world %s' % woman&lt;br /&gt;        return wrapped_f&lt;br /&gt;    return wrap&lt;br /&gt;&lt;br /&gt;@Decorator('stanley', 'christy')&lt;br /&gt;def test(who):&lt;br /&gt;    print 'test(%s)' % who &lt;br /&gt;&lt;br /&gt;test('joseph')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./test.py&lt;br /&gt;hello stanley&lt;br /&gt;test(joseph)&lt;br /&gt;world christy&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-391636520745760669?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/391636520745760669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-how-to-implement-decorator-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/391636520745760669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/391636520745760669'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-how-to-implement-decorator-in.html' title='[Level 2] How to implement decorator in Python (II).'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-861508282320957886</id><published>2011-09-21T14:58:00.000+08:00</published><updated>2011-09-21T14:58:23.755+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Testing combination of loop and try.</title><content type='html'>Sample code and test result are as the following:&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;class e(Exception):&lt;br /&gt;    def __init__(self):&lt;br /&gt;       pass&lt;br /&gt;&lt;br /&gt;server_list = [1,2,3,4,5]&lt;br /&gt;for server in server_list:&lt;br /&gt;    try:&lt;br /&gt;        sReturn = server&lt;br /&gt;        print 's:%s' % sReturn&lt;br /&gt;        if sReturn&lt;3: continue&lt;br /&gt;        if sReturn==3: raise e&lt;br /&gt;        print 'try:%s' % sReturn&lt;br /&gt;    except Exception, e:&lt;br /&gt;        print 'except1:%s' % sReturn&lt;br /&gt;        continue&lt;br /&gt;        print 'except2:%s' % sReturn&lt;br /&gt;    else:&lt;br /&gt;        print 'else:%s' % sReturn&lt;br /&gt;        break&lt;br /&gt;    finally:&lt;br /&gt;        print 'finally:%s' % sReturn&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./t.py &lt;br /&gt;s:1&lt;br /&gt;finally:1&lt;br /&gt;s:2&lt;br /&gt;finally:2&lt;br /&gt;s:3&lt;br /&gt;except1:3&lt;br /&gt;finally:3&lt;br /&gt;s:4&lt;br /&gt;try:4&lt;br /&gt;else:4&lt;br /&gt;finally:4&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-861508282320957886?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/861508282320957886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-testing-combination-of-loop-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/861508282320957886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/861508282320957886'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/09/level-2-testing-combination-of-loop-and.html' title='[Level 2] Testing combination of loop and try.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6551960636981942051</id><published>2011-08-31T13:51:00.000+08:00</published><updated>2011-08-31T13:51:46.457+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Configuration'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] Make Nautilus always use Location Entry in Ubuntu 10.04</title><content type='html'>Hi all:&lt;br /&gt;&lt;br /&gt;FYI.&lt;br /&gt;&lt;a href="http://ubuntuguide.net/make-nautilus-always-use-location-entry-in-ubuntu-10-04"&gt;http://ubuntuguide.net/make-nautilus-always-use-location-entry-in-ubuntu-10-04&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6551960636981942051?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6551960636981942051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-1-make-nautilus-always-use.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6551960636981942051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6551960636981942051'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-1-make-nautilus-always-use.html' title='[Level 1] Make Nautilus always use Location Entry in Ubuntu 10.04'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6435342437435534776</id><published>2011-08-31T09:51:00.000+08:00</published><updated>2011-08-31T09:51:43.979+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='expect'/><category scheme='http://www.blogger.com/atom/ns#' term='Shell Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Commands'/><title type='text'>[Level 1] Install autoexpect</title><content type='html'>&lt;pre class="prettyprint lang-html"&gt;$ autoexpect -f ./auto.exp&lt;br /&gt;autoexpect started, file is ./auto.exp&lt;br /&gt;$ ssh stanley@localhost&lt;br /&gt;The authenticity of host 'localhost (127.0.0.1)' can't be established.&lt;br /&gt;RSA key fingerprint is 36:12:a4:49:26:fe:18:0d:77:bf:c7:e8:36:86:b7:f2.&lt;br /&gt;Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;Warning: Permanently added 'localhost' (RSA) to the list of known hosts.&lt;br /&gt;stanley@localhost's password: &lt;br /&gt;Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-generic x86_64)&lt;br /&gt;&lt;br /&gt; * Documentation:  https://help.ubuntu.com/&lt;br /&gt;&lt;br /&gt;*** /dev/sda5 will be checked for errors at next reboot ***&lt;br /&gt;&lt;br /&gt;Last login: Thu Jul 28 12:17:50 2011 from stanley-ubuntu&lt;br /&gt;$ ls&lt;br /&gt;apache-cassandra-0.8.1-SNAPSHOT.jar  Public&lt;br /&gt;auto.exp                             Ruckus&lt;br /&gt;Desktop                              script.exp&lt;br /&gt;Documents                            scripts&lt;br /&gt;Downloads                            scripts_20110302.tgz&lt;br /&gt;eclipse                              Self_assesment_201103.pdf&lt;br /&gt;English_Survey.pdf                   SUR-1-Vesu_Piplod_NewCityLigh_1.png&lt;br /&gt;examples.desktop                     Templates&lt;br /&gt;minicom.log                          Videos&lt;br /&gt;Music                                vmEsxi4.1_customize.docx&lt;br /&gt;Perforce                             workspace&lt;br /&gt;Pictures&lt;br /&gt;$ pwd&lt;br /&gt;/home/stanley&lt;br /&gt;$ exit&lt;br /&gt;logout&lt;br /&gt;Connection to localhost closed.&lt;br /&gt;$ exit&lt;br /&gt;exit&lt;br /&gt;autoexpect done, file is ./auto.exp&lt;br /&gt;$ ls -al ./auto.exp&lt;br /&gt;-rwxr-xr-x 1 stanley stanley 4004 2011-08-31 09:44 ./auto.exp&lt;br /&gt;$ cat ./auto.exp&lt;br /&gt;#!/usr/bin/expect -f&lt;br /&gt;#&lt;br /&gt;# This Expect script was generated by autoexpect on Wed Aug 31 09:44:02 2011&lt;br /&gt;# Expect and autoexpect were both written by Don Libes, NIST.&lt;br /&gt;#&lt;br /&gt;# Note that autoexpect does not guarantee a working script.  It&lt;br /&gt;# necessarily has to guess about certain things.  Two reasons a script&lt;br /&gt;# might fail are:&lt;br /&gt;#&lt;br /&gt;# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,&lt;br /&gt;# etc.) and devices discard or ignore keystrokes that arrive "too&lt;br /&gt;# quickly" after prompts.  If you find your new script hanging up at&lt;br /&gt;# one spot, try adding a short sleep just before the previous send.&lt;br /&gt;# Setting "force_conservative" to 1 (see below) makes Expect do this&lt;br /&gt;# automatically - pausing briefly before sending each character.  This&lt;br /&gt;# pacifies every program I know of.  The -c flag makes the script do&lt;br /&gt;# this in the first place.  The -C flag allows you to define a&lt;br /&gt;# character to toggle this mode off and on.&lt;br /&gt;&lt;br /&gt;set force_conservative 0  ;# set to 1 to force conservative mode even if&lt;br /&gt;			  ;# script wasn't run conservatively originally&lt;br /&gt;if {$force_conservative} {&lt;br /&gt;	set send_slow {1 .1}&lt;br /&gt;	proc send {ignore arg} {&lt;br /&gt;		sleep .1&lt;br /&gt;		exp_send -s -- $arg&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#&lt;br /&gt;# 2) differing output - Some programs produce different output each time&lt;br /&gt;# they run.  The "date" command is an obvious example.  Another is&lt;br /&gt;# ftp, if it produces throughput statistics at the end of a file&lt;br /&gt;# transfer.  If this causes a problem, delete these patterns or replace&lt;br /&gt;# them with wildcards.  An alternative is to use the -p flag (for&lt;br /&gt;# "prompt") which makes Expect only look for the last line of output&lt;br /&gt;# (i.e., the prompt).  The -P flag allows you to define a character to&lt;br /&gt;# toggle this mode off and on.&lt;br /&gt;#&lt;br /&gt;# Read the man page for more info.&lt;br /&gt;#&lt;br /&gt;# -Don&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;set timeout -1&lt;br /&gt;spawn $env(SHELL)&lt;br /&gt;match_max 100000&lt;br /&gt;expect -exact "]0;$\$ "&lt;br /&gt;send -- "ssh stanely@"&lt;br /&gt;expect -exact [K"&lt;br /&gt;send -- ""&lt;br /&gt;expect -exact [K"&lt;br /&gt;send -- ""&lt;br /&gt;expect -exact [K"&lt;br /&gt;send -- ""&lt;br /&gt;expect -exact [K"&lt;br /&gt;send -- "ley@localhost\r"&lt;br /&gt;expect -exact "ley@localhost\r&lt;br /&gt;The authenticity of host 'localhost (127.0.0.1)' can't be established.\r&lt;br /&gt;RSA key fingerprint is 36:12:a4:49:26:fe:18:0d:77:bf:c7:e8:36:86:b7:f2.\r&lt;br /&gt;Are you sure you want to continue connecting (yes/no)? "&lt;br /&gt;send -- "yes\r"&lt;br /&gt;expect -exact "yes\r&lt;br /&gt;Warning: Permanently added 'localhost' (RSA) to the list of known hosts.\r\r&lt;br /&gt;stanley@localhost's password: "&lt;br /&gt;send -- "MyPassword\r"&lt;br /&gt;expect -exact "\r&lt;br /&gt;Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-generic x86_64)\r&lt;br /&gt;\r&lt;br /&gt; * Documentation:  https://help.ubuntu.com/\r&lt;br /&gt;\r&lt;br /&gt;*** /dev/sda5 will be checked for errors at next reboot ***\r&lt;br /&gt;\r&lt;br /&gt;Last login: Thu Jul 28 12:17:50 2011 from stanley-ubuntu\r\r&lt;br /&gt;]0;$\$ "&lt;br /&gt;send -- "ls\r"&lt;br /&gt;expect -exact "ls\r&lt;br /&gt;[0m[01;31mapache-cassandra-0.8.1-SNAPSHOT.jar[0m  [01;34mPublic[0m\r&lt;br /&gt;[01;32mauto.exp[0m                             [01;34mRuckus[0m\r&lt;br /&gt;[01;34mDesktop[0m                              [01;32mscript.exp[0m\r&lt;br /&gt;[01;34mDocuments[0m                            [01;34mscripts[0m\r&lt;br /&gt;[01;34mDownloads[0m                            [01;31mscripts_20110302.tgz[0m\r&lt;br /&gt;[01;34meclipse[0m                              Self_assesment_201103.pdf\r&lt;br /&gt;English_Survey.pdf                   [01;35mSUR-1-Vesu_Piplod_NewCityLigh_1.png[0m\r&lt;br /&gt;examples.desktop                     [01;34mTemplates[0m\r&lt;br /&gt;minicom.log                          [01;34mVideos[0m\r&lt;br /&gt;[01;34mMusic[0m                                vmEsxi4.1_customize.docx\r&lt;br /&gt;[01;34mPerforce[0m                             [01;34mworkspace[0m\r&lt;br /&gt;[01;34mPictures[0m\r&lt;br /&gt;]0;$\$ "&lt;br /&gt;send -- "pwd\r"&lt;br /&gt;expect -exact "pwd\r&lt;br /&gt;/home/stanley\r&lt;br /&gt;]0;$\$ "&lt;br /&gt;send -- "exit\r"&lt;br /&gt;expect -exact "exit\r&lt;br /&gt;logout\r&lt;br /&gt;Connection to localhost closed.\r\r&lt;br /&gt;]0;$\$ "&lt;br /&gt;send -- "exit\r"&lt;br /&gt;expect eof&lt;br /&gt;$&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6435342437435534776?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6435342437435534776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-1-install-autoexpect.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6435342437435534776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6435342437435534776'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-1-install-autoexpect.html' title='[Level 1] Install autoexpect'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6092749997762517771</id><published>2011-08-30T09:49:00.000+08:00</published><updated>2011-08-30T09:49:20.138+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Commands'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 2] How to simulate udevinfo in Ubuntu 11.04</title><content type='html'>When you try to use command udevinfo in Ubuntu 11.04, you would get the response "udevinfo: command not found".&lt;br /&gt;How to simulate the command udevinfo?&lt;br /&gt;Use command udevinfo with info option.&lt;br /&gt;Ex.&lt;br /&gt;# udevadm info -q all -n /dev/video0&lt;br /&gt;You could also create a function named udevinfo as you like&lt;br /&gt;Ex.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;# udevinfo () { udevadm info -a -p `udevadm info -q path -n "$1"`; }&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;# udevinfo /dev/video0&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6092749997762517771?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6092749997762517771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-how-to-simulate-udevinfo-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6092749997762517771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6092749997762517771'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-how-to-simulate-udevinfo-in.html' title='[Level 2] How to simulate udevinfo in Ubuntu 11.04'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-674954745158721260</id><published>2011-08-28T08:30:00.000+08:00</published><updated>2011-08-28T08:30:10.548+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] python oui lookup</title><content type='html'>&lt;pre class="prettyprint lang-html"&gt;$ sudo apt-get -y install python-netaddr&lt;br /&gt;...&lt;br /&gt;$ cd /usr/share/pyshared/netaddr/eui&lt;br /&gt;$ sudo python ./ieee.py &lt;br /&gt;downloading latest copy of http://standards.ieee.org/regauth/oui/oui.txt&lt;br /&gt;downloading latest copy of http://standards.ieee.org/regauth/oui/iab.txt&lt;br /&gt;$ python&lt;br /&gt;&gt;&gt;&gt; from netaddr import *&lt;br /&gt;&gt;&gt;&gt; mac = EUI('bc:ae:c5:3b:fc:5e')&lt;br /&gt;&gt;&gt;&gt; print mac.oui.registration().org&lt;br /&gt;ASUSTek COMPUTER INC.&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-674954745158721260?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/674954745158721260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-python-oui-lookup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/674954745158721260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/674954745158721260'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-python-oui-lookup.html' title='[Level 2] python oui lookup'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3682518576831260135</id><published>2011-08-27T11:01:00.002+08:00</published><updated>2011-08-27T11:02:27.733+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OpenVPN'/><category scheme='http://www.blogger.com/atom/ns#' term='Shell Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Use expect to run openvpn.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/expect&lt;br /&gt;set password [lindex $argv 0]&lt;br /&gt;spawn sudo openvpn --script-security 2 --config /home/stanley/Ruckus/RuckusVPN_config/ruckus_taipei.ovpn&lt;br /&gt;expect Enter\ Private\ Key\ Password:&lt;br /&gt;sleep 1&lt;br /&gt;send $password&lt;br /&gt;sleep 1&lt;br /&gt;interact&lt;br /&gt;&lt;/pre&gt;Test run:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# ./openvpn.expect mypassword&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3682518576831260135?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3682518576831260135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-use-expect-to-run-openvpn.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3682518576831260135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3682518576831260135'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-use-expect-to-run-openvpn.html' title='[Level 2] Use expect to run openvpn.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8792006972544672104</id><published>2011-08-26T11:46:00.000+08:00</published><updated>2011-08-26T11:46:41.366+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Pexpect of Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import os, sys&lt;br /&gt;import StringIO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class AuthorizedKeyError(Exception):&lt;br /&gt;    def __init__(self, host):&lt;br /&gt;        self.value = 'Did not be authorized by remote server(%s)!!!' % host&lt;br /&gt;    def __str__(self):&lt;br /&gt;        return repr(self.value)&lt;br /&gt;&lt;br /&gt;class FileSyncManager:&lt;br /&gt;    def fileSync(self, user, host, file):&lt;br /&gt;        output = StringIO.StringIO()&lt;br /&gt;        sCmd = 'scp %s %s@%s:%s' % (file, user, host, file)&lt;br /&gt;        self.debug(sCmd)&lt;br /&gt;        &lt;br /&gt;        scp = pexpect.spawn(sCmd)&lt;br /&gt;        scp.logfile = output&lt;br /&gt;        &lt;br /&gt;        while True:&lt;br /&gt;            index = scp.expect(["Are you sure you want to continue connecting (yes/no)?", "password:" ,pexpect.TIMEOUT, pexpect.EOF]) &lt;br /&gt;            if index == 0: &lt;br /&gt;                scp.sendline('yes')&lt;br /&gt;            elif index == 1:&lt;br /&gt;                raise AuthorizedKeyError(host)&lt;br /&gt;            else:&lt;br /&gt;                break&lt;br /&gt;            &lt;br /&gt;        if scp.exitstatus:&lt;br /&gt;            error_message = output.getvalue().rstrip()&lt;br /&gt;            self.debug(error_message)&lt;br /&gt;            print error_message&lt;br /&gt;            &lt;br /&gt;        scp.close(True)&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8792006972544672104?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8792006972544672104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-pexpect-of-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8792006972544672104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8792006972544672104'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-pexpect-of-python.html' title='[Level 2] Pexpect of Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-9182616923173724219</id><published>2011-08-09T15:39:00.003+08:00</published><updated>2011-09-20T14:56:07.690+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ssh'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to skip StrictHostKeyChecking in ssh.</title><content type='html'>If you want to ignore strict host key checking, even skip saving the host key info,&lt;br /&gt;you could use option UserKnownHostsFile, StrictHostKeyChecking.&lt;br /&gt;Ex.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no stanley@192.168.1.1&lt;/pre&gt;or modify /etc/ssh/ssh_config for global settings.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# cat /etc/ssh/ssh_config&lt;br /&gt;    ...&lt;br /&gt;    UserKnownHostsFile /dev/null&lt;br /&gt;    StrictHostKeyChecking no&lt;br /&gt;    ...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-9182616923173724219?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/9182616923173724219/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-how-to-skip-stricthostkeychecki.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9182616923173724219'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9182616923173724219'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-how-to-skip-stricthostkeychecki.html' title='[Level 2] How to skip StrictHostKeyChecking in ssh.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4559336973083457943</id><published>2011-08-04T15:01:00.000+08:00</published><updated>2011-08-04T15:01:20.243+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Recursive directory list</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import os, sys&lt;br /&gt;wholeFileList = []&lt;br /&gt;baseDir = sys.argv[1]&lt;br /&gt;for parentDir, childDirList, fileList in os.walk(baseDir):&lt;br /&gt;    for file in fileList:&lt;br /&gt;        wholeFileList.append(os.path.join(parentDir,file))&lt;br /&gt;for file in wholeFileList:&lt;br /&gt;    print file&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;# ./t.py /tmp/d&lt;br /&gt;/tmp/d/1.txt&lt;br /&gt;/tmp/d/2/6.txt&lt;br /&gt;/tmp/d/2/3/a.txt&lt;br /&gt;/tmp/d/2/4/b.txt&lt;br /&gt;/tmp/d/2/5/c.txt&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4559336973083457943?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4559336973083457943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-recursive-directory-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4559336973083457943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4559336973083457943'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/08/level-2-recursive-directory-list.html' title='[Level 2] Recursive directory list'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-501910628311291630</id><published>2011-07-28T11:29:00.000+08:00</published><updated>2011-07-28T11:29:38.895+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>[Level 3] Python performance.</title><content type='html'>Days ago, I discussed the coding style of python,&lt;br /&gt;and I use one example to present what I want you to know.&lt;br /&gt;&lt;br /&gt;The most 2 ways to use of renaming a file are:&lt;br /&gt;1. Use rename method os moudle [ os.rename(f1, f2) ],&lt;br /&gt;2. Use external command by popen method[ os.popen('mv f1 f2') ].&lt;br /&gt;&lt;br /&gt;Some people might think there are not much different between these two ways.&lt;br /&gt;But after a stress test, you will realize it did has different between these two ways.&lt;br /&gt;&lt;br /&gt;The sample code and test run are as the following.&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import os, sys&lt;br /&gt;&lt;br /&gt;from time import gmtime, strftime&lt;br /&gt;&lt;br /&gt;n = 10000&lt;br /&gt;&lt;br /&gt;f1 = '/1'&lt;br /&gt;f2 = '/2'&lt;br /&gt;&lt;br /&gt;os.popen('touch %s' % f1).read()&lt;br /&gt;print strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())&lt;br /&gt;for i in range(n):&lt;br /&gt;    if os.path.exists(f1):&lt;br /&gt;        os.rename(f1, f2)&lt;br /&gt;    else:&lt;br /&gt;        os.rename(f2, f1)&lt;br /&gt;print strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())&lt;br /&gt;for i in range(n):&lt;br /&gt;    if os.path.exists(f1):&lt;br /&gt;        os.popen('mv %s %s' % (f1, f2)).read()&lt;br /&gt;    else:&lt;br /&gt;        os.popen('mv %s %s' % (f2, f1)).read()&lt;br /&gt;print strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;# ./t.py &lt;br /&gt;Thu, 28 Jul 2011 03:18:55 +0000&lt;br /&gt;Thu, 28 Jul 2011 03:18:56 +0000&lt;br /&gt;Thu, 28 Jul 2011 03:19:38 +0000&lt;br /&gt;/# ./t.py &lt;br /&gt;Thu, 28 Jul 2011 03:19:55 +0000&lt;br /&gt;Thu, 28 Jul 2011 03:19:55 +0000&lt;br /&gt;Thu, 28 Jul 2011 03:20:38 +0000&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To many system call will have impact the performance,&lt;br /&gt;and also the portable capability.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-501910628311291630?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/501910628311291630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-3-python-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/501910628311291630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/501910628311291630'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-3-python-performance.html' title='[Level 3] Python performance.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3541955628040700029</id><published>2011-07-28T11:11:00.003+08:00</published><updated>2011-07-28T11:31:33.287+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>[Level 3] Python performance tips.</title><content type='html'>Python performance tips.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://wiki.python.org/moin/PythonSpeed"&gt;http://wiki.python.org/moin/PythonSpeed&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://wiki.python.org/moin/PythonSpeed/PerformanceTips"&gt;http://wiki.python.org/moin/PythonSpeed/PerformanceTips&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3541955628040700029?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3541955628040700029/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-3-python-performance-tips.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3541955628040700029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3541955628040700029'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-3-python-performance-tips.html' title='[Level 3] Python performance tips.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8980951727980049613</id><published>2011-07-27T10:45:00.000+08:00</published><updated>2011-07-27T10:46:00.000+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to get python version on run-time.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import sys&lt;br /&gt;print sys.version&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;# python -c 'import sys; print sys.version'&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;2.6.5 (r265:79063, Apr 16 2010, 13:57:41) &lt;br /&gt;[GCC 4.4.3]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8980951727980049613?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8980951727980049613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-2-how-to-get-python-version-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8980951727980049613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8980951727980049613'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-2-how-to-get-python-version-on.html' title='[Level 2] How to get python version on run-time.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-9187128871368928754</id><published>2011-07-12T19:44:00.000+08:00</published><updated>2011-07-12T19:44:32.985+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to allow using symbolic link in tomcat? (with python code)</title><content type='html'>If you want to allow using symbolic link in tomcat, &lt;br /&gt;you could add and attribute called "context" with an key "allowLinking"&lt;br /&gt;eg.&lt;br /&gt;&amp;lt;Context path="/myapp" allowLinking="true"/&amp;gt;&lt;br /&gt;and I wrote a sample python code to do this.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import os,sys&lt;br /&gt;from xml.dom import minidom&lt;br /&gt;def getXMLDom(FILE):&lt;br /&gt;    return minidom.parse(open(FILE,'r'))&lt;br /&gt;&lt;br /&gt;def saveXML(FILE, dom):&lt;br /&gt;    fd = open(FILE, 'w')&lt;br /&gt;    fd.write(dom.toxml())&lt;br /&gt;    fd.close()&lt;br /&gt;&lt;br /&gt;def appendElement(FILE, base_element_name, element_name, attr_key_val, element_index=0, backup_flag='y'):&lt;br /&gt;    if backup_flag == 'y': backupConfigFile(FILE)&lt;br /&gt;    dom = getXMLDom(FILE)&lt;br /&gt;    e = dom.createElement(element_name)&lt;br /&gt;    for attr, val in attr_key_val:&lt;br /&gt;        e.setAttribute(attr, val)&lt;br /&gt;    dom.getElementsByTagName(base_element_name)[element_index].appendChild(e)&lt;br /&gt;    saveXML(FILE, dom)&lt;br /&gt;&lt;br /&gt;xmlFile = prefix+'/opt/ruckuswireless/3rdparty/tomcat/conf/server.xml'&lt;br /&gt;base_element_name = 'Host'&lt;br /&gt;element_name = 'Context'&lt;br /&gt;attr_key_val = [ &lt;br /&gt;  ["path", "/myapp"],&lt;br /&gt;  ["allowLinking", "true"]&lt;br /&gt;]&lt;br /&gt;appendElement(xmlFile, base_element_name, element_name, attr_key_val)&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-9187128871368928754?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/9187128871368928754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-2-how-to-allow-using-symbolic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9187128871368928754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9187128871368928754'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/07/level-2-how-to-allow-using-symbolic.html' title='[Level 2] How to allow using symbolic link in tomcat? (with python code)'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-5654985105553437042</id><published>2011-06-29T10:41:00.001+08:00</published><updated>2011-06-29T10:46:35.371+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Jython'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] How to install Jython on Ubuntu.</title><content type='html'>You have two way to install jython on Ubuntu:&lt;br /&gt;1. Use apt-get:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# sudo apt-get -y install jython&lt;br /&gt;# jython --version&lt;/pre&gt;2. Download source:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# cd /tmp&lt;br /&gt;# wget http://sourceforge.net/projects/jython/files/jython/2.5.2/jython_installer-2.5.2.jar/download&lt;br /&gt;# mv ./download ./jython.jar&lt;br /&gt;# java -jar ./jython.jar&lt;br /&gt;... following the wizard.&lt;br /&gt;# export PATH=$PATH:/opt/jython/bin # (if you installed Jython in /opt/jython)&lt;br /&gt;# jython --version&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-5654985105553437042?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/5654985105553437042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-install-jython-on-ubuntu.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5654985105553437042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5654985105553437042'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-install-jython-on-ubuntu.html' title='[Level 1] How to install Jython on Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6676391158127277390</id><published>2011-06-29T09:50:00.000+08:00</published><updated>2011-06-29T09:50:07.286+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scala'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] How to install Scala on Ubuntu.</title><content type='html'>You have two way to install it.&lt;br /&gt;1. Use apt-get:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# sudo apt-get -y install scala&lt;br /&gt;&lt;/pre&gt;2. Download source: (browse http://www.scala-lang.org/downloads first)&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# cd /opt&lt;br /&gt;# wget http://www.scala-lang.org/downloads/distrib/files/scala-2.9.0.1.tgz&lt;br /&gt;# tar -C /opt zxf ./scala-2.9.0.1.tgz&lt;br /&gt;# export PATH=$PATH:/opt/scala-2.9.0.1/bin&lt;br /&gt;# scala -version&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6676391158127277390?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6676391158127277390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-install-scala-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6676391158127277390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6676391158127277390'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-install-scala-on-ubuntu.html' title='[Level 1] How to install Scala on Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4256915673406406164</id><published>2011-06-28T19:52:00.002+08:00</published><updated>2011-06-28T19:55:05.106+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Wireless'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] Enable wireless of network-manager in Ubuntu 11.04</title><content type='html'>Once you upgrade Ubuntu from 10.04 to 11.04, and you will find out the network-manager won't manage wireless any more. But you still could change NetworkManager.conf to enable it.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# sudo vi /etc/NetworkManager/NetworkManager.conf&lt;br /&gt;and change "managed" attribute from "false" to “true“ and restart it.&lt;br /&gt;# sudo /etc/init.d/network-manager restart&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4256915673406406164?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4256915673406406164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-2-enable-wireless-of-network.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4256915673406406164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4256915673406406164'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-2-enable-wireless-of-network.html' title='[Level 2] Enable wireless of network-manager in Ubuntu 11.04'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7656645196405342658</id><published>2011-06-22T11:27:00.000+08:00</published><updated>2011-06-22T11:27:28.323+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ntpserver'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] How to set ntp client in Ubuntu.</title><content type='html'>If you want to sync time with time server in Ubuntu,&lt;br /&gt;you could use command ntpdate + time_server.&lt;br /&gt;And don't forget write date into bios too.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;ntpdate time.stdtime.gov.tw &amp;&amp; hwclock -w&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7656645196405342658?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7656645196405342658/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-set-ntp-client-in-ubuntu.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7656645196405342658'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7656645196405342658'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-set-ntp-client-in-ubuntu.html' title='[Level 1] How to set ntp client in Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2154771266070777584</id><published>2011-06-15T19:31:00.000+08:00</published><updated>2011-06-15T19:31:49.882+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Commands'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] How to grep  in file.</title><content type='html'>Just use -P and '\t' with grep command.&lt;br /&gt;Ex.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# grep -P '\t' /etc/passwd &lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2154771266070777584?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2154771266070777584/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-grep-in-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2154771266070777584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2154771266070777584'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-how-to-grep-in-file.html' title='[Level 1] How to grep &lt;Tab&gt; in file.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1332467413314989931</id><published>2011-06-01T15:41:00.002+08:00</published><updated>2011-06-14T11:13:51.334+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MP4'/><category scheme='http://www.blogger.com/atom/ns#' term='MP3'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>[Level 1] MP3 editor in Ubuntu.</title><content type='html'>If you want to modify mp3 in Ubuntu,&lt;br /&gt;you could use "audacity".&lt;br /&gt;And you could download it from reposity.&lt;br /&gt;The commands as the following.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# apt-cache search audacity&lt;br /&gt;create-resources - shared resources for use by creative applications&lt;br /&gt;audacity - fast, cross-platform audio editor&lt;br /&gt;audacity-data - fast, cross-platform audio editor (data)&lt;br /&gt;audacity-dbg - fast, cross-platform audio editor (debug)&lt;br /&gt;vamp-plugin-sdk - audio analysis and feature extraction plugins (SDK)&lt;br /&gt;# apt-get -y install audacity&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After for a while, I heard a good tool to convert mp4 to mp3 call avidemux&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# apt-cache search avidemux&lt;br /&gt;libavidemux0 - a free video editor - shared libraries&lt;br /&gt;avidemux - a free video editor - GTK version&lt;br /&gt;avidemux-cli - a free video editor - command line version&lt;br /&gt;avidemux-common - a free video editor - Internationalization files&lt;br /&gt;avidemux-plugins-cli - a free video editor - CLI plugins&lt;br /&gt;avidemux-plugins-common - a free video editor - common files for plugins&lt;br /&gt;avidemux-plugins-gtk - a free video editor - GTK plugins&lt;br /&gt;avidemux-plugins-qt - a free video editor - Qt plugins&lt;br /&gt;avidemux-qt - a free video editor - QT version&lt;br /&gt;# apt-get -y install avidemux&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1332467413314989931?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1332467413314989931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-mp3-editor-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1332467413314989931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1332467413314989931'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/06/level-1-mp3-editor-in-ubuntu.html' title='[Level 1] MP3 editor in Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2774585502946572523</id><published>2011-05-25T02:31:00.000+08:00</published><updated>2011-05-25T02:31:39.060+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Script'/><title type='text'>[Level 1] Linux simulator on web.</title><content type='html'>Petty cool stuff.&lt;br /&gt;Linux simulator on web.&lt;br /&gt;Please refer to the foll&lt;br /&gt;&lt;a href="http://bellard.org/jslinux"&gt;http://bellard.org/jslinux&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2774585502946572523?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2774585502946572523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/05/level-1-linux-simulator-on-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2774585502946572523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2774585502946572523'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/05/level-1-linux-simulator-on-web.html' title='[Level 1] Linux simulator on web.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4112785624997463773</id><published>2011-05-20T20:35:00.000+08:00</published><updated>2011-05-20T20:35:23.940+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Resource'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Process'/><title type='text'>[Level 2] How to check the resource limitation of specific process in Ubuntu.</title><content type='html'>How to check the resource limitation of specific process in Ubuntu.&lt;br /&gt;You can follow the below steps:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# ps -ef | grep nfsd4&lt;br /&gt;root      1098     2  0 May13 ?        00:00:00 [nfsd4]&lt;br /&gt;root     18674 18607  0 20:32 pts/15   00:00:00 grep --color=auto nfsd4&lt;br /&gt;# cat /proc/1098/limits &lt;br /&gt;Limit                     Soft Limit           Hard Limit           Units     &lt;br /&gt;Max cpu time              unlimited            unlimited            seconds   &lt;br /&gt;Max file size             unlimited            unlimited            bytes     &lt;br /&gt;Max data size             unlimited            unlimited            bytes     &lt;br /&gt;Max stack size            10485760             unlimited            bytes     &lt;br /&gt;Max core file size        0                    unlimited            bytes     &lt;br /&gt;Max resident set          unlimited            unlimited            bytes     &lt;br /&gt;Max processes             47490                47490                processes &lt;br /&gt;Max open files            1024                 1024                 files     &lt;br /&gt;Max locked memory         65536                65536                bytes     &lt;br /&gt;Max address space         unlimited            unlimited            bytes     &lt;br /&gt;Max file locks            unlimited            unlimited            locks     &lt;br /&gt;Max pending signals       47490                47490                signals   &lt;br /&gt;Max msgqueue size         819200               819200               bytes     &lt;br /&gt;Max nice priority         0                    0                    &lt;br /&gt;Max realtime priority     0                    0                    &lt;br /&gt;Max realtime timeout      unlimited            unlimited            us        &lt;br /&gt;# &lt;br /&gt;&lt;/pre&gt;Wish this helps.&lt;br /&gt;&amp;nbsp;regards,&lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4112785624997463773?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4112785624997463773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/05/level-2-how-to-check-resource.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4112785624997463773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4112785624997463773'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/05/level-2-how-to-check-resource.html' title='[Level 2] How to check the resource limitation of specific process in Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2179113709258120511</id><published>2011-05-10T11:41:00.000+08:00</published><updated>2011-05-10T11:41:44.067+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Wireless'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] How to connect wireless ap by command in Ubuntu.</title><content type='html'>How to connect wireless ap by command in Ubuntu?&lt;br /&gt;You can use two commands, 'iwlist', 'iwconfig'.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# iwlist --help&lt;br /&gt;Usage: iwlist [interface] scanning [essid NNN] [last]&lt;br /&gt;              [interface] frequency &lt;br /&gt;              [interface] channel &lt;br /&gt;              [interface] bitrate &lt;br /&gt;              [interface] rate &lt;br /&gt;              [interface] encryption &lt;br /&gt;              [interface] keys &lt;br /&gt;              [interface] power &lt;br /&gt;              [interface] txpower &lt;br /&gt;              [interface] retry &lt;br /&gt;              [interface] ap &lt;br /&gt;              [interface] accesspoints &lt;br /&gt;              [interface] peers &lt;br /&gt;              [interface] event &lt;br /&gt;              [interface] auth &lt;br /&gt;              [interface] wpakeys &lt;br /&gt;              [interface] genie &lt;br /&gt;              [interface] modulation &lt;br /&gt;# iwlist wlan0 scanning essid ap_name&lt;br /&gt;# iwconfig --help&lt;br /&gt;Usage: iwconfig [interface]&lt;br /&gt;                interface essid {NNN|any|on|off}&lt;br /&gt;                interface mode {managed|ad-hoc|master|...}&lt;br /&gt;                interface freq N.NNN[k|M|G]&lt;br /&gt;                interface channel N&lt;br /&gt;                interface bit {N[k|M|G]|auto|fixed}&lt;br /&gt;                interface rate {N[k|M|G]|auto|fixed}&lt;br /&gt;                interface enc {NNNN-NNNN|off}&lt;br /&gt;                interface key {NNNN-NNNN|off}&lt;br /&gt;                interface power {period N|timeout N|saving N|off}&lt;br /&gt;                interface nickname NNN&lt;br /&gt;                interface nwid {NN|on|off}&lt;br /&gt;                interface ap {N|off|auto}&lt;br /&gt;                interface txpower {NmW|NdBm|off|auto}&lt;br /&gt;                interface sens N&lt;br /&gt;                interface retry {limit N|lifetime N}&lt;br /&gt;                interface rts {N|auto|fixed|off}&lt;br /&gt;                interface frag {N|auto|fixed|off}&lt;br /&gt;                interface modulation {11g|11a|CCK|OFDMg|...}&lt;br /&gt;                interface commit &lt;br /&gt;       Check man pages for more details.&lt;br /&gt;# iwconfig wlan0 essid ap_name&lt;br /&gt;# iwconfig wlan0 enc passphrase&lt;br /&gt;# dhclient wlan0&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2179113709258120511?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2179113709258120511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/05/level-2-how-to-connect-wireless-ap-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2179113709258120511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2179113709258120511'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/05/level-2-how-to-connect-wireless-ap-by.html' title='[Level 2] How to connect wireless ap by command in Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6925317597137026924</id><published>2011-04-27T14:05:00.000+08:00</published><updated>2011-04-27T14:05:13.590+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 1] How to get user home directoy in Python</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import os&lt;br /&gt;print os.path.expanduser('~')&lt;br /&gt;print os.path.expanduser('~stanley')&lt;br /&gt;print os.environ['HOME']&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;./getUserHomeDirectory.py &lt;br /&gt;/home/stanley&lt;br /&gt;/home/stanley&lt;br /&gt;/home/stanley&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6925317597137026924?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6925317597137026924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-how-to-get-user-home-directoy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6925317597137026924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6925317597137026924'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-how-to-get-user-home-directoy.html' title='[Level 1] How to get user home directoy in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4149926185429060423</id><published>2011-04-26T19:14:00.000+08:00</published><updated>2011-04-26T19:14:44.605+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cassandra'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 1] How to setup Cassandra home directory</title><content type='html'>If you want to create multi Cassandra instances and only use one copy of binary.&lt;br /&gt;You need to setup CASSANDRA_HOME environment variable.&lt;br /&gt;If you only use symbolic link to link binary file,&lt;br /&gt;Cassandra will search the real binary directory and set its parent directory as the home,&lt;br /&gt;if you don't setup the CASSANDRA_HOME environment variable.&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# export CASSANDRA_HOME=[new directory you want]&lt;br /&gt;# cd [new directory you want]&lt;br /&gt;# ./bin/cassandra&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4149926185429060423?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4149926185429060423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-how-to-setup-cassandra-home.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4149926185429060423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4149926185429060423'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-how-to-setup-cassandra-home.html' title='[Level 1] How to setup Cassandra home directory'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7074053860177646857</id><published>2011-04-26T11:50:00.002+08:00</published><updated>2011-04-26T13:48:18.730+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zip'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] how to extract compressed file in Python.</title><content type='html'>If you want to extract compressed file, you could use zipfile/tarfile to implement.&lt;br /&gt;&lt;br /&gt;[zip]&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import sys, zipfile, os, os.path&lt;br /&gt;&lt;br /&gt;def unzip_file_into_dir(file, dir):&lt;br /&gt;    os.mkdir(dir, 0777)&lt;br /&gt;    zfobj = zipfile.ZipFile(file)&lt;br /&gt;    for name in zfobj.namelist():&lt;br /&gt;        if name.endswith('/'):&lt;br /&gt;            os.mkdir(os.path.join(dir, name))&lt;br /&gt;        else:&lt;br /&gt;            outfile = open(os.path.join(dir, name), 'wb')&lt;br /&gt;            outfile.write(zfobj.read(name))&lt;br /&gt;            outfile.close()&lt;br /&gt;&lt;br /&gt;unzip_file_into_dir('/tmp/mywar.war', '/tmp/mywar')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;[tar.gz]&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import tarfile&lt;br /&gt;&lt;br /&gt;def extract_file(file_name):&lt;br /&gt;    tar_file=tarfile.open(name=file_name, mode='r:gz')&lt;br /&gt;    tar_file.extractall()&lt;br /&gt;    tar_file.close()&lt;br /&gt;    pass&lt;br /&gt;&lt;br /&gt;extract_file('/tmp/mytar.tar.gz')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7074053860177646857?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7074053860177646857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-extract-compressed-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7074053860177646857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7074053860177646857'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-extract-compressed-file.html' title='[Level 2] how to extract compressed file in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6365104130226203712</id><published>2011-04-26T11:35:00.002+08:00</published><updated>2011-04-26T11:35:59.248+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Certificate'/><category scheme='http://www.blogger.com/atom/ns#' term='OpenSSL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='OpenSSH'/><title type='text'>[Level 2] Convert keys between openssh and openssl</title><content type='html'>A good artical for convert keys between openssh and openssl.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://sysmic.org/dotclear/index.php?post/2010/03/24/Convert-keys-betweens-GnuPG,-OpenSsh-and-OpenSSL"&gt;http://sysmic.org/dotclear/index.php?post/2010/03/24/Convert-keys-betweens-GnuPG,-OpenSsh-and-OpenSSL&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6365104130226203712?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6365104130226203712/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-convert-keys-between-openssh.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6365104130226203712'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6365104130226203712'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-convert-keys-between-openssh.html' title='[Level 2] Convert keys between openssh and openssl'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2119608955647838432</id><published>2011-04-25T22:33:00.003+08:00</published><updated>2011-04-27T10:46:00.406+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to create multi instances of tomcat.</title><content type='html'>If you want to create multi instances of tomcat,&lt;br /&gt;you can follow the below steps:&lt;br /&gt;1. Copy logs, conf and webapps from origianl tomcat foler to a new location.&lt;br /&gt;# mkdir -p [a new folder you like]&lt;br /&gt;# cd [original tomcat folder]&lt;br /&gt;# cp ./logs ./conf ./webapps [a new folder you like]&lt;br /&gt;2. Set environment variables "CATALINA_BASE" to the above path.&lt;br /&gt;# export CATALINA_BASE=[a new folder you like]&lt;br /&gt;3. Startup tomcat.&lt;br /&gt;# [original tomcat folder]/bin/startup.sh&lt;br /&gt;&lt;br /&gt;And what's the difference between CATALINA_BASE and CATALINA_HOME,&lt;br /&gt;the decision path is as below:&lt;br /&gt;1. Decide CATALINA_BASE:&lt;br /&gt;If you have CATALINA_BASE, the base directory is CATALINA_BASE,&lt;br /&gt;if not, the real path of binary would be the CATALINA_BASE.&lt;br /&gt;2. Decide CATALINA_HOME:&lt;br /&gt;If you have CATALINA_HOME, the webapps base directory is in CATALINA_HOME,&lt;br /&gt;if not, the CATALINA_BASE would be the CATALINA_HOME.&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;&lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2119608955647838432?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2119608955647838432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-create-multi-instances.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2119608955647838432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2119608955647838432'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-create-multi-instances.html' title='[Level 2] How to create multi instances of tomcat.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-5406113985724217885</id><published>2011-04-22T17:56:00.007+08:00</published><updated>2011-09-30T19:45:54.944+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to display current line number in Python</title><content type='html'>If you want to display current line number for debug info.&lt;br /&gt;You can import inspect to do that.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import inspect&lt;br /&gt;from inspect import currentframe, getframeinfo&lt;br /&gt;&lt;br /&gt;def getFilenameLineno():&lt;br /&gt;    frameinfo = getframeinfo(currentframe().f_back)&lt;br /&gt;    return (frameinfo.filename, frameinfo.lineno)&lt;br /&gt;&lt;br /&gt;def lineno():&lt;br /&gt;    return inspect.currentframe().f_back.f_lineno&lt;br /&gt;&lt;br /&gt;def curr_filename_lineno():&lt;br /&gt;    return inspect.currentframe().f_back.f_code&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    print lineno()&lt;br /&gt;    # skip line with comment&lt;br /&gt;    print curr_filename_lineno()&lt;br /&gt;    &lt;br /&gt;    print '%s(#%s)' % getFilenameLineno()&lt;br /&gt;&lt;br /&gt;    print lineno()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testLineno.py &lt;br /&gt;16&lt;br /&gt;&amp;lt;code object &amp;lt;module&amp;gt; at 0xb7509f50, file "/tmp/t.py", line 2&amp;gt;&lt;br /&gt;/tmp/testLineno.py(#20)&lt;br /&gt;22&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Another way is to parse inspect.stack()&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;import inspect&lt;br /&gt;&lt;br /&gt;def t():&lt;br /&gt;    tt()&lt;br /&gt;&lt;br /&gt;def tt():&lt;br /&gt;    ttt()&lt;br /&gt;&lt;br /&gt;def ttt():&lt;br /&gt;    tttt()&lt;br /&gt;&lt;br /&gt;def tttt():&lt;br /&gt;    print inspect.stack()&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    t()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./test.py &lt;br /&gt;[(&amp;lt;frame object at 0x18ff820&amp;gt;, '/tmp/t.py', 14, 'tttt', ['    print inspect.stack()\n'], 0), (&amp;lt;frame object at 0x190d970&amp;gt;, '/tmp/t.py', 11, 'ttt', ['    tttt()\n'], 0), (&amp;lt;frame object at 0x18fe0c0&amp;gt;, '/tmp/t.py', 8, 'tt', ['    ttt()\n'], 0), (&amp;lt;frame object at 0x1924460&amp;gt;, '/tmp/t.py', 5, 't', ['    tt()\n'], 0), (&amp;lt;frame object at 0x18c7f70&amp;gt;, '/tmp/t.py', 17, '&amp;lt;module&amp;gt;', ['    t()\n'], 0)]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;more info, please reference &lt;a href="http://docs.python.org/library/inspect.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-5406113985724217885?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/5406113985724217885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-how-to-display-current-line.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5406113985724217885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5406113985724217885'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-how-to-display-current-line.html' title='[Level 2] How to display current line number in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-3685772056290327236</id><published>2011-04-22T12:59:00.004+08:00</published><updated>2011-11-04T13:39:39.842+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to use yield in Python</title><content type='html'>yield in python just pass the control to the parent.&lt;br /&gt;if a() call b(),&lt;br /&gt;in b and execute yield,&lt;br /&gt;the control would back to a() util a call generator.next()&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def foo():&lt;br /&gt;    print 'start foo()'       ## only pass here when first time call .next()&lt;br /&gt;    n = 3 &lt;br /&gt;    for i in range(1,n+1):&lt;br /&gt;        print 'in for()'&lt;br /&gt;        print 'yield %s' % i &lt;br /&gt;        yield i               ## return i when call .next()&lt;br /&gt;        print 'back to for()' ## start from here when call .next() again&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__': &lt;br /&gt;    print 'start main'&lt;br /&gt;    print 'init main vars'&lt;br /&gt;    f = foo()&lt;br /&gt;    i = 0 &lt;br /&gt;    n = 10&lt;br /&gt;    print 'f: %s' % f &lt;br /&gt;    print 'i: %s' % i &lt;br /&gt;    print 'n: %s' % n &lt;br /&gt;    &lt;br /&gt;    for x in range(0,n): &lt;br /&gt;        print 'f.next()'&lt;br /&gt;        i = f.next()&lt;br /&gt;        print 'print i'&lt;br /&gt;        print i&lt;br /&gt;        print 'in main'&lt;br /&gt;    print 'call again f.next()'&lt;br /&gt;    print f.next()&lt;br /&gt;    print 'exit'&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./t1.py &lt;br /&gt;start main&lt;br /&gt;init main vars&lt;br /&gt;f: &amp;lt;generator object foo at 0xb73e69dc&amp;gt;&lt;br /&gt;i: 0&lt;br /&gt;n: 10&lt;br /&gt;f.next()&lt;br /&gt;start foo()&lt;br /&gt;in for()&lt;br /&gt;yield 1&lt;br /&gt;print i&lt;br /&gt;1&lt;br /&gt;in main&lt;br /&gt;f.next()&lt;br /&gt;back to for()&lt;br /&gt;in for()&lt;br /&gt;yield 2&lt;br /&gt;print i&lt;br /&gt;2&lt;br /&gt;in main&lt;br /&gt;f.next()&lt;br /&gt;back to for()&lt;br /&gt;in for()&lt;br /&gt;yield 3&lt;br /&gt;print i&lt;br /&gt;3&lt;br /&gt;in main&lt;br /&gt;f.next()&lt;br /&gt;back to for()&lt;br /&gt;Traceback (most recent call last):&lt;br /&gt;  File "./t.py", line 23, in &lt;module&gt;&lt;br /&gt;    i = f.next()&lt;br /&gt;StopIteration&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def foo():&lt;br /&gt;  for i in range(0,5):&lt;br /&gt;    yield i&lt;br /&gt;&lt;br /&gt;f = foo()&lt;br /&gt;&lt;br /&gt;for n in f:&lt;br /&gt;  print 'n=%s' % n &lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./t2.py &lt;br /&gt;n=0&lt;br /&gt;n=1&lt;br /&gt;n=2&lt;br /&gt;n=3&lt;br /&gt;n=4&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-3685772056290327236?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/3685772056290327236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-use-yield-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3685772056290327236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/3685772056290327236'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-use-yield-in-python.html' title='[Level 2] How to use yield in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1581133101285213940</id><published>2011-04-22T12:39:00.001+08:00</published><updated>2011-04-22T12:39:51.005+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Encoding'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 1'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 1] Support utf-8 in python.</title><content type='html'>If you got an error message like "SyntaxError: Non-ASCII character '\xe4' in file"&lt;br /&gt;That means you have non-ascii character in your script.&lt;br /&gt;And if you want to support utf-8, you could add the comment in your script.&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;# -*- coding: utf8 -*-&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1581133101285213940?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1581133101285213940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-support-utf-8-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1581133101285213940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1581133101285213940'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-1-support-utf-8-in-python.html' title='[Level 1] Support utf-8 in python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-9059960892794498972</id><published>2011-04-21T01:58:00.000+08:00</published><updated>2011-04-21T01:58:35.617+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] Unit test in Python.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/usr/bin/env python&lt;br /&gt;import os,sys&lt;br /&gt;import unittest&lt;br /&gt;&lt;br /&gt;class C(object):&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self.name = 'stanley'&lt;br /&gt;        self.age = 24&lt;br /&gt;&lt;br /&gt;class TS(unittest.TestCase):&lt;br /&gt;    ## set up&lt;br /&gt;    def setUp(self):&lt;br /&gt;        self.c = C()&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    ## clean up&lt;br /&gt;    def tearDown(self):&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    def test_getName(self):&lt;br /&gt;        print self.c.name&lt;br /&gt;&lt;br /&gt;    def test_getAge(self):&lt;br /&gt;        print self.c.age&lt;br /&gt;&lt;br /&gt;    def test_getNameAge(self):&lt;br /&gt;        c = C()&lt;br /&gt;        print c.name&lt;br /&gt;        print c.age &lt;br /&gt;&lt;br /&gt;    def runTest(self):&lt;br /&gt;        print self.test_getName()&lt;br /&gt;        print self.test_getAge()&lt;br /&gt;&lt;br /&gt;    #def myTestModule():&lt;br /&gt;    #    tests = ['test_getName', 'test_getAge']&lt;br /&gt;    #    suite = unittest.TestSuite(map(TS, tests))&lt;br /&gt;    #    unittest.TextTestRunner(verbosity=2).run(suite)&lt;br /&gt;&lt;br /&gt;class TS1(unittest.TestCase):&lt;br /&gt;    def setUp(self):&lt;br /&gt;        self.c = C()&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    def tearDown(self):&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    def test_name1(self):&lt;br /&gt;        print self.c.name&lt;br /&gt;&lt;br /&gt;    def test_age1(self):&lt;br /&gt;        print self.c.age&lt;br /&gt;&lt;br /&gt;    def runTest(self):&lt;br /&gt;        self.test_name1()&lt;br /&gt;        self.test_age1()&lt;br /&gt;&lt;br /&gt;class TS2(unittest.TestCase):&lt;br /&gt;    def setUp(self):&lt;br /&gt;        self.c = C()&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    def tearDown(self):&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    def test_name2(self):&lt;br /&gt;        print self.c.name&lt;br /&gt;&lt;br /&gt;    def test_age2(self):&lt;br /&gt;        print self.c.age&lt;br /&gt;&lt;br /&gt;    def runTest(self):&lt;br /&gt;        self.test_name2()&lt;br /&gt;        self.test_age2()&lt;br /&gt;&lt;br /&gt;def getSuite1():&lt;br /&gt;    suite = unittest.TestSuite()&lt;br /&gt;    ## use suite.addTest()&lt;br /&gt;    ## 1. only coudl pass instance&lt;br /&gt;    ## 2. must have method named 'runTest()'&lt;br /&gt;    ## 3. could also pass test method when instanize&lt;br /&gt;&lt;br /&gt;    suite.addTest(TS('test_getName'))&lt;br /&gt;    suite.addTest(TS('test_getAge'))&lt;br /&gt;    ts1 = TS1()&lt;br /&gt;    ts2 = TS2('test_age2')&lt;br /&gt;    suite.addTest(ts1)&lt;br /&gt;    suite.addTest(ts2)&lt;br /&gt;    return suite&lt;br /&gt;&lt;br /&gt;def getSuite2():&lt;br /&gt;    tests = ['test_getName', 'test_getAge']&lt;br /&gt;    return unittest.TestSuite(map(TS, tests))&lt;br /&gt;&lt;br /&gt;def getSuite3():&lt;br /&gt;    return unittest.TestSuite(map(TS, ['test_getName']))&lt;br /&gt;&lt;br /&gt;def getSuite4():&lt;br /&gt;    return unittest.TestSuite(map(TS, ['test_getAge']))&lt;br /&gt;&lt;br /&gt;def getCompositeSuite34():&lt;br /&gt;    return unittest.TestSuite([getSuite3(), getSuite4()])&lt;br /&gt;    &lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    ## uncomment when want to test. ##&lt;br /&gt;    ## way 1:&lt;br /&gt;    #unittest.main()&lt;br /&gt;    ## way 2:&lt;br /&gt;    #suite = unittest.TestLoader().loadTestsFromTestCase(TS)&lt;br /&gt;    #unittest.TextTestRunner(verbosity=2).run(suite)&lt;br /&gt;    ## way 3:&lt;br /&gt;    #suite = unittest.TestLoader().loadTestsFromTestCase(TS)&lt;br /&gt;    #suite1 = getSuite1()&lt;br /&gt;    #suite2 = getSuite2()&lt;br /&gt;    #allsuites = unittest.TestSuite((suite1, suite2))&lt;br /&gt;    #unittest.TextTestRunner(verbosity=2).run(suite1)&lt;br /&gt;    #unittest.TextTestRunner(verbosity=2).run(suite2)&lt;br /&gt;    #unittest.TextTestRunner(verbosity=2).run(allsuites)&lt;br /&gt;    ## way 4:&lt;br /&gt;    #suite = getCompositeSuite34()&lt;br /&gt;    #unittest.TextTestRunner(verbosity=2).run(suite)&lt;br /&gt;&lt;br /&gt;    ## main ##&lt;br /&gt;    #c = C()&lt;br /&gt;    #print 'hello %s(%s)' % (c.name, c.age)&lt;br /&gt;    pass&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-9059960892794498972?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/9059960892794498972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-3-unit-test-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9059960892794498972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/9059960892794498972'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-3-unit-test-in-python.html' title='[Level 3] Unit test in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7084172561636410180</id><published>2011-04-20T23:37:00.002+08:00</published><updated>2011-04-20T23:39:10.511+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] Python variable scope (2).</title><content type='html'>In previous, I wrote a paper for &lt;a href="http://stanley-huang.blogspot.com/2011/03/level-2-python-variable-scope.html"&gt;python variable scope&lt;/a&gt;.&lt;br /&gt;This time, I try to use python native decorator to implement the same idea.&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-python linenums:1"&gt;#!/usr/bin/env python&lt;br /&gt;class C(object):&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self._name = None&lt;br /&gt;        self.__age = None&lt;br /&gt;&lt;br /&gt;    @property&lt;br /&gt;    def name(self):&lt;br /&gt;        """I'm the 'name' propertage."""&lt;br /&gt;        return self._name&lt;br /&gt;&lt;br /&gt;    @name.setter&lt;br /&gt;    def name(self, value):&lt;br /&gt;        self._name = value&lt;br /&gt;&lt;br /&gt;    @name.deleter&lt;br /&gt;    def name(self):&lt;br /&gt;        del self._name&lt;br /&gt;&lt;br /&gt;    @property&lt;br /&gt;    def age(self):&lt;br /&gt;        pass&lt;br /&gt;&lt;br /&gt;    @age.getter&lt;br /&gt;    def age(self):&lt;br /&gt;        return self.__age&lt;br /&gt;&lt;br /&gt;    @age.setter&lt;br /&gt;    def age(self, value):&lt;br /&gt;        self.__age = value&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    c = C() &lt;br /&gt;    c.name = 1 &lt;br /&gt;    print c.name&lt;br /&gt;    print c._name&lt;br /&gt;    del c.name&lt;br /&gt;    try:&lt;br /&gt;        print c.name&lt;br /&gt;    except AttributeError, e:&lt;br /&gt;        #print "'C' object has no attribute '_name'"&lt;br /&gt;        print e&lt;br /&gt;    &lt;br /&gt;    c.age = 2 &lt;br /&gt;    print c.age&lt;br /&gt;    try:&lt;br /&gt;        print c.__age&lt;br /&gt;    except AttributeError, e:&lt;br /&gt;        #print "'C' object has no attribute '__age'"&lt;br /&gt;        print e&lt;br /&gt;    &lt;br /&gt;    try:&lt;br /&gt;        del c.age&lt;br /&gt;    except AttributeError, e:&lt;br /&gt;        #print "can't delete attribute"&lt;br /&gt;        print e&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./testProperty.py &lt;br /&gt;1&lt;br /&gt;1&lt;br /&gt;'C' object has no attribute '_name'&lt;br /&gt;2&lt;br /&gt;'C' object has no attribute '__age'&lt;br /&gt;can't delete attribute&lt;br /&gt;$&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7084172561636410180?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7084172561636410180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/in-previous-i-wrote-paper-for-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7084172561636410180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7084172561636410180'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/in-previous-i-wrote-paper-for-python.html' title='[Level 2] Python variable scope (2).'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-2651874012073090892</id><published>2011-04-01T17:38:00.003+08:00</published><updated>2011-04-01T18:34:35.239+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Firewall'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 3] Firewall in Ubuntu.</title><content type='html'>install gui tool for ufw&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# apt-get -y install gufw&lt;br /&gt;# gufw&lt;br /&gt;&lt;/pre&gt;use command(ufw) to setting firewall, and the config file in in /lib/ufw/user.rules&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# ufw deny from any to any port 22&lt;br /&gt;# ls -al /lib/ufw/user.rules -rw-r----- 1 root root 1405 2011-04-01 17:36 /lib/ufw/user.rules&lt;br /&gt;# ufw delete deny from any to any port 22&lt;br /&gt;# ls -al /lib/ufw/user.rules -rw-r----- 1 root root 1263 2011-04-01 17:36 /lib/ufw/user.rules&lt;br /&gt;&lt;/pre&gt;my setting history (reference only):&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;ufw disable&lt;br /&gt;ufw default deny&lt;br /&gt;ufw logging ON&lt;br /&gt;ufw enable&lt;br /&gt;ufw allow 22/tcp&lt;br /&gt;ufw allow proto tcp from 192.168.1.0/24 to 192.168.1.101 port 80&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-2651874012073090892?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/2651874012073090892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-3-firewall-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2651874012073090892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/2651874012073090892'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-3-firewall-in-ubuntu.html' title='[Level 3] Firewall in Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1380808104340884739</id><published>2011-04-01T09:10:00.002+08:00</published><updated>2011-10-05T17:48:20.139+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to compare two list (array) in Python</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;a=[1,2,3]&lt;br /&gt;b=[2,3,4]&lt;br /&gt;set_a = set(a)&lt;br /&gt;set_b = set(b)&lt;br /&gt;print set_a.difference(set_b)&lt;br /&gt;print set_b.difference(set_a)&lt;br /&gt;print set_a.union(set_b)&lt;br /&gt;print set_a.intersection(set_b)&lt;br /&gt;# print set_a.difference(set_b)[0] ## fail, 'set' object does not support indexing&lt;br /&gt;print list(set_a.difference(set_b))[0]&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./t.py&lt;br /&gt;set([1])&lt;br /&gt;set([4])&lt;br /&gt;set([1, 2, 3, 4])&lt;br /&gt;set([2, 3])&lt;br /&gt;1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1380808104340884739?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1380808104340884739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-compare-two-list-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1380808104340884739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1380808104340884739'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/04/level-2-how-to-compare-two-list-in.html' title='[Level 2] How to compare two list (array) in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-5673215514589084991</id><published>2011-03-30T20:50:00.002+08:00</published><updated>2011-03-30T21:14:49.050+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gtk+'/><category scheme='http://www.blogger.com/atom/ns#' term='Vala'/><category scheme='http://www.blogger.com/atom/ns#' term='Gcc'/><category scheme='http://www.blogger.com/atom/ns#' term='Shell Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] gtk shell script for gcc/vala</title><content type='html'>1. get vala syntax from &lt;a href="http://live.gnome.org/Vala/Vim"&gt;gnome&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;[gcc.sh]&lt;br /&gt;&lt;pre class="prettyprint lang-sh linenums:1"&gt;#!/bin/bash -vx&lt;br /&gt;output=`echo $1 | sed -e 's/\.c$//'`&lt;br /&gt;gcc -Wall $1 -o $output `pkg-config --cflags --libs gtk+-2.0`&lt;br /&gt;$output&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ alias gcc='./gcc.sh '&lt;br /&gt;$ gcc ./1.helloworld.c&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;[valac.sh]&lt;br /&gt;&lt;pre class="prettyprint lang-sh linenums:1"&gt;#!/bin/bash&lt;br /&gt;output=`echo $1 | sed -e 's/\.vala$//'`&lt;br /&gt;/usr/bin/valac --pkg gtk+-2.0 $1&lt;br /&gt;$output&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ alias valac='./valac.sh '&lt;br /&gt;$ valac ./3.helloworld.vala&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-5673215514589084991?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/5673215514589084991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-gtk-shell-script-for-gccvala.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5673215514589084991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/5673215514589084991'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-gtk-shell-script-for-gccvala.html' title='[Level 2] gtk shell script for gcc/vala'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8166555638993845768</id><published>2011-03-30T14:04:00.002+08:00</published><updated>2011-03-31T10:29:10.039+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to verify instance has attribute (variables in global/local) or not.</title><content type='html'>$ cat ./test1.py&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;class myClass:&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self.attr1 = 'a'&lt;br /&gt;        self.attr2 = 'b'&lt;br /&gt;    def checkAttr(self, sAttr):&lt;br /&gt;        return hasattr(self, sAttr)&lt;br /&gt;&lt;br /&gt;mc = myClass()&lt;br /&gt;print hasattr(mc, 'attr1')&lt;br /&gt;print hasattr(mc, 'attr2')&lt;br /&gt;print hasattr(mc, 'attr3')&lt;br /&gt;print mc.checkAttr('attr1')&lt;br /&gt;print mc.checkAttr('attr2')&lt;br /&gt;print mc.checkAttr('attr3')&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./test1.py&lt;br /&gt;True&lt;br /&gt;True&lt;br /&gt;False&lt;br /&gt;True&lt;br /&gt;True&lt;br /&gt;False&lt;br /&gt;&lt;/pre&gt;$ cat ./test2.py&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;## cannot extract test locals() in another method! ##&lt;br /&gt;def testExistInGlobal():&lt;br /&gt;#    print globals()&lt;br /&gt;#    print locals()&lt;br /&gt;    print 'a in globals(): %s' % ('Ture' if 'a' in globals() else 'False')&lt;br /&gt;    print 'b in globals(): %s' % ('Ture' if 'b' in globals() else 'False')&lt;br /&gt;#    print 'a in locals(): %s' % ('Ture' if 'a' in locals() else 'False')&lt;br /&gt;#    print 'b in locals(): %s' % ('Ture' if 'b' in locals() else 'False')&lt;br /&gt;&lt;br /&gt;def inFunc1():&lt;br /&gt;    a=2&lt;br /&gt;    print a&lt;br /&gt;    print b&lt;br /&gt;    testExistInGlobal()&lt;br /&gt;    print 'a in locals(): %s' % ('Ture' if 'a' in locals() else 'False')&lt;br /&gt;    print 'b in locals(): %s' % ('Ture' if 'b' in locals() else 'False')&lt;br /&gt;&lt;br /&gt;def inFunc2(b):&lt;br /&gt;    b=3&lt;br /&gt;    print a&lt;br /&gt;    print b&lt;br /&gt;    testExistInGlobal()&lt;br /&gt;&lt;br /&gt;print '-' * 20&lt;br /&gt;print 'before assign a=1, b=2'&lt;br /&gt;testExistInGlobal()&lt;br /&gt;print 'a in locals(): %s' % ('Ture' if 'a' in locals() else 'False')&lt;br /&gt;print 'b in locals(): %s' % ('Ture' if 'b' in locals() else 'False')&lt;br /&gt;&lt;br /&gt;a=1&lt;br /&gt;b=2&lt;br /&gt;&lt;br /&gt;print '-' * 20&lt;br /&gt;print 'after assign a=1, b=2'&lt;br /&gt;testExistInGlobal()&lt;br /&gt;print 'a in locals(): %s' % ('Ture' if 'a' in locals() else 'False')&lt;br /&gt;print 'b in locals(): %s' % ('Ture' if 'b' in locals() else 'False')&lt;br /&gt;&lt;br /&gt;print '-' * 20&lt;br /&gt;print 'test in method1, a=2'&lt;br /&gt;inFunc1()&lt;br /&gt;&lt;br /&gt;print '-' * 20&lt;br /&gt;print 'test in method2, b=3'&lt;br /&gt;inFunc2(b)&lt;br /&gt;&lt;br /&gt;print '-' * 20&lt;br /&gt;print 'back to main'&lt;br /&gt;testExistInGlobal()&lt;br /&gt;print 'a in locals(): %s' % ('Ture' if 'a' in locals() else 'False')&lt;br /&gt;print 'b in locals(): %s' % ('Ture' if 'b' in locals() else 'False')&lt;br /&gt;print a&lt;br /&gt;print b&lt;br /&gt;&lt;/pre&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./test2.py &lt;br /&gt;--------------------&lt;br /&gt;before assign a=1, b=2&lt;br /&gt;a in globals(): False&lt;br /&gt;b in globals(): False&lt;br /&gt;a in locals(): False&lt;br /&gt;b in locals(): False&lt;br /&gt;--------------------&lt;br /&gt;after assign a=1, b=2&lt;br /&gt;a in globals(): Ture&lt;br /&gt;b in globals(): Ture&lt;br /&gt;a in locals(): Ture&lt;br /&gt;b in locals(): Ture&lt;br /&gt;--------------------&lt;br /&gt;test in method1, a=2&lt;br /&gt;2&lt;br /&gt;2&lt;br /&gt;a in globals(): Ture&lt;br /&gt;b in globals(): Ture&lt;br /&gt;a in locals(): Ture&lt;br /&gt;b in locals(): False&lt;br /&gt;--------------------&lt;br /&gt;test in method2, b=3&lt;br /&gt;1&lt;br /&gt;3&lt;br /&gt;a in globals(): Ture&lt;br /&gt;b in globals(): Ture&lt;br /&gt;a in locals(): False&lt;br /&gt;b in locals(): Ture&lt;br /&gt;--------------------&lt;br /&gt;back to main&lt;br /&gt;a in globals(): Ture&lt;br /&gt;b in globals(): Ture&lt;br /&gt;a in locals(): Ture&lt;br /&gt;b in locals(): Ture&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8166555638993845768?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8166555638993845768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-how-to-verify-instance-has.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8166555638993845768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8166555638993845768'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-how-to-verify-instance-has.html' title='[Level 2] How to verify instance has attribute (variables in global/local) or not.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4434135826981476746</id><published>2011-03-23T14:05:00.000+08:00</published><updated>2011-03-23T14:05:56.249+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] get broadcast by Python</title><content type='html'>I wrote a python script to get broadcast by giving ip and netmask.&lt;br /&gt;And I use "lambda" and "map" function to shorten my code,&lt;br /&gt;so it's also a good sample for you to study map function.&lt;br /&gt;More information please refer &lt;a href="http://docs.python.org/library/"&gt;here&lt;/a&gt;.&lt;br /&gt;The sample code is as the following:&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def getBroadcast(self, ip=None, netmask=None):&lt;br /&gt;    if not ip or not netmask: return None&lt;br /&gt;    ip = ip.split('.')&lt;br /&gt;    netmask = netmask.split('.')&lt;br /&gt;        &lt;br /&gt;    for n in range(0,4):&lt;br /&gt;        if netmask[n] == '0': break&lt;br /&gt;    bc = (map(lambda a, b: str(int(a, 10)&amp;int(b,10)), ip[0:n]+['255']*(4-n), netmask[0:n]+['255']*(4-n)))&lt;br /&gt;&lt;br /&gt;    if n &gt; 1: bc[n-1] = str(int(bc[n-1]) + (255 - int(netmask[n-1])))&lt;br /&gt;    return '.'.join(bc)&lt;br /&gt;&lt;br /&gt;print getBroadcast('192.168.10.1','255.255.254.0')&lt;br /&gt;&lt;/pre&gt;Result:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;192.168.11.255&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4434135826981476746?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4434135826981476746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-get-broadcast-by-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4434135826981476746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4434135826981476746'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-get-broadcast-by-python.html' title='[Level 2] get broadcast by Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7482211320835683529</id><published>2011-03-22T12:50:00.002+08:00</published><updated>2011-03-22T22:57:22.739+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] Get ether list by Python in Ubuntu.</title><content type='html'>&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def getEtherList():&lt;br /&gt;    return [x.strip() for x in \&lt;br /&gt;    os.popen("ifconfig -a | \&lt;br /&gt;    grep Link | grep '^[^ ]' | \&lt;br /&gt;    grep -v lo | awk '{print($1)}'")\&lt;br /&gt;    .readlines()]&lt;br /&gt;&lt;br /&gt;print getEtherList()&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7482211320835683529?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7482211320835683529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-get-ether-list-by-python-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7482211320835683529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7482211320835683529'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-get-ether-list-by-python-in.html' title='[Level 2] Get ether list by Python in Ubuntu.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6679150306854422855</id><published>2011-03-21T16:17:00.004+08:00</published><updated>2011-03-22T23:09:01.773+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] iif in Python</title><content type='html'>If you want to implement iif in Python,&lt;br /&gt;please refer to the following sample code:&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def iif(b):&lt;br /&gt;  return 'It\'s True' if b else 'It\'s False'&lt;br /&gt;&lt;br /&gt;print iif(True)&lt;br /&gt;print iif(False)&lt;br /&gt;&lt;/pre&gt;And the following sample, guess what will you get!&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;b = True&lt;br /&gt;print 'b: %s' % 'Ture' if b else 'False'&lt;br /&gt;b = False&lt;br /&gt;print 'b: %s' % 'Ture' if b else 'False'&lt;br /&gt;&lt;/pre&gt;Result:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;$ ./iif.py &lt;br /&gt;b: Ture&lt;br /&gt;False&lt;br /&gt;&lt;/pre&gt;The second result is "False", not "b: False". Why???&lt;br /&gt;Because the prededence of string concatenation is higher than if.&lt;br /&gt;Therefore you need to use () to make it correct.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;b = True&lt;br /&gt;print 'b: %s' % 'Ture' if b else 'False'&lt;br /&gt;b = False&lt;br /&gt;print 'b: %s' % ('Ture' if b else 'False')&lt;br /&gt;&lt;/pre&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6679150306854422855?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6679150306854422855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-iif-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6679150306854422855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6679150306854422855'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-iif-in-python.html' title='[Level 2] iif in Python'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-1443384481419166498</id><published>2011-03-21T14:28:00.000+08:00</published><updated>2011-03-21T14:28:52.920+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] Implement prefix and netmask transfer with Python.</title><content type='html'>Sometimes, you want to transfer between netmask and prefix setting.&lt;br /&gt;You can use the following sample script which is written by Python.&lt;br /&gt;&lt;pre class="prettyprint lang-py linenums:1"&gt;#!/bin/env python&lt;br /&gt;def transferPrefix2Netmask(self, prefix):&lt;br /&gt;        netmask = ''&lt;br /&gt;        nLeadingFF = prefix / 8&lt;br /&gt;        netmask += '.'.join(['255']*nLeadingFF)&lt;br /&gt;        if nLeadingFF != 4:&lt;br /&gt;            netmask += '.' + str(256-2**(8-prefix%8))&lt;br /&gt;        nSuffix00 = 3 - nLeadingFF&lt;br /&gt;        if nLeadingFF &amp;lt; 3:&lt;br /&gt;            netmask += '.' + '.'.join(['00']*nSuffix00)&lt;br /&gt;        return netmask&lt;br /&gt;    &lt;br /&gt;    def transferNetmask2Prefix(self, netmask):&lt;br /&gt;        prefix = 0&lt;br /&gt;        left = 0&lt;br /&gt;        for i in netmask.split('.'):&lt;br /&gt;            if i == '255':&lt;br /&gt;                prefix += 8&lt;br /&gt;            else:&lt;br /&gt;                left = int(i)&lt;br /&gt;                break&lt;br /&gt;        if left != 0:&lt;br /&gt;            for n in range(7, 0, -1):&lt;br /&gt;                prefix += 1&lt;br /&gt;                if left - 2 ** n == 0:&lt;br /&gt;                    break&lt;br /&gt;                else:&lt;br /&gt;                    left -= 2 ** n&lt;br /&gt;        return prefix&lt;br /&gt;&lt;br /&gt;print transferPrefix2Netmask(16)&lt;br /&gt;print transferPrefix2Netmask(17)&lt;br /&gt;print transferPrefix2Netmask(18)&lt;br /&gt;print transferPrefix2Netmask(22)&lt;br /&gt;print transferPrefix2Netmask(23)&lt;br /&gt;print transferPrefix2Netmask(24)&lt;br /&gt;print transferNetmask2Prefix('255.255.128.0')&lt;br /&gt;print transferNetmask2Prefix('255.255.192.0')&lt;br /&gt;print transferNetmask2Prefix('255.255.252.0')&lt;br /&gt;print transferNetmask2Prefix('255.255.254.0')&lt;br /&gt;print transferNetmask2Prefix('255.255.255.0')&lt;br /&gt;print transferNetmask2Prefix('255.255.255.128')&lt;br /&gt;print transferNetmask2Prefix('255.255.255.192')&lt;br /&gt;print transferNetmask2Prefix('255.255.255.252')&lt;br /&gt;print transferNetmask2Prefix('255.255.255.254')&lt;br /&gt;print transferNetmask2Prefix('255.255.255.255')&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-1443384481419166498?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/1443384481419166498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-implement-prefix-and-netmask.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1443384481419166498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/1443384481419166498'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-implement-prefix-and-netmask.html' title='[Level 2] Implement prefix and netmask transfer with Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-6019888239933336586</id><published>2011-03-21T14:25:00.000+08:00</published><updated>2011-03-21T14:25:12.708+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><category scheme='http://www.blogger.com/atom/ns#' term='Networking'/><title type='text'>[Level 2] How to reset interface seq. no in Ubuntu</title><content type='html'>&lt;pre class="prettyprint lang-html linenums:1"&gt;If you want to reset the seq. no of interface.&lt;/pre&gt;&lt;pre class="prettyprint lang-html linenums:1"&gt;You can remove the record in /etc/udev/rules.d/70-persistent-net.rules. &lt;/pre&gt;&lt;br /&gt;Wish this helps.&lt;br /&gt;regards,&lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-6019888239933336586?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/6019888239933336586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-how-to-reset-interface-seq-no.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6019888239933336586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/6019888239933336586'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-how-to-reset-interface-seq-no.html' title='[Level 2] How to reset interface seq. no in Ubuntu'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-8314564407521292152</id><published>2011-03-19T22:31:00.002+08:00</published><updated>2011-06-28T14:39:54.675+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OpenSSL'/><category scheme='http://www.blogger.com/atom/ns#' term='Level 2'/><title type='text'>[Level 2] How to change passphrase by openssl in.</title><content type='html'>If your company give you the key and cert for openvpn,&lt;br /&gt;but somehow you want to change the passphrase that you easy to remember.&lt;br /&gt;You can use openssl to modify the passphrase.&lt;br /&gt;The sample as below:&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cccccc;"&gt;Step 1, Remove the password:&lt;br /&gt;# openssl rsa -in client.key -out client2.key&lt;/div&gt;&lt;div style="background-color: #cccccc;"&gt;(It will prompt you for the current password, and write the decrypted key to client2.key)&lt;/div&gt;&lt;div style="background-color: #cccccc;"&gt;Step 2, Add or change the password:&lt;br /&gt;# openssl rsa -in client.key -out client2.key -des3&lt;/div&gt;&lt;div style="background-color: #cccccc;"&gt;(It will prompt you for the current password (if any), then for the new password, and then write the encrypted key to client2.key)&lt;/div&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-8314564407521292152?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/8314564407521292152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-how-to-change-passphrase-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8314564407521292152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/8314564407521292152'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-2-how-to-change-passphrase-by.html' title='[Level 2] How to change passphrase by openssl in.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-7236803214057985323</id><published>2011-03-18T17:43:00.002+08:00</published><updated>2011-03-18T17:43:45.737+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] How to implement "Press any key to continue" in Python.</title><content type='html'>When you develop a terminal program,&lt;br /&gt;you always need a function to "Press any key to continue",&lt;br /&gt;but how to implement it in Python script.&lt;br /&gt;&lt;br /&gt;I found out a sample on here:&lt;br /&gt;&lt;a href="http://code.activestate.com/recipes/134892/"&gt;http://code.activestate.com/recipes/134892/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Wish this helps.  &lt;br /&gt;regards, &lt;br /&gt;Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-7236803214057985323?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/7236803214057985323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-3-how-to-implement-press-any-key.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7236803214057985323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/7236803214057985323'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-3-how-to-implement-press-any-key.html' title='[Level 3] How to implement &quot;Press any key to continue&quot; in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8444186573141677286.post-4364978993673264307</id><published>2011-03-18T16:56:00.000+08:00</published><updated>2011-03-18T16:56:41.065+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Level 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>[Level 3] How to implement reflection in Python.</title><content type='html'>The Python Code:&lt;br /&gt;&lt;pre class="prettyprint lang-python linenums:1"&gt;#!/bin/env python&lt;br /&gt;def f1():&lt;br /&gt;  exec 'a=1'&lt;br /&gt;&lt;br /&gt;def f2():&lt;br /&gt;  exec 'global a; a=2'&lt;br /&gt;&lt;br /&gt;def f3():&lt;br /&gt;  print a&lt;br /&gt;&lt;br /&gt;global a&lt;br /&gt;a=0&lt;br /&gt;f1()&lt;br /&gt;f3()&lt;br /&gt;f2()&lt;br /&gt;f3()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The output is:&lt;br /&gt;&lt;pre class="prettyprint lang-html"&gt;# /tmp/t.py &lt;br /&gt;0&lt;br /&gt;2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see,&lt;br /&gt;The f1() function cannot modify global variable "a" successfully,&lt;br /&gt;we can say that, exec is a fact function, and unless you declare a variable as a global variable,&lt;br /&gt;or you just deal with a local variable. Like f1()&lt;br /&gt;So if you want to deal with global variable,&lt;br /&gt;please remember to declare it as the global variable first. Like f2()&lt;br /&gt;&lt;br /&gt;Wish this helps.  regards, Stanley Huang&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8444186573141677286-4364978993673264307?l=stanley-huang.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stanley-huang.blogspot.com/feeds/4364978993673264307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-3-how-to-implement-reflection-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4364978993673264307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8444186573141677286/posts/default/4364978993673264307'/><link rel='alternate' type='text/html' href='http://stanley-huang.blogspot.com/2011/03/level-3-how-to-implement-reflection-in.html' title='[Level 3] How to implement reflection in Python.'/><author><name>Stanley Huang</name><uri>http://www.blogger.com/profile/08590821090529939664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://3.bp.blogspot.com/_3Hws32V6QEg/SpKL8U_dJNI/AAAAAAAAAGc/uQXgb_HIiWM/S220/stanley_SunTechDay.jpg'/></author><thr:total>0</thr:total></entry></feed>
