Skip to content

Instantly share code, notes, and snippets.

View juftin's full-sized avatar
🤠
wranglin' data

Justin Flannery juftin

🤠
wranglin' data
View GitHub Profile
@juftin
juftin / yml_reader.py
Created November 16, 2019 23:21
A safe way to read yml files with environmental variable integration
#!/usr/bin/env python
from os import environ
from re import compile
from yaml import SafeLoader, load
def yml(path=None, data=None, tag=None):
"""
@juftin
juftin / logger.py
Created November 18, 2019 20:08
Easy Logging Setup
#!/usr/bin/env python
import logging
from os import environ
def logger(level="info", timestamp=True, filename=None,
custom_format=None, inherit_env=True):
"""
Default Logging Method. This takes multiple
@juftin
juftin / finite_state_machine_example.py
Created June 18, 2020 04:41
Here is an quick example of a finite state machine from the Python transitions package
#!/usr/bin/env python3
# Author:: Justin Flannery (mailto:[email protected])
"""
State Machine Example.
"""
import logging
from enum import Enum
@juftin
juftin / month_completion.py
Created September 5, 2020 20:49
Python: Retrieve Percent Through Month
#!/usr/bin/env python3
# Author:: Justin Flannery (mailto:[email protected])
"""
An Easy Script for Retrieving the Percent Through the Current Month
"""
from calendar import monthrange
from datetime import datetime
@juftin
juftin / cohorting.py
Last active April 8, 2022 15:00
Reproducible Cohorting
"""
Reproducible Cohorting for Experiments
"""
import hashlib
import logging
from typing import Dict, Optional, Tuple
import numpy as np
from pandas import DataFrame
@juftin
juftin / json_encoding.py
Last active July 1, 2023 07:12
Custom JSON Encoder function
"""
Custom JSON Encoding
Thanks Pydantic! https://github.com/samuelcolvin/pydantic/blob/master/pydantic/json.py
"""
from collections import deque
from dataclasses import asdict, is_dataclass
import datetime
from decimal import Decimal
@juftin
juftin / recursive_namespace.py
Last active November 4, 2024 21:46
Recursive SimpleNamespace Extension
"""
Extending the SimpleNamespace Class
"""
import datetime
from functools import singledispatch
from types import SimpleNamespace
from typing import Any
@juftin
juftin / rotation.py
Last active October 24, 2022 17:37
Rotating through AWS Profiles to Overwrite the Default
#!/usr/bin/env python3
"""
AWS Profile Rotation Script
"""
import argparse
import configparser
import pathlib
from copy import deepcopy
@juftin
juftin / README.md
Last active August 19, 2023 19:56
FastAPI Users + SQLModel

FastAPI Users + SQLModel

You will notice that the SQLModel example is very similar to the SQLAlchemy example for fastapi-users. This is because SQLModel is built on top of SQLAlchemy and pydantic.

There are a few important differences you should take note of:

app/db.py

@juftin
juftin / gist.py
Last active August 31, 2023 19:28
string literals
from typing import Literal, TypedDict
DENSE_CALCIUM_VOLUME: Literal["denseCalciumVolume"] = "denseCalciumVolume"
FATTY_FIBROUS_VOLUME: Literal["fattyFibrousVolume"] = "fattyFibrousVolume"
TOTAL_CALCIFIED_PLAQUE_VOLUME = "totalCalcifiedPlaqueVolume"
class TypedCleerlyDict(TypedDict):
denseCalciumVolume: float
fattyFibrousVolume: float