This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install PostgreSQL 9 in Mac OSX via Homebrew | |
Mac OS X Snow Leopard | |
System Version: Mac OS X 10.6.5 | |
Kernel Version: Darwin 10.5.0 | |
Install notes for PostgreSQL 9.0.1 install using Homebrew: | |
sh-3.2# brew install postgresql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import psycopg2 | |
>>> conn = psycopg2.connect(database='mydb', user='eric', password='eric') | |
>>> cur = conn.cursor() | |
>>> cur.execute('''create table users(id serial, name varchar(25));''') | |
>>> conn.commit() | |
>>> cur.execute('''insert into users(name) values('eric');''') | |
>>> conn.commit() | |
>>> cur.execute('''select * from users''') | |
>>> for row in cur.fetchall(): | |
... print row[0], row[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WillPaginate | |
module ViewHelpers | |
@@pagination_options.merge!({ | |
:previous_label => '上一页', | |
:next_label => '下一页' | |
}) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_key | |
new_record? ? nil : [ self.send(self.class.primary_key) ] | |
end | |
# Ruby中 respond_to? 和 send 的用法 http://hi.baidu.com/you5a_com/blog/item/4f80cd33a9e65da25fdf0e5d.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: t = True and 'dfsfsdf' or '' | |
In [2]: t | |
Out[2]: 'dfsfsdf' | |
In [3]: t = 'dfsfsdf' if True else '' | |
In [4]: t | |
Out[4]: 'dfsfsdf' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#coding=utf8 | |
from weibopy.auth import BasicAuthHandler | |
from weibopy.api import API | |
import optparse | |
import os | |
import time | |
class Weibo(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last; | |
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last; | |
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; | |
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; | |
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; | |
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last; | |
rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last; | |
if (!-e $request_filename) { | |
return 404; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cur.execute("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'xxx' AND TABLE_NAME LIKE 'pre%'") | |
rows = cur.fetchall() | |
for row in rows: | |
cur.execute("DROP TABLE %s"%row[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
修改系统时间 | |
root@vps:/etc# mv localtime localtime_bak | |
root@vps:/etc# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | |
root@vps:/etc# date | |
Sun Nov 7 23:20:04 CST 2010 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import re | |
import os | |
import logging | |
def detect(request): | |
user_agent = request.headers['User-Agent'] | |
result = {} | |
result['ua'] = user_agent |