Skip to content

Instantly share code, notes, and snippets.

View StevenACoffman's full-sized avatar

Steve Coffman StevenACoffman

View GitHub Profile
@StevenACoffman
StevenACoffman / numbers-to-words.go
Created January 6, 2025 21:45 — forked from knadh/numbers-to-words.go
Simple algorithm for converting numbers to English words (Golang)
package main
import (
"fmt"
)
var (
ones = []string{
"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
func main() {
@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: