This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
""" Child threads with join | |
Main thread wait unit all child threads terminate. | |
""" | |
import threading | |
from time import sleep |
This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
import logging | |
def get_logger(): | |
# Get a logger, default is the root logger. | |
logger = logging.getLogger('mylogger') |
This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
""" 测试 Python 在什么情况下会输出 Unicode 字符串 | |
需要首先理解在 Python 中 Unicode 类型和 Unicode 字符串指的不是同一个东西。 | |
Unicode 字符串是 str 类型,但它的值的表现形式是 Unicode 编码形式。 | |
""" | |
def printt(str): |
This file contains 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
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc | |
. ~/.bashrc | |
mkdir ~/local | |
mkdir ~/node-latest-install | |
cd ~/node-latest-install | |
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 | |
./configure --prefix=~/local | |
make install # ok, fine, this step probably takes more than 30 seconds... | |
curl -L https://www.npmjs.org/install.sh | sh |
This file contains 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
# 查找出当前文件夹中以 x 开头的文件,文件名作为参数传给 python 脚本,然后放到后台执行 | |
for i in x* | |
do | |
python t.py $i & | |
done |
This file contains 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
# http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.Transaction | |
from sqlalchemy import create_engine | |
engine = create_engine("postgresql://scott:tiger@localhost/test") | |
connection = engine.connect() | |
trans = connection.begin() | |
connection.execute("insert into x (a, b) values (1, 2)") | |
trans.commit() |
This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
""" | |
用多进程模拟数据库事务在并发环境下的表现。 | |
测试环境: | |
一个数据库 server, 4 核机器, 四个进程 | |
运行结果:: | |
run 0 process | |
run 1 process |
This file contains 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
# python cors_server.py | |
import SimpleHTTPServer | |
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
def send_head(self): | |
"""Common code for GET and HEAD commands. | |
This sends the response code and MIME headers. | |
Return value is either a file object (which has to be copied |
This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
# 参考资料: | |
# * https://en.wikipedia.org/wiki/Advanced_Encryption_Standard | |
# * https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation | |
# | |
# Show AES document: | |
# > from Crypto.Cipher import AES | |
# > help(AES) |
This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
# 参考资料: | |
# * https://en.wikipedia.org/wiki/RSA | |
# | |
# Show RSA document: | |
# > from Crypto.PublicKey import RSA | |
# > help(RSA) | |
from Crypto.PublicKey import RSA |
OlderNewer