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

Wednesday, December 5, 2007

How to select count distinct number of two columns in SQL?

Note count (distinct column1, column2) is invalid.

You could use self join like this:

SELECT count(*) FROM table a FULL JOIN table b ON (a.column1 = b.column1 AND a.column2 = b.column2);

You could use sub query like this:

SELECT count(*) FROM ( SELECT 1 FROM table GROUP BY column1, column 2 ) zz ;
zz is the alias for sub-SELECT

You could use || like this:

SELECT count(distinct column1||'%'||column2 ) FROM table;

Maybe should use " instead of ' in some machine. And you also could use other words other than % to avoid mistakes.

Tuesday, December 4, 2007

Be indexed by Google

Home page crawl:

Googlebot last successfully accessed your home page on Dec 2, 2007.

Also registered Google Analytics for this blog, Currently:
0 Visits
0 Pageviews

:-(

Sunday, December 2, 2007

SQL JOIN

JOIN == INNER JOIN
LEFT JOIN == LEFT OUTER JOIN
RIGHT JOIN == RIGHT OUTER JOIN
FULL JOIN == FULL OUTER JOIN


Why we use "OUTER" ???

Saturday, December 1, 2007

How to get program's directory in python?

import os

path = os.path.dirname(__file__) to get the path of .py file.

os.path.dirname returns the directory component of a pathname, __file__ is the full path of .py file.

os.path is a useful module, see the doc:
http://docs.python.org/lib/module-os.path.html

Thursday, November 29, 2007

Setup my adsense account

Finally I have setup my Google adsense account.
Cheers!

Wednesday, November 28, 2007

What is fairfox?

[It is copied from somewhere]

The Fairfox

The god of thought, Alger, created the Fairfox in his own mental image. In the time before mechanization, Alger believed that humans needed a sparring partner to enhance their mental abilities. To confront only the brightest of human beings, Alger created a large furry creature called the Fairfox.

The Fairfox was first made to look like an overly large fox with the most cunning mind of all magical creatures. Over time, little has changed in the Fairfox appearance; they have grown a little larger and slightly fatter than their ancestors, but they have also grown more intelligent in order to keep up with leaps in human intellectual thought.

Fairfoxes are quite particular about their habitat. They will only exist in warm forested areas and they will hibernate through any cold periods. Fairfoxes also insist on a plentiful source of fresh water nearby, as the creature is known for his fastidiously clean nature. Fairfoxes feed on wild flowers, usually pink ones, and will occasionally attack and consume particularly brainless adventurers who may seek them out.

Although Fairfoxes may have occasionally lapses in good nature, they are generally benign creatures. They will most often merely ask questions of adventures that cross their paths and even when an adventurer answer the question incorrectly, it is said that if the proper respect and admiration is given to any Fairfox, he will refrain from attacking.

It is also said that the further etiquette must be practiced when dealing with a Fairfox. The Fairfox should always be addressed as “Sir;” since there are no female Fairfoxes this is a safe title. Lore also calls for the adventurer to ask few questions, if any, of the Fairfox. They do not enjoy answering inane questions and it is nearly impossible to stump one with a riddle. It is unwise to attempt to bribe a Fairfox, unless the adventurer uses a bouquet of pink flowers. If an adventurer does succeed in answering whatever riddles the Fairfox throws at him, he should not boast to others about his deed. These claims almost always get back to the Fairfox and an angry Fairfox is a dangerous Fairfox.

The dangers laid aside, Fairfoxes are amazing intellectuals and have a wealth of knowledge at their disposal due to their long life span and frequent communication with Alger. If an adventurer can convince a Fairfox to confide in him,he is blessed indeed. Fairfoxes often know the paths to treasure and relics and since they have no interest in material goods themselves, they do not dread parting with such information as long as the adventurer has earned it.