Skip to content

Instantly share code, notes, and snippets.

View headsrooms's full-sized avatar
🦊

Pablo Cabezas headsrooms

🦊
  • SNGULAR
  • Madrid
  • 06:39 (UTC +01:00)
View GitHub Profile
@headsrooms
headsrooms / avoid.py
Created August 14, 2018 10:00
Manage python exceptions through decorators
@contextmanager
def avoid(
exception: type(Exception),
raises: Exception = None,
exception_manager: Callable = None,
finally_manager: Callable = lambda: (),
):
try:
yield
except exception as e:
@headsrooms
headsrooms / no_stdout.py
Created November 15, 2018 16:44
No stdout decorator
@contextlib.contextmanager
def no_stdout():
save_stdout = sys.stdout
sys.stdout = io.BytesIO()
yield
sys.stdout = save_stdout
@headsrooms
headsrooms / timeit.py
Created November 15, 2018 16:55
Timeit decorator asyncio compatible with repetitions and geometric mean result
def timeit(n):
def timeit_decorator(func):
async def process(func, *args, **params):
if asyncio.iscoroutinefunction(func):
return await func(*args, **params)
else:
return func(*args, **params)
async def helper(*args, **params):
times = []