Skip to content

Instantly share code, notes, and snippets.

View tonyseek's full-sized avatar

Jiangge Zhang tonyseek

View GitHub Profile
tonyseek /
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(
tonyseek / gi
Last active March 9, 2023 04:00
"gi tfetch" => ~/.local/bin/gi tfetch => gti fetch => git fetch (but with a car)
set -e
if [[ $1 == t* ]]; then
exec gti "${1#t}"
>&2 printf 'command not found: gi\n'
exit 127
tonyseek /
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
tonyseek / miniconda3
Last active May 24, 2022 13:55
#!/usr/bin/env bash
set -e
tonyseek /
Last active June 23, 2021 06:42
Download IETF RFC
#!/usr/bin/env bash
set -e
set -o pipefail
if ! grep -qE '^[[:digit:]]+$' <<<"$RFC_ID"; then
printf >&2 'Usage: %s RFC_ID\n' "$(basename "$0")"
exit 2
tonyseek /
Last active July 4, 2019 17:16
Use TreeCache of Kazoo to get node data.
import logging
import threading
from kazoo.client import KazooClient
from kazoo.recipe.cache import TreeCache, TreeEvent
class TreeCacheListener(object):
tonyseek /
Last active November 21, 2018 06:06
The decorator on instance method as a descriptor
import functools
class Increment(object):
def __init__(self, wrapped, delta):
self.wrapped = wrapped = delta
def __get__(self, instance, owner=None):
method = self.wrapped.__get__(instance, owner)
tonyseek / clean_code_wcc
Last active July 21, 2018 08:11
Remove wild control characters from files which was edited by VSCode
#!/usr/bin/env sh
# Clean up the control characters of documents
# See also:
exec find . -type f -name '*.md' -exec perl -pi -e 's/[\x{0000}\x{0001}\x{0002}\x{0003}\x{0004}\x{0005}\x{0006}\x{0007}\x{0008}\x{000b}\x{000c}\x{000d}\x{000e}\x{000f}\x{0010}\x{0011}\x{0012}\x{0013}\x{0014}\x{0015}\x{0016}\x{0017}\x{0018}\x{0019}\x{001a}\x{001b}\x{001c}\x{001d}\x{001e}\x{001f}\x{001c}\x{007f}]//gm' {} +
tonyseek /
Last active May 28, 2018 14:27
Perform MySQL incremental backup with Percona XtraBackup
set -e
tonyseek /
Last active October 28, 2017 22:42
Downgrade Sketch documents

Downgrade Sketch Document


I don't wish to buy Sketch 3 again since I bought it from MacAppStore but lost continue upgrades and 5 devices support. A old version of Sketch will be restricted from opening documents created by the new versions of Sketch.

This is a workaround for some Sketch documents which don't depend on any