Skip to content

Instantly share code, notes, and snippets.

View tonyseek's full-sized avatar

Jiangge Zhang tonyseek

View GitHub Profile
@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 / 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}")
@tonyseek
tonyseek / ietf-rfc-dl.sh
Last active June 23, 2021 06:42
Download IETF RFC
#!/usr/bin/env bash
set -e
set -o pipefail
RFC_ID="$1"
if ! grep -qE '^[[:digit:]]+$' <<<"$RFC_ID"; then
printf >&2 'Usage: %s RFC_ID\n' "$(basename "$0")"
exit 2
fi
@tonyseek
tonyseek / treecache.py
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):
CONNECTIVE_EVENTS = {
@tonyseek
tonyseek / instance_method_decorator.py
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
self.delta = delta
def __get__(self, instance, owner=None):
method = self.wrapped.__get__(instance, owner)
@tonyseek
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: https://wdd.js.org/vscode-control-characters-problem.html
# https://github.com/Microsoft/vscode/issues/37114
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
tonyseek / mysql-backup.sh
Last active May 28, 2018 14:27
Perform MySQL incremental backup with Percona XtraBackup
#!/bin/sh
set -e
MYSQL_USERNAME='root'
MYSQL_PASSWORD=''
MYSQL_HOST='127.0.0.1'
MYSQL_PORT='3306'
MYSQL_DATADIR='/var/lib/mysql'
@tonyseek
tonyseek / README.md
Last active October 28, 2017 22:42
Downgrade Sketch documents

Downgrade Sketch Document

Why

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