Posts

Showing posts from May, 2013

[ Level 1 ] create cpio file with find.

Cpio is a good tool to pack files in one image, and it's fast. You could use find command to find files that you want and also use gzip to compress it. ex. $ find ./ -print | cpio -o -Hnewc | gzip > /tmp/my.cpio.gz Wish this helps. regards, Stanley Huang

[ Level 2 ] Create an egg for Python in Ubuntu.

How to create an egg file for Python. First of all, you must have setuptools module. $ sudo apt-get -y install python-setuptools Now, you could try to create an empty egg now. $ mkdir /tmp/demo $ cd /tmp/demo $ cat &ht; ./setup.py <<EOF #!/bin/env python #-*- coding:utf-8 -*- from setuptools import setup setup() EOF $ python setup.py bdist_egg ## bdist_egg is the option for creating egg. $ ls -ALb build dist setup.py UNKNOWN.egg-info You could find, we have three more directories after you execute setup.py build -> dist -> final egg file UNKNOW.egg-info -> egg info Now, we could give setuptools more information about egg. cat > ./setup.py <<EOF #!/bin/env python #-*- coding:utf-8 -*- from setuptools import setup, find_packages setup( name = "my_first_egg", version="0.0.1", packages = find_packages(), zip_safe = False, description = "my first egg.", long_descriptio...

[ Level 2 ] Fix duplicate vg/lv name.

1. scan vgs: $ vgscan 2. get vg information: $ vgdisplay --- Volume group --- VG Name vg00 ... VG UUID FUoK9F-9mgs-jO4M-vub1-Y7zs-6wpQ-uM2S11 --- Volume group --- VG Name vg00 ... VG UUID FUoK9F-9mgs-jO4M-vub1-Y7zs-6wpQ-uM2S12 3. export vg $ vgexport 4. rename vg name $ vgrename FUoK9F-9mgs-jO4M-vub1-Y7zs-6wpQ-uM2S12 vg01 5. import vg $ vgimport vg01 6. get vg information: $ vgdisplay --- Volume group --- VG Name vg00 ... VG UUID FUoK9F-9mgs-jO4M-vub1-Y7zs-6wpQ-uM2S11 --- Volume group --- VG Name vg01 ... VG UUID FUoK9F-9mgs-jO4M-vub1-Y7zs-6wpQ-uM2S12 7. get lv information $ lvscan ACTIVE '/dev/vg00/lv00' [13.99 GiB] inherit inactive '/dev/vg01/lv00' [13.99 GiB] inherit 8. active vg01 $ vgchange --ignorelockingfailure --noudevsync --sysinit -ay vg01 >/dev/null 2>&1 && 9. rename lv name(optio...

[ Level 2 ] Get last argument in bash.

You could use the following methods to get the last argument that you pass to script. #!/bin/bash getLastArg1() { for last do true done echo $last } getLastArg2() { echo $@ | awk '{print($NF)}' } getLastArg3() { eval echo `echo \\$${#@}` } getLastArg1 $@ getLastArg2 $@ getLastArg3 $@ $ ./test.sh a b c c c c $ Wish this helps. regards, Stanley Huang

[ Level 3 ] Test your Python code.

Ref: https://python-guide.readthedocs.org/en/latest/writing/tests.html Mock: http://www.voidspace.org.uk/python/mock/getting-started.html# Wish this helps. regards, Stanley Huang

[ Level 2 ] Tips of unittest for Python.

There are tips for Python: 1. Use mock for replace method. ex. myMock=mox.Mox() myMock.StubOutWithMock(myModule, 'replaceMethod') myModule.replaceMethod(input).AndReturn('Hello World!') myMock.ReplayAll() expected = 'Hello World!' self.assertEqual(module.replaceMethod(input), expected) myMock.VerifyAll() #verify if all mocks be executed. myMock.UnsetStubs() #release all mocks 2. Use -m to test one method only. ex. $ python -m unittest myApp.TestClass.testMethod Wish this helps. regards, Stanley Huang

[ Level 2 ] Coverage in Python.

$ sudo pip install coverage $ coverage run myApp.py arg1 arg2... $ coverage report -m $ coverage html $ coverage help (run) ## or coverage run --help Commands of coverage: run – Run a Python program and collect execution data. report – Report coverage results. html – Produce annotated HTML listings with coverage results. xml – Produce an XML report with coverage results. annotate – Annotate source files with coverage results. erase – Erase previously collected coverage data. combine – Combine together a number of data files. debug – Get diagnostic information. Ref: http://nedbatchelder.com/code/coverage/ http://nedbatchelder.com/code/coverage/cmd.html#cmd Wish this helps. regards, Stanley Huang

[ Level 1 ] The popular MySQL GUI client tools

There are the popular MySQL GUI client tools: . Aqua Data Studio. http://www.aquafold.com/aquadatastudio_downloads.html . CLIENT FOR MYSQL BY ENGINSITE. http://www.enginsite.com/Download.htm . dbForge Studio. http://www.devart.com/dbforge/mysql/studio/ . DBTools Manager. http://www.dbtools.com.br/EN/dbmanagerpro/ . DbVisualizer. http://www.dbvis.com/ . Dreamcoder for MySQL. http://www.sqldeveloper.net/database-tools/mysql/overview.html . HeidiSQL. http://www.heidisql.com/ . Navicat. http://www.navicat.com/en/products/navicat_mysql/mysql_overview.html . MyDB Studio. http://www.mydb-studio.com . phpMyAdmin. http://www.phpmyadmin.net/home_page/ . Sequel Pro. http://www.sequelpro.com/ . SQL Examiner Suite. http://www.sqlaccessories.com/SQL_Examiner_Suite/ . SQL Maestro MySQL Tools Family. http://www.sqlmaestro.com/products/mysql/ . SQLWave. http://www.nerocode.com/ . SQLyog. https://www.webyog.com/ . SQuirreL. http://squirrel-sql.sourceforge.net/ . Toad for MySQL. http://www.quest....

[ Level 3 ] How to build MySQL client tool - mysql

First, you have to download MySQL source and use the following command to build it. $ ./configure --without-server --enable-thread-safe-client --with-client-ldflags=-all-static --prefix=/usr/local/mysql --with-machine-type=powerpc --with-zlib-dir=/usr/local/zlib --without-debug --without-docs --with-big-tables If you don't want to build it, there is a way to get it. (The sample is for Ubuntu only.) $ apt-get install libmysqlclient15-dev Wish this helps. regards, Stanley Huang