Skip to content

Instantly share code, notes, and snippets.

View DougAF's full-sized avatar
💭
Always Learning!

Douglas Franklin DougAF

💭
Always Learning!
View GitHub Profile
@DougAF
DougAF / timer.py
Last active April 8, 2024 10:14
From Edwards joblib repo - more useful timing function with closure
"""Build the timefunc decorator."""
import time
import functools
def timefunc(func):
"""timefunc's doc"""
@functools.wraps(func)
@DougAF
DougAF / database.py
Created May 7, 2020 20:58
FastAPI database file
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
SQLALCHEMY_DATABASE_URL = os.getenv("DB_CONN")
engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
@DougAF
DougAF / tracer.py
Last active June 26, 2022 19:52
Tracing Decorator for Medium
import functools
def tracefunc(func):
"""Decorates a function to show its trace."""
@functools.wraps(func)
def tracefunc_closure(*args, **kwargs):
"""The closure."""
result = func(*args, **kwargs)
@DougAF
DougAF / pyproject.toml
Created December 22, 2020 23:07
Poetry toml for covid streamlit app
[tool.poetry]
name = "covid-forecast-poetry"
version = "0.1.0"
description = ""
authors = ["edkrueger <edkrueger@gmail.com>"]
[tool.poetry.dependencies]
python = "==3.7.5"
fbprophet = "==0.6"
matplotlib = "==3.2.2"
@DougAF
DougAF / example.py
Created July 6, 2021 22:30
poke article exa
pikachu_cry = make_pokemon("Pika")
pikachu_cry()
@DougAF
DougAF / example.py
Created July 6, 2021 22:29
poke article
pikachu = Pokemon("Pika")
pikachu.cry()
def citrus_press_factory(press_type):
"""Creates a citrus press."""
press_types = {"lime", "lemon", "orange", "grapefruit"}
if not press_type in press_types:
raise ValueError(f"press_type must be one of {press_types}")
compatible_fruit_types_lookup = {
"lime": {"lime", "lemon"},
"lemon": {"lime", "lemon"},
@DougAF
DougAF / poke_class.py
Created June 26, 2021 15:40
Pokemon class for article
"""You can use currying to replicate the behavior of some classes."""
class Pokemon:
def __init__(self, sound):
self.sound = sound
def cry(self):
return self.sound
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from joblib import Parallel, delayed
def multiprocess(inputs):
return Parallel(n_jobs=2)(delayed(f)(x) for x in inputs)