Skip to content

Instantly share code, notes, and snippets.

View eruvanos's full-sized avatar

Maic Siemering eruvanos

View GitHub Profile
@eruvanos
eruvanos / flask_json_dataclass.py
Created May 12, 2019 13:14
Enhance JSONEncoder supporting dataclasses
from flask import Flask
from flask.json import JSONEncoder
class EnhancedJSONEncoder(JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return super().default(o)
@eruvanos
eruvanos / timeit.py
Last active December 10, 2019 23:29
Time a python funtion
# Timer for functions
from functools import wraps
def timeit(f):
@wraps(f)
def wrap(*args, **kwargs):
start = time()
r = f(*args, **kwargs)
print(f.__name__, time() - start)
@eruvanos
eruvanos / README.md
Last active September 8, 2020 09:45
LocalDynamoDB Setup

Setup for a local DynamoDB for testing

Requirements

boto3 # aws sdk
requests # to download dynamodb
mirakuru # monitors the subprocess and checks for an open port
@eruvanos
eruvanos / log_util.py
Last active August 22, 2022 17:45
Better log config
"""
Configures a logger to log <=INFO to stdout and >INFO to stderr
"""
import logging
import os
import sys
DEFAULT_FORMAT = '%(asctime)s - %(levelname)s - %(name)s - %(message)s'
NO_TIME_FORMAT = '%(levelname)s - %(name)s - %(message)s'
@eruvanos
eruvanos / test_flask.py
Created February 26, 2020 09:03
Run Flask app as fixture
from threading import Thread
import pytest
import requests
from flask import Flask
@pytest.fixture()
def app() -> Flask:
host = 'localhost'
@eruvanos
eruvanos / README.md
Last active May 9, 2024 08:12
Simple mock server for testing using Flask

Mock server for testing using flask

License

MIT

Prepare

Install flask and requests to run this example.