Skip to content

Instantly share code, notes, and snippets.

View dhermes's full-sized avatar

Danny Hermes dhermes

View GitHub Profile
@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.
@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
@dhermes
dhermes / sizes.sql
Created September 30, 2022 14:43
[2022-09-30] Query to summarize PostgreSQL table size across all (specified) schemas
WITH raw_relation_sizes AS (
SELECT
n.nspname || '.' || c.relname as table_name,
pg_relation_size(n.nspname || '.' || c.relname) AS relation_size
FROM
pg_catalog.pg_class AS c
LEFT OUTER JOIN
pg_catalog.pg_namespace AS n
ON
n.oid = c.relnamespace
@dhermes
dhermes / main.go
Created September 9, 2022 15:42
[2022-09-09] Struct embedding a Go interface (e.g. for unit tests)
package main
import (
"fmt"
)
type Interface interface {
Foo() int
Bar() string
}
@dhermes
dhermes / main.go
Created September 9, 2022 15:42
[2022-09-09] Some examples of Go struct embedding
package main
import (
"fmt"
"math"
)
type EmbeddedType struct {
X int
Y int
@dhermes
dhermes / main.go
Created July 21, 2022 18:21
[2022-07-21] Quirks of JSON unmarshal onto `any` in Go
package main
import (
"encoding/json"
"fmt"
)
type T struct {
X float64 `json:"x"`
Y float64 `json:"y"`
@dhermes
dhermes / event_names.json
Created July 13, 2022 19:24
[2022-07-13] Stripe Event Names
{
"source": "https://stripe.com/docs/api/events/types",
"length": 194,
"names": [
"account.updated",
"account.application.authorized",
"account.application.deauthorized",
"account.external_account.created",
"account.external_account.deleted",
"account.external_account.updated",
@dhermes
dhermes / README.md
Last active July 8, 2022 01:45
[2022-07-07] FYI, nanoid is lossy

FYI, nanoid is lossy

I was scratching my head trying to understand where some of the bits went in a Nano ID. A Nano ID is 16 characters from the [Crockford base 32 alphabet][1]. Since 2**5 == 32, this means each character comes with 5 bits, for a total of 80 bits (5 * 16).

However a UUID has 128 bits, so 3 out of every 8 bits are missing.