Skip to content

Instantly share code, notes, and snippets.

View StevenACoffman's full-sized avatar

Steve Coffman StevenACoffman

View GitHub Profile
@StevenACoffman
StevenACoffman / room.go
Last active October 20, 2024 19:57
Four Digit room code to integer
// https://go.dev/play/p/CxJf4Jf9rDZ
package main
import (
"fmt"
"strings"
)
const ZZZZ = 18279 + 456975
@StevenACoffman
StevenACoffman / sh
Last active September 17, 2024 16:44 — forked from ltupin/sh
Filter failed kubernetes jobs to delete it
#Should be a job too :-D
# With xargs (on all namespaces)
kc get jobs -o=jsonpath='{range .items[?(@.status.conditions[0].type == "Failed")]}{.metadata.name}{"\t"}{.metadata.namespace}{"\n"}{end}' --all-namespaces | \
xargs -n2 sh -c 'kubectl delete jobs $0 --namespace=$1'
# For loop (only in the current namespace)
for i in $(kc get jobs -o=jsonpath='{range .items[?(@.status.conditions[0].type == "Failed")]}{.metadata.name}{"\n"}{end}');
do kubectl delete jobs $i; done
@StevenACoffman
StevenACoffman / StructCompareExceptOneField.md
Last active July 26, 2024 19:23
Compare Structs except for one field
@StevenACoffman
StevenACoffman / go-httpclient.md
Created June 11, 2024 21:14
HTTPClient in Go

In Go, usually an HTTP client is:

type doer interface {
  Do(req *http.Request) (*http.Response, error)
}

Go's HTTP situation is that the http.RoundTripper interface is explicitly designed to provide customization of how an HTTP request executes,as that's exactly what it's there for.

If you take a look at the definition of RoundTripper and compare it to the doer interface above, I think you'll see that the similarity is striking:

@StevenACoffman
StevenACoffman / ttrpg-scenario-design-procedures.md
Last active May 21, 2024 11:45
Tabletop Role Playing Game Scenario Design Recipes

There are a number of different approaches to designing a scenario/adventure/module.

In a Five Room Dungeon, the basic formula is:

  1. Entrance or Guardian
  2. Puzzle or Roleplaying Challenge
  3. Trick or Setback
  4. Climax, Big Battle, or Conflict
  5. Reward, Revelation, or Plot Twist

Justin Alexander's 5+5 Dungeon Recipe:

https://github.com/lf-edge/eve-libs/blob/main/reconciler/README.md
https://github.com/spotahome/gontroller
@StevenACoffman
StevenACoffman / apollo-sandbox-sri.go
Last active June 22, 2023 15:37
Get latest Apollo Sandbox Playground and SRI
// Gets the latest Apollo Embedded Sandbox Playground URL from the CDN S3 bucket
//
// To get the Subresource Integrity check, `go run main.go` and take what that outputs and run like this:
// CDN_FILE=https://embeddable-sandbox.cdn.apollographql.com/58165cf7452dbad480c7cb85e7acba085b3bac1d/embeddable-sandbox.umd.production.min.js
// curl -s $CDN_FILE | openssl dgst -sha256 -binary | openssl base64 -A; echo
package main
import (
"encoding/xml"

sqlc isn’t an ORM, but it implements one of the most useful features of one – mapping a query back into a struct without the need for boilerplate. If you have query with a SELECT * or RETURNING *, it knows which fields a table is supposed to have, and emits the result to a standard struct representing its records. All queries for a particular table that return its complete set of fields get to share the same output struct.

Rather than implement its own partially-complete SQL parser, sqlc uses PGAnalyze’s excellent pg_query_go, which bakes in the same query parser that Postgres really uses. It’s never given me trouble so far – even complex queries with unusual Postgres embellishments work.

This query parsing also gives you some additional pre-runtime code verification. It won’t protect you against logical bugs, but it won’t compile invalid SQL queries, which is a far shot better than the guarantees you get with SQL-in-Go-strings. And thanks to SQL’s declarative nature, it tends to produce fewer bugs than com