Skip to content

Instantly share code, notes, and snippets.

@tanbro
tanbro / Dockerfile
Created March 27, 2025 02:06
Dockerfile for chaquopy
# A Dockerfile for building Python(Chaquo) modules
FROM quay.io/pypa/manylinux_2_28_x86_64 AS base
ARG GRADLE_VERSION=8.13
ARG ANDROID_API_LEVEL=29
ARG ANDROID_BUILD_TOOLS_LEVEL=29.0.3
ARG ANDROID_NDK_VERSION=27.2.12479018
# See also:
# * https://medium.com/@simplatex/how-to-build-a-lightweight-docker-container-for-android-build-c52e4e68997e
@tanbro
tanbro / GIT_SSH_COMMAND.sh
Created January 12, 2025 08:48
GIT_SSH_COMMAND for Socks5 proxy example
GIT_SSH_COMMAND='ssh -o ProxyCommand="connect -S 127.0.0.1:1080 %h %p"'
@tanbro
tanbro / snippetfuncexecutor.py
Created January 15, 2024 04:16
exec and eval a Python code snippet with return expression, as if it's in a non-arguments function
class SnippetFuncExecutor:
"""
exec and eval a Python code snippet with return expression, as if it's in a non-arguments function
"""
def __init__(
self,
*,
prefix: Optional[str] = None,
optimize: int = -1,
@tanbro
tanbro / grab_source_files.py
Last active March 9, 2024 09:33
Export all source code files into a single HTML file with Pygments syntax highlight and remove all comments and empty lines.
#!/usr/bin/env python
"""
Export all source code files into a single HTML file with Pygments syntax highlight and remove all comments and empty lines.
"""
import argparse
import fnmatch
import os
import sys
#!/usr/bin/env python3
"""
# Report PyProject version
The tool print python source code project's version from pip install report with a dry-run.
The project MUST have a `pyproject.toml` file with metadata defined in it!
- On non-western language Windows, environment `PYTHONUTF8` may be in need .
@tanbro
tanbro / caseconvert.py
Last active June 16, 2023 03:07
Change dictionary's key naming style
"""
Change dictionary's key naming style
"""
from typing import (
Any,
Callable,
Iterable,
Mapping,
MutableMapping,
@tanbro
tanbro / captchaimage.py
Last active June 18, 2025 04:55
Generate a captcha image
from __future__ import annotations
import platform
from collections.abc import Mapping, Sequence
from os import PathLike, environ, path
from pathlib import Path
from random import choice, randint
from typing import TYPE_CHECKING, Any, BinaryIO
import numpy as np
@tanbro
tanbro / make_manylinux_wheels.py
Last active August 3, 2022 07:13
使用 quay.io 提供的 pypa/manylinux Docker 镜像构建该项目及其依赖软件的 Python Wheel 发布包
#!/usr/bin/env python3
"""
使用 quay.io 提供的 pypa/manylinux Docker 镜像构建该项目及其依赖软件的 Python Wheel 发布包
"""
import argparse
import os
import os.path
import platform
#include <stddef.h>
#include <memory.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
/// 参考: https://www.openssl.org/docs/man1.0.2/man3/BIO_f_base64.html 以及
/// https://gist.github.com/barrysteyn/7308212