Tuesday, April 8, 2008

Create a web site by Google App Engine

http://moma.appspot.com
Coming soon! haha!

Google App Engine:
http://code.google.com/appengine/

Tuesday, April 1, 2008

python class method

>>> class SomeClass(object):
... total = 0
... @classmethod
... def GetTotal(cls):
... return cls.total
... @classmethod
... def Add(cls, num):
... cls.total = cls.total + num
...
>>>
>>> A = SomeClass()
>>> B = SomeClass()
>>>
>>> A.GetTotal()
0
>>> B.Add(10)
>>> A.GetTotal()
10
>>> B.GetTotal()
10

Tuesday, March 4, 2008

Usage of grep

grep [OPTION] PATTERN [FILE]

Example:
Count for lines contain numbers:
grep -E '[0-9]+' -c filename

-E means extended regular expression
-c means to print a count of matching lines per file, otherwise it will print all suitable lines.

Monday, February 25, 2008

How to remove a file whose name starts with a - (minus)

use one of these commands:
rm -- -foo

rm ./-foo

Tuesday, February 19, 2008

How to lock screen in Ubuntu?

Ctrl + Alt + L

Thursday, February 14, 2008

Singleton in Python

We don't need Singleton in Python. We need singleton just because we need some static data and static functions. In Python we can simply use following code:

def InitStaticData(data):
pass

class Global(object):
""" A global class to store static data."""
__private_data = xxx
static_data = InitStaticData(__private_data) //assume it's a list.


def ReadStaticData(arg):
return Global.StaticData[arg]

The Global class itself will be initialized for one time. And we can define related static function in the module. The only thing we should do is: do not use __init__ of Global.

Keep in mind: in Python, each module is itself an object without having to define an explicit class.

Sunday, February 10, 2008

An abbreviation for Delivery

How about Dlvry?

Wednesday, January 23, 2008

How to check your disk quota under Linux

df --help

Monday, January 7, 2008

Usage of CAST in SQL

CAST( Var AS Type)
e.g.
Select CAST(1 AS Boolean);
true
Select CAST("123" AS INT);
123