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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dhermes
dhermes / README.md
Last active January 13, 2023 16:27
[2023-03-13] How many values are nan? (IEEE-754 float64)

How many nan values exist?

It turns out a lot (2**52). Anything where the 12 exponent bits are all 1, independent of the values of the other 52 bits).

$ python main.py
binary(1.0)  = 0011111111110000000000000000000000000000000000000000000000000000
binary(2.0)  = 0100000000000000000000000000000000000000000000000000000000000000
binary(-1.0) = 1011111111110000000000000000000000000000000000000000000000000000
@dhermes
dhermes / main.go
Created January 11, 2023 17:42
[2023-01-11] Don't use pointers in structs used for Go map keys (or know what you're getting into)
package main
import (
"fmt"
"os"
"github.com/google/uuid"
)
type mapKey struct {
@dhermes
dhermes / .gitignore
Last active January 8, 2023 06:01
[2023-01-07] supervisord playground
/__pycache__/
/supervisord.log
/supervisord.pid