Skip to content

Instantly share code, notes, and snippets.

View gbiz123's full-sized avatar

Greg Bizup gbiz123

View GitHub Profile
@gbiz123
gbiz123 / typehint_sqlalchemy_join.md
Last active January 8, 2024 23:17
How to Properly Type Hint SQLAlchemy Join Queries

How to Type Hint SQLAlchemy Join Queries

This Gist will show you how and why to properly type hint your SQLAlchemy join queries. Typehinting join queries is not well documented or discussed as of yet, but I'm here to change that.

If you are converting your ORM models to dictionaries, you are missing out!

If you aren't typehinting in SQLAlchemy, you're missing out on all the powerful ORM features that will speed your development and help prevent bugs. Properly typehinted Python code will give you specific benefits including:

  • Autocompletion of fields
  • Static analysis and linting
  • Clean code
@gbiz123
gbiz123 / downsample.py
Created July 28, 2024 18:39
Downsample Binary Pytorch Dataset Down To Size Of Smallest Class
import torch
from torch.utils.data import ConcatDataset, DataLoader, Dataset, Subset
import torchvision
import numpy as np
import matplotlib.pyplot as plt
import time
import os
from PIL import Image
from tempfile import TemporaryDirectory
import random