Skip to content

Instantly share code, notes, and snippets.

View dhermes's full-sized avatar

Danny Hermes dhermes

View GitHub Profile
@dhermes
dhermes / README.md
Created April 8, 2026 15:19
[2026-04-08] "Proof" that `session` in SQLAlchemy does not consume DB resources until used

"Proof" that session in SQLAlchemy does not consume DB resources until used

Before session1 exists

acme-db> SELECT
     pid,
     usename,
     application_name,
     state,
@dhermes
dhermes / README.md
Created April 2, 2026 18:19
[2026-04-02] `datetime.date.today()` local timezone

Showing how datetime.date.today() in Python is sensitive to local timezone:

$ uv run how_today.py; echo '=='; date
TZ=
today() -> 2026-04-02
impl -> 2026-04-02
full    -> 2026-04-02T13:17:19
==
Thu Apr 2 13:17:19 CDT 2026
@dhermes
dhermes / signal_example.py
Created March 26, 2026 17:29
[2026-03-26] Example for SIGTERM handling
import os
import signal
import sys
import time
import types
class _Global:
SHUTDOWN_REQUESTED = False
@dhermes
dhermes / .python-version
Last active March 24, 2026 20:40
[2026-03-24] flask@1.1.1 globals + child threads
3.12.12
@dhermes
dhermes / .python-version
Last active March 23, 2026 21:31
[2026-03-23] Playing with `contextvars`
3.14.3
@dhermes
dhermes / _credentials_poc.py
Last active August 15, 2025 21:34
[2025-08-15] Proof-of-concept: impersonate service account (for signing) with Python `google-auth`
import datetime
import os
import google.auth
import google.auth.compute_engine
import google.auth.credentials
import google.auth.impersonated_credentials
import google.auth.transport.requests
import google.cloud.storage
import google.oauth2.credentials
@dhermes
dhermes / materialized-view-dependency-graph.sql
Created February 27, 2025 18:58
[2025-02-27] Building a dependency graph for materialized view(s) (PostgreSQL)
SELECT DISTINCT
r.ev_class::regclass AS materialized_view,
n.nspname AS schema_name,
c.relname AS object_name,
CASE c.relkind
WHEN 'r' THEN 'Table'
WHEN 'v' THEN 'View'
WHEN 'm' THEN 'Materialized View'
WHEN 'f' THEN 'Foreign Table'
WHEN 'p' THEN 'Partitioned Table'
@dhermes
dhermes / patch_service_version.py
Created February 14, 2025 17:50
[2025-02-14] Manually patch scaling on App Engine service
import json
import subprocess
import click
import requests
### https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1beta/apps.services.versions/get
### https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1beta/apps.services.versions/patch
@dhermes
dhermes / 01-initialize.sql
Last active February 19, 2025 21:55
[2025-01-29] PostgreSQL database permissions
--------------------------------------------------
------------------ Add role(s) -------------------
--------------------------------------------------
CREATE ROLE acme_admin
WITH ENCRYPTED PASSWORD 'devpassword_admin'
VALID UNTIL 'infinity'
CONNECTION LIMIT -1
NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN NOREPLICATION NOBYPASSRLS;
@dhermes
dhermes / marbles.py
Created January 2, 2025 15:22
[2025-01-02] Chessboard parity (odd/even sums across rows and columns)
# See: https://www.youtube.com/watch?v=EONem7cdmSM
import fractions
import numpy as np
def even_sum(m, n):
for i in range(n):
s = sum(m[i, :])