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 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
@dhermes
dhermes / prune_graphql_fragments.py
Created January 31, 2024 22:12
[2024-01-31] Script to prune GraphQL fragments based on dependency of other fragments
import graphql.language
import networkx as nx
import tabulate
def _find_field_fragment_dependencies(
field_node: graphql.language.ast.FieldNode,
) -> list[str]:
if field_node.selection_set is None:
return []
@dhermes
dhermes / README.md
Created November 8, 2023 16:20
[2023-11-08] Subtleties of Go JSON marshaling and `null` / `nil`

Subtleties of Go JSON marshaling and null / nil

The TL;DR here is that if the standard encoding/json machinery in Go sees a null in a JSON field or a nil pointer in a Go field (of type *T), then it will not invoke the UnmarshalJSON() / MarshalJSON() on your type.

$ go run ./main.go
t1 = main.T{Shift:(*main.Point)(nil)} (nil stays nil, UnmarshalJSON() not invoked)
@dhermes
dhermes / pg_graphviz_graph.py
Last active May 11, 2023 21:47
[2023-05-11] Script to generate an ERD using only foreign keys
# Copyright (c) 2023 - Present. Hardfin, Inc. All rights reserved.
# Hardfin Confidential - Restricted
import csv
import io
import pathlib
import subprocess
import tempfile
@dhermes
dhermes / README.md
Last active April 12, 2023 21:25
[2023-04-12] The problem with "as-of-now" computed columns

The problem with "as-of-now" computed columns

The below illustrates why only actually IMMUTABLE functions should be used for PostgreSQL generated columns.

Basic status

Using a function that incorporates the current time, we can generate a status based on the value of a given timestamp:

@dhermes
dhermes / understanding_float64.ipynb
Created April 7, 2023 18:02
[2023-04-07] Understanding float64
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.