Skip to content

Instantly share code, notes, and snippets.

View knwng's full-sized avatar
🐱

Kyle Wang knwng

🐱
View GitHub Profile
@knwng
knwng / gunicorn_callbacks_for_worker_id.py
Last active February 16, 2023 09:14 — forked from hynek/gunicorn_callbacks_for_worker_id.py
This is an attempt to emulate uWSGI’s uwsgi.worker_id() that ensures that I have worker IDs from 1…--workers which is useful in logging and instrumentation where changing PIDs are annoying.
def on_starting(server):
setattr(server, '_worker_id_set', set())
def _next_worker_id(server):
if hasattr(server, '_worker_id_set') and isinstance(server._worker_id_set, set) and len(server._worker_id_set) > 0:
return server._worker_id_set.pop()
in_use = set(w._worker_id for w in tuple(server.WORKERS.values()) if hasattr(w, '_worker_id') and w.alive)
free = set(range(1, server.num_workers + 1)) - in_use
@knwng
knwng / supervisor.conf
Created December 31, 2020 09:26 — forked from tsabat/supervisor.conf
Sample supervisor config file
; Sample supervisor config file.
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
;chmod=0700 ; sockef file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
;[inet_http_server] ; inet (TCP) server disabled by default
@knwng
knwng / gfwlist2regex.py
Last active July 12, 2020 16:35 — forked from gwjwin/gfwlist2regex.py
Download and convert GFWList to url regex which compatible with Squid. Compatible with py3
#!/usr/bin/env python
#encoding: utf-8
import urllib.request
import re
from base64 import b64decode
LIST_URL = 'https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt'
DECODE_FILE = 'decode.txt'
BLACK_FILE = 'gfw.url_regex.lst'
@knwng
knwng / commandline.txt
Created April 24, 2019 13:43 — forked from sandervm/commandline.txt
Generate Django secret key commandline
$ python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'
@knwng
knwng / tensorflow_rename_variables.py
Last active April 5, 2018 02:33 — forked from batzner/tensorflow_rename_variables.py
Small python script to rename variables in a TensorFlow checkpoint
import sys, getopt
import tensorflow as tf
usage_str = 'python tensorflow_rename_variables.py --checkpoint_dir=path/to/dir/ ' \
'--replace_from=substr --replace_to=substr --add_prefix=abc --dry_run'
def rename(checkpoint_dir, replace_from, replace_to, add_prefix, dry_run):