Skip to content

Instantly share code, notes, and snippets.

View exhuma's full-sized avatar
🐢
Slowly advancing on hobby projects

Michel Albert exhuma

🐢
Slowly advancing on hobby projects
View GitHub Profile
@exhuma
exhuma / settings.json
Created November 28, 2023 15:29
Don't auto-format SQL files in VS-Code
{
"[sql]": {
"editor.formatOnSave": false
}
}
@exhuma
exhuma / example.py
Last active April 14, 2024 10:25
Automatic Pagination with FastAPI and SQLAlchemy
from fastapi import Depends, FastAPI
from pydantic import BaseModel
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Query, Session
from pagination import PaginatedList, paginated_get
Base = declarative_base()
#!/bin/bash
# -----------------------------------------------------------------------------
# This script extracts the path of the devcontainer config-file from
# docker-events.
#
# This helps in identifying who has started a container if the container-name
# does not itself include any indication.
#
# This can be used to determine if a container can be safely stopped/removed
"""
This module contains classes that dispatch calls depending on arg-types.
The goal is to handle "media-types" for HTTP APIs with well-defined functions.
An "incoming" request may contain a payload that needs to be stored in the
back-end. We need to "parse/decode" the incoming object depending on media-type.
Similarly, when we respond to the request we may need to convert the object to
something the client understands. The client can opt-in/-out using the "Accept"
media-type.
@exhuma
exhuma / init-keycloak.py
Created December 16, 2024 14:06
Initialise keycloak realm with test user
#!/usr/bin/python3
"""
This script creates a realm, client, and user in Keycloak for local development.
"""
from os import environ
import requests
import rich
@exhuma
exhuma / listen_sqla.py
Created February 17, 2025 19:04 — forked from dtheodor/listen_sqla.py
Listen for pg_notify with SQL Alchemy + Psycopg2
import select
import datetime
import psycopg2
import psycopg2.extensions
from sqlalchemy import create_engine, text
engine = create_engine("postgresql+psycopg2://vagrant@/postgres")
@exhuma
exhuma / rate_limit.py
Created May 20, 2025 13:51
Rate limiter for ASGI apps. Without dependency on any higher-level framework.
# cspell: ignore ASGI
"""
A simple rate-limiting middleware for ASGI applications.
This middleware uses the `limits` library to enforce rate limits on incoming
requests. It allows you to specify a default rate limit and custom limits for
specific client-IPs on specific paths.
Usage::
@exhuma
exhuma / test.json
Created September 5, 2025 20:11
testdata.json
{
"jingles":[
{
"resource_str":"300-dine_in_hell",
"movie":"300",
"title":"We Dine in Hell!",
"duration":3.761625,
"has_metadata":true,
"inserted":"2021-02-09T18:38:48.199850+00:00"
},