Skip to content

Instantly share code, notes, and snippets.

View DeoLeung's full-sized avatar

Zhanzhao (Deo) Liang DeoLeung

View GitHub Profile
@DeoLeung
DeoLeung / sample_openapi_spec.py
Created March 12, 2024 03:14
generate openapi.json with fastapi
"""python scripts/sample_openapi_spec.py openapi.json title version"""
import json
import sys
import fastapi
from fastapi import Body
from fastapi import Depends
from fastapi import Query
from fastapi.openapi.utils import get_openapi
from fastapi.security import APIKeyHeader
@DeoLeung
DeoLeung / paradedb.py
Created January 22, 2024 10:01
sqlalchemy recipe for paradedb
"""
sqlalchemy discussion: https://github.com/sqlalchemy/sqlalchemy/discussions/10841
"""
def dump_dict(v):
"""recursively dump dict into rust style, which no quotes for key"""
match v:
case str():
return f'"{v}"'
case int():
return f'{v}'
@DeoLeung
DeoLeung / list_to_bitmaps.py
Created December 26, 2017 06:21
transform list of integers into bitmaps bytes and back
import numpy as np
ids = [1, 5, 7, 12]
bitmaps = np.zeros(max(ids) + 1, dtype=np.bool)
bitmaps[ids] = True
bitmaps = np.packbits(bitmaps).tostring()
print(bitmaps)
# b'E\x08'
# could be use as a binary field to be stored in database
@DeoLeung
DeoLeung / devpi.sh
Created May 19, 2017 04:57
搭建内部python registry, 使用douban镜像
# devpi server
# install package
pip install --trusted-host pypi.douban.com -i http://pypi.douban.com/simple devpi
# initialize the server directory
devpi-server --init
# create the supervisord devpi.ini or start the server directly, if not root user, provide the --serverdir
devpi-server --host 0.0.0.0 --port 3141 --serverdir ~/.devpi/server
# after the server is running
# point to registry