Skip to content

Instantly share code, notes, and snippets.

View EdwinChan's full-sized avatar

Edwin Chan EdwinChan

View GitHub Profile
@EdwinChan
EdwinChan / move.py
Created November 24, 2022 05:13
Transferring ownership of function argument to function in Python (aka move semantics)
import psutil
def rss(label):
print(label, psutil.Process().memory_info().rss)
class Wrapper:
def __init__(self, value):
self.value = value
def __call__(self):
@EdwinChan
EdwinChan / textbbox.py
Created February 16, 2019 23:20
Matplotlib text bounding boxes
mode = ['png', 'svg', 'pdf', 'pgf'][3]
dpi = 100
poem = '''
Farewell sweet earth and northern sky,
for ever blest, since here did lie,
and here with lissom limbs did run,
beneath the moon, beneath the sun,
L\xfathien Tin\xfaviel
more fair than mortal tongue can tell.
@EdwinChan
EdwinChan / nested.py
Last active May 8, 2024 20:58
Trick for using multiprocessing with nested functions and lambda expressions
import concurrent.futures
import multiprocessing
import sys
import uuid
def globalize(func):
def result(*args, **kwargs):
return func(*args, **kwargs)
result.__name__ = result.__qualname__ = uuid.uuid4().hex
setattr(sys.modules[result.__module__], result.__name__, result)
@EdwinChan
EdwinChan / README
Last active July 1, 2016 00:51
Brute-force solution of arithmetic restoration problem
Original problem:
ab
- cd
----
ef
+ gh
----
iii