Skip to content

Instantly share code, notes, and snippets.

View tonyseek's full-sized avatar

Jiangge Zhang tonyseek

View GitHub Profile
@tonyseek
tonyseek / android-captive.sh
Last active April 2, 2024 02:49
Overrides the captive portal settings of Android in the People's Republic China mainland
#!/usr/bin/env sh
## I don't have any devices running Android OS now. These settings may have been outdated but I cannot verify it.
adb shell settings put global captive_portal_fallback_url http://g.cn/generate_204
adb shell settings put global captive_portal_http_url http://www.google.cn/generate_204
adb shell settings put global captive_portal_https_url https://www.google.cn/generate_204
adb shell settings put global captive_portal_other_fallback_urls http://www.qualcomm.cn/generate_204
@tonyseek
tonyseek / supervisord.service
Created August 8, 2014 07:11
Running supervisord with systemd.
[Unit]
Description=supervisord - Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecReload=/usr/bin/supervisorctl reload
ExecStop=/usr/bin/supervisorctl shutdown
@tonyseek
tonyseek / setup.py
Last active November 20, 2023 11:51
Parse __version__ from your Python package without importing it
#!/usr/bin/env python3
import ast
from setuptools import setup
def parse_version(pkg_init_path, version_name='__version__'):
with open(pkg_init_path) as pkg_init_file:
pkg_init_ast = ast.parse(pkg_init_file.read())
@tonyseek
tonyseek / gi
Last active March 9, 2023 04:00
"gi tfetch" => ~/.local/bin/gi tfetch => gti fetch => git fetch (but with a car)
#!/bin/bash
set -e
if [[ $1 == t* ]]; then
exec gti "${1#t}"
fi
>&2 printf 'command not found: gi\n'
exit 127
@tonyseek
tonyseek / leader-election.py
Created March 6, 2023 14:15
Elect a leader in multiprocess program with unnamed domain socket
import os
import signal
import collections
import logging
import resource
logging.basicConfig(level=logging.DEBUG)
@tonyseek
tonyseek / README.rst
Last active November 5, 2022 15:20
Build Python binding of C++ library with cffi (PyPy/Py3K compatible)

Run with Python:

pip-2.7 install cffi
PYTHON=python2.7 sh go.sh

Run with PyPy:

pip-pypy install cffi
PYTHON=pypy sh go.sh
@tonyseek
tonyseek / Usage.markdown
Created November 28, 2012 12:46
Visualizing Gcc's AST
@tonyseek
tonyseek / formula.py
Last active June 28, 2022 09:13
render latex formula with matplotlib and pillow.
try:
from StringIO import StringIO as BytesIO
except ImportError:
from io import BytesIO
import matplotlib.pyplot as plt
def render_latex(formula, fontsize=12, dpi=300, format_='svg'):
"""Renders LaTeX formula into image."""
@tonyseek
tonyseek / miniconda3
Last active May 24, 2022 13:55
~/.local/bin/miniconda3
#!/usr/bin/env bash
set -e
IMAGE="docker.io/continuumio/miniconda3:latest"
HOST_CONDA_DIR="/opt/conda"
HOST_NOTEBOOK_DIR="${PWD}"
HOST_NOTEBOOK_PORT="8888"
podman_cmd=("${@:-/bin/bash}")
"""
ZooKeeper Monitor
=================
This is a simple script to monitor ZooKeeper node by "mntr" command. The
command response will be collected to the statsd server.
"""
import argparse
import logging