Skip to content

Instantly share code, notes, and snippets.

View lwzm's full-sized avatar
🎯
Focusing

Weizhao Li lwzm

🎯
Focusing
View GitHub Profile
create table t1 (id integer primary key, name text, x text);
insert into t1 (name, x) values('n1', 'xxx');
insert into t1 (name, x) values('n2', 'xxx');
insert into t1 (name, x) values('n3', 'xxx');
insert into t1 (name, x) values('n4', 'xxx');
create table t2 (id integer primary key, name text);
insert into t2 (name) values('_1');
insert into t2 (name) values('_2');
insert into t2 (id, name) values(-1, 'q');
from gunicorn.http.body import Body
Body.readable = lambda _: True
Body.writable = lambda _: False
Body.seekable = lambda _: False
Body.closed = False
@lwzm
lwzm / Caddyfile
Last active December 9, 2019 02:01
caddy server: webdav
http://* {
webdav
gzip
log / stderr "{when_iso} {remote} {method} {uri} {proto} {status} {size} {latency} {>Content-Length} {>User-Agent}"
#log / stderr "{when_iso} {remote} {method} {uri} {status} {request_body}"
}
#!/usr/bin/env python3
import io
import tempfile
import urllib.request
def open_rb(filename):
if filename.startswith("http://") or filename.startswith("https://"):
return urllib.request.urlopen(filename)
import importlib
import sys
name = sys.argv[1]
if name.endswith(".py"):
name = name[:-3].replace("/", ".")
if __name__ == '__main__':
m = importlib.import_module(name)
print(m.main())
@lwzm
lwzm / app.py
Last active August 5, 2022 14:37
gunicorn and pyinstaller and file-upload-app
#!/usr/bin/env python3
import shutil
from flask import Flask, Response, request
app = Flask(__name__)
@app.route('/<path:path>', methods=['GET', 'POST'])
def hello(path):
cmd="$1"
dir=$(dirname $(realpath $cmd))
$cmd &
pyinstaller_ppid="$!"
#echo $pyinstaller_ppid
#ps -o pid,ppid
@lwzm
lwzm / nginx.py
Last active November 7, 2019 10:09
#!/usr/bin/env python3
import sys
from string import Template
tpl = Template("""
upstream ${name} {
server ${name}${port};
keepalive 64;
}
import sys
for line in sys.stdin:
print(repr(line))
import gzip
with gzip.open(fn, 'rt') as f:
for i in f:
print(i)