Skip to content

Instantly share code, notes, and snippets.

View tweakimp's full-sized avatar
🏠
Working from home

FW tweakimp

🏠
Working from home
View GitHub Profile
@tweakimp
tweakimp / deco.py
Last active November 25, 2019 07:38
decorator magic
import functools
import inspect
import time
import cProfile
import time
from contextlib import contextmanager
import pstats
import sys
@tweakimp
tweakimp / singleton.py
Last active December 15, 2019 14:02
Singleton
class Singleton(type):
"""
Metaclass.
Only allows the creation of one instance, all other tries return
the same instance of the first creation.
Use:
class Test(metaclass=Singleton):
...
@tweakimp
tweakimp / cached.py
Created December 15, 2019 16:08
Cached
import weakref
class Cached(type):
"""
Metaclass.
Only allows the creation of one type of instance, all other instances
with the same initialization variables return the same instance of the
first creation.