Skip to content

Instantly share code, notes, and snippets.

View GuangTianLi's full-sized avatar
:electron:
cool

TT GuangTianLi

:electron:
cool
  • China
View GitHub Profile
@GuangTianLi
GuangTianLi / dict.py
Created April 1, 2021 07:49
HashMap Python Implementation
import array
import collections
# Placeholder constants
FREE = -1
DUMMY = -2
class Dict(collections.MutableMapping):
'Space efficient dictionary with fast iteration and cheap resizes.'
@GuangTianLi
GuangTianLi / combine.sh
Last active December 22, 2020 02:55
combine
#!/usr/bin/bash
echo "processing $1 and $2"
PNG0=$1 ## png0 <----- first image should be the BLACKEST
PNG1=$2 ## png1 <----- second image should be the WHITEST
#PNG2=$3 ## png2 <----- third - todo - this could be an opaque fg with tranparent bg
bg_size=`identify -format '%wx%h' "$1"`
#echo "bg is $bg_size"
magick convert $PNG1 -resize $bg_size $PNG1
magick convert $PNG0 -channel RGBA -matte -colorspace gray -normalize -ordered-dither o8x8 gray_$PNG0
magick convert $PNG1 -channel RGBA -matte -colorspace gray -normalize -ordered-dither o8x8 gray_$PNG1
@GuangTianLi
GuangTianLi / LRUDict.py
Created September 15, 2020 09:47
LRUDict
from threading import Lock
from typing import Iterable
_sentry = object()
class DoublyLinkedListNode(Iterable):
__slots__ = ("prev", "next", "key", "result")
def __init__(
@GuangTianLi
GuangTianLi / demo.py
Last active February 3, 2019 04:47
Type hint with dynamic __init__.
from dataclasses import dataclass
from typing import Tuple, Dict, TypeVar
_C = TypeVar('_C', bound=type)
class TestORM(type):
def __new__(cls, clsname: str, bases: Tuple, clsdict: Dict):
param = ""
for key, key_type in clsdict.get('__annotations__', {}).items():