2013年7月3日 星期三

在PosgreSQL有connection的情況下,刪除database或更名database

 
SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname='<db_name>';DROP DATABASE <db_name>;
SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname='<db_name>';ALTER DATABASE <old_db_name> RENAME TO <new_db_name>;

SVN刪除所有missing的檔案

svn st | grep ^! | awk '{print " --force "$2}' | xargs svn rm

2013年3月17日 星期日

Put Spring's applicationContext.xml into src/main/resources folder

The standard folder layout of Maven is quite convenient for me, the applicationContext.xml is put into /webapp/WEB-INF instead of /src/main/resources folder. It conflicts the convention of Maven, therefore I add the following command in web.xml in order to load applicationContext.xml from /webapp/WEB-INF folder.

    contextConfigLocation
    classpath:applicationContext.xml

Reference: stackoverflow

2013年2月20日 星期三

安裝VIM的supertab plugin

SuperTab 網頁下載最新的 supertab.vmb
vim supertab.vmb

# source 這個檔案
:so %
之後在 vim 中,只要用 tab 鍵,就可以做 auto completion

2013年1月23日 星期三

2013年1月3日 星期四

升級到OSX 10.8 (Mountain Lion)後,pip使用遇到問題

升級之後,使用pip安裝套件,卻出現下面這種狀況。
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 5, in 
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in 
    working_set.require(__requires__)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: pip==1.1
這時候要做的事情很容易,只需要把pip做升級,就可以解決這個問題。
sudo easy_install -U pip
Reference: stackoverflow

2012年12月21日 星期五

活用fping監控大量機器的狀態

由於需要管理手中機器的存活狀態,找到了fping這個方便的指令來做這件事情,把需要監控的機器IP寫在一份.txt檔案中,格式如下:

100.65.206.219
100.65.206.220
100.65.206.221
100.65.206.222
100.65.206.223

接著執行這行指令,我在後面加上了

grep unreachable
是因為我只需要知道掛掉的機器是哪些,其中 -r 這個參數是retry的次數, -t 是timeout的長度(in millisec)。
# -r: retry count
# -t: timeout interval (in millisec)
sudo fping -f ip.txt -r 2 -t 50 | grep unreachable
當然,fping不只如此,他還可以指定要掃描的起始IP跟結束IP,或者是指定子網路遮罩。
fping -g 100.65.206.219 100.65.206.223
fping -g 100.65.206.0/24