Skip to content

Instantly share code, notes, and snippets.

View StevenACoffman's full-sized avatar

Steve Coffman StevenACoffman

View GitHub Profile
@StevenACoffman
StevenACoffman / ttrpg-scenario-design-procedures.md
Last active January 1, 2024 18:30
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

@StevenACoffman
StevenACoffman / golangci.yaml
Created March 28, 2023 13:45 — forked from cristaloleg/golangci.yaml
Go linters configuration, the right version.
# See: https://olegk.dev/go-linters-configuration-the-right-version
run:
# Depends on your hardware, my laptop can survive 8 threads.
concurrency: 8
# I really care about the result, so I'm fine to wait for it.
timeout: 30m
# Fail if the error was met.
@StevenACoffman
StevenACoffman / dial-pq-via-ssh.go
Created March 26, 2023 16:13 — forked from vinzenz/dial-pq-via-ssh.go
Use postgres via SSH in Golang
package main
import (
"database/sql"
"database/sql/driver"
"fmt"
"net"
"os"
"time"
@StevenACoffman
StevenACoffman / example_test.go
Last active February 7, 2023 22:44
Golang Testify go-cmp Partial Equal
package main
import (
"fmt"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
@StevenACoffman
StevenACoffman / slog_console_handler.go
Last active March 26, 2023 23:09 — forked from wijayaerick/slog_console_handler.go
Example ConsoleHandler for golang.org/x/exp/slog Logger
// ConsoleHandler formats slog.Logger output in console format, a bit similar with Uber's zap
// ConsoleEncoder or Apex's CLI log
// The log format is designed to be human-readable.
//
// Performance can definitely be improved, however it's not my priority as
// this should only be used in development environment.
//
// e.g. log output:
// • ./main.go:21 Debug message {"hello":"world","!BADKEY":"bad kv"}
// ℹ ./main.go:217 Info message {"with_key_1":"with_value_1","group_1":{"with_key_2":"with_value_2","hello":"world"}}
RunParallel(t, TestCase{
Steps: []TestStep{
{
Query: `
query getWorksheet($id: ObjectId!) {
worksheet(id: $id) {
id
label
name
}
@StevenACoffman
StevenACoffman / main.go
Created September 2, 2022 18:26 — forked from pteich/main.go
Example for using go's sync.errgroup together with signal detection signal.Notify to stop all running goroutines
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"os"