Skip to content

Instantly share code, notes, and snippets.

from __future__ import print_function
import dis
def f1():
x = 'a' * 20
y = 'a' * 20
return x is y
@mrluanma
mrluanma / README.md
Last active August 1, 2017 01:22
使用 requests + concurrent.futures 并发的访问 HTTP 服务示例
$ python t.py
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): example.net
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (2): example.net
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (3): example.net
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (4): example.net
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (5): example.net
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (6): example.net
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (7): example.net
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (8): example.net
# -*- coding: utf-8
from lxml import etree as ET
from io import BytesIO
gb2312_xml = u"""<?xml version="1.0" encoding="gb2312" ?>
<node>中文</node>""".encode("gb2312")
print(ET.tostring(ET.parse(BytesIO(gb2312_xml)), encoding="utf-8"))
@mrluanma
mrluanma / api.example.net.conf
Created September 9, 2014 08:27
cache POST request with Nginx
upstream api_example_net {
server api.example.net:4000;
keepalive 600;
}
proxy_cache_path /var/cache/nginx/tag levels=1:2 keys_zone=tag:10m inactive=1d max_size=10g;
server {
listen 80;
server_name api.example.net;
upstream hurl_proxy {
server www.hurl.it;
keepalive 600;
}
server {
listen 80;
server_name hurl.example.com;
access_log /var/log/nginx/hurl_proxy.access.log;
import ast
from ast import Assign, Name, Call, Store, Load, Str, Num, List, Add, BinOp
from ast import Subscript, Slice, Attribute, GeneratorExp, comprehension
from ast import Compare, Mult
import codegen
import random
import sys
def random_string(minlength, maxlength):
@mrluanma
mrluanma / tips.md
Last active January 12, 2016 06:26

JSON 支持 UTF-8 编码的 string

我们的好多地方都使用了一行一个 JSON 对象的格式,并且这个 JSON 里一般含有中文,默认 Python 的 json.dumps 会对中文进行转义。也就是说:

In [2]: print(json.dumps(['我', '爱', 'Python']))
["\u6211", "\u7231", "Python"]
-- [[ Implementation of MergeSort --]]
-- merge an array split from p-q, q-r
merge = (A, p, q, r) ->
n1 = q - p + 1
n2 = r - q
left = {}
right = {}
for i = 1, n1
@mrluanma
mrluanma / app.py
Last active November 9, 2020 16:23
log X-Request-Id in uwsgi
import bottle
app = bottle.Bottle()
@app.route('/')
def index():
return "Hello world!"
ppa:saltstack/salt
ppa:chris-lea/uwsgi
ppa:nginx/stable
ppa:chris-lea/redis-server