Skip to content

Instantly share code, notes, and snippets.

View dhermes's full-sized avatar

Danny Hermes dhermes

View GitHub Profile
@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, :])
@dhermes
dhermes / README.md
Created December 20, 2024 19:05
[2024-12-20] `pydantic` transforming wrong zero-value container

Transforming {} to []

$ python transformed.py
{'points': []}
{'points': []}
`grid3` failed as expected
{'points': [{'x': 3, 'y': 4}]}
{'points': [{'x': 3, 'y': 4}, {'x': 5, 'y': 12}]}
`grid6` failed as expected
@dhermes
dhermes / README.md
Created September 16, 2024 15:10
[2024-09-16] All `gcloud` config fields involving region / location
@dhermes
dhermes / README.md
Last active June 22, 2024 06:05
[2024-06-21] Guts of `sql.Tx` <-> `pgx.Tx`

Guts of sql.Tx <-> pgx.Tx

Placeholder

@dhermes
dhermes / example.sql
Created June 7, 2024 16:38
[2024-06-07] Exclusion constraints as "UNIQUE except for X"
CREATE TABLE foo (
id INTEGER PRIMARY KEY,
v1 INTEGER NOT NULL,
v2 INTEGER NOT NULL,
v3 INTEGER NOT NULL
);
ALTER TABLE foo
ADD CONSTRAINT uniq_except_v3_zero
EXCLUDE USING GIST (v1 WITH =, v2 WITH =, v3 WITH =) WHERE (v3 <> 0);
@dhermes
dhermes / README.md
Last active April 11, 2024 19:37
[2024-04-11] Quirks of time in Go with `time.Local`, eng blog post?
@dhermes
dhermes / .gitignore
Last active March 25, 2024 02:53
[2024-03-24] IHSA state champs in one year records
/1930s.html
/1960s.html
/1970s.html
/1980s.html
/1990s.html
/2000s.html
/2010s.html