TAG

首都機能移轉 (2) 歌詞 (2) 靠北文 (40) 戲言 (30) 糟糕 (7) ACG (23) Assembly (2) Boost (2) C (31) C++ (69) CMake (4) CSIE (67) Debian (34) Design_Pattern (2) Django (1) Eclipse (1) en_US (13) FFmpeg (3) FoolproofProject (26) FreeBSD (2) Git (4) GNU_Linux (65) IDE (5) Java (11) JavaScript (19) KDE (15) Khopper (16) KomiX (3) Kubuntu (18) Life (1) Lighttpd (2) Mac_OS_X (2) Opera (1) PHP (2) PicKing (2) Programing (21) Prolog (1) Python (7) QSnapshot (2) Qt (30) Qt_Jambi (1) Regular_Expression (1) Shell_Script (7) Talk (98) VirtualBox (7) Visual_Studio (13) Windows (18) zh_TW (36)
顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2012年7月15日 星期日

Garbage Collection (1)

這篇只是介紹比較知名的方法,預計之後還會再發一兩篇討論 C++/Qt 的回收手法。

2011年6月23日 星期四

Configure Django with Lighttpd on Debian/Ubuntu

網路上找到的資料都有點不完全, 最近在逃避現實的過程中找到了一個比較簡單的方式, 供有需要的人參考.

2011年1月23日 星期日

Use pyside-uic to compile ui files automatically

PySide 可以用 pyside-uic 來轉換 *.ui 到 python code,但每次都要手動弄這個真的很煩。所以我把所有的 ui 檔案集中放到一個資料夾內作為 package,並在 __init__.py 上動點手腳:

2008年6月6日 星期五

git compress tarbell script - in Python

#! /usr/bin/env python
#-*- coding: utf-8 -*-

import sys, os, bz2, time, optparse

BASE = os.path.basename( os.getcwd() )
TIMESTAMP = time.strftime( '%Y%m%d' )

def main( args = None ):
    if args is None:
        args = sys.argv
    parser = optparse.OptionParser( usage='usage: %prog [options] ' )
    parser.add_option( '-s', '--spec', type='string', dest='spec', help='explicitly sets version string' )
    parser.add_option( '--prefix', type='string', dest='prefix', help='string that before version' )
    parser.add_option( '--postfix', type='string', dest='postfix', help='string that append to timestamp' )
    parser.add_option( '-q', '--quiet', action='store_false', dest='verbose', help='be vewwy quiet (I\'m hunting wabbits)' )
    parser.set_defaults( verbose=True )
    opts, args = parser.parse_args( args=args[1:] )
    if len( args ) < 1:
        parser.print_help()
        return 1

    fileName = '%s-%s.%s' % ( BASE if opts.prefix is None else opts.prefix, args[0] if opts.spec is None else opts.spec, TIMESTAMP )
    if opts.postfix is not None:
        fileName += '-' + opts.postfix
    rData = os.popen( 'git archive --format=tar %s --prefix=%s/ %s' % ( '--verbose' if opts.verbose else '', fileName, args[0] ) ).read()
    cData = bz2.compress( rData )
    fout = open( '%s.tbz2' % fileName , 'wb' )
    fout.write( cData )
    fout.close()
    if opts.verbose:
        print "== compression ==\nbefore:\t%d\nafter:\t%d\nrate:\t%f%%" % ( len( rData ), len( cData ), 100.0 - ( 100.0 * len( cData ) / len( rData ) ) )
 
    return 0

if __name__ == '__main__':
    sys.exit( main() )

我真的覺得Python太好用了....還有我一直沒在做正事= =

2008年4月20日 星期日

だるい

#! /usr/bin/env python
#-*- coding: utf-8 -*-

for second in xrange( 睡醒, 現在 ):
    self.setState( u'不想唸書' )

2008年1月31日 星期四

防火牆修復

在遠端登入時如果不小心把防火牆搞爛了,可是非常麻煩的事,因為你很有可能無法再次遠端登入來修復防火牆;所以前幾天用python寫了個程式,在伺服器完全斷線時可以先讓防火牆恢復正常。
#! /usr/bin/env python
# -*- encoding: utf-8 -*-

import os, time, sys

def connect_test( *sites ):
        for site in sites :
                if os.system( "wget --tries=2 --timeout=120 -O - %s >/dev/null 2>&1" % site ) == 0 :
                        return True
        return False

flog = open( '/var/log/firewall_fix.log', 'a' )
timestamp = time.strftime( '%Y/%m/%d %H:%M' )

if connect_test( 'http://www.google.com/' ):
        print >> flog, "%s\tSuccess and do nothing.\n" % timestamp
else:
        try:
                if os.system( 'iptables-restore <%s >/dev/null 2>&1' % sys.args[1] ) != 0 :
                        raise OSError
                else:
                        print >> flog, "%s\tFirewall fixed. ( Use `%s'. )\n" % ( timestamp, sys.args[1] )
        except ( IndexError, OSError ):
                os.system( 'iptables -F' )
                for chain in [ 'INPUT', 'OUTPUT', 'FORWARD' ] :
                        os.system( "iptables -P %s ACCEPT" % chain )
                print >> flog, "%s\tFirewall fixed. ( Flush all. )\n" % timestamp

flog.close()

中間的連線測試其實滿dirty的[?],不過目前想不到其他更好的辦法。
噢,對了,Linux only。
2008/2/08 edited. Few code changed.