Skip to content

Instantly share code, notes, and snippets.

View StevenACoffman's full-sized avatar

Steve Coffman StevenACoffman

View GitHub Profile
@StevenACoffman
StevenACoffman / workload_federation_dwd.go
Created January 30, 2025 01:24 — forked from salrashid123/workload_federation_dwd.go
Access GCP and workspace APIs using GCP Workload Identity Federation usign Domain Delegation
package main
import (
"fmt"
"log"
"context"
"cloud.google.com/go/storage"
@StevenACoffman
StevenACoffman / dwd.go
Created January 29, 2025 18:23 — forked from salrashid123/dwd.go
Gsuites domain wide delegation/impersonation
package main
import (
"fmt"
"io/ioutil"
"log"
"context"
"cloud.google.com/go/storage"
@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 / 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 / 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 / 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"}}
@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"
@StevenACoffman
StevenACoffman / gcs-signed-url-main.go
Created June 28, 2022 14:29 — forked from pdecat/gcs-signed-url-main.go
Creating a GCS Signed URL without a Service Account Key from a GCE instance or a GKE Pod using Workload Identity
package main
import (
"context"
"flag"
"log"
"net/url"
"time"
"cloud.google.com/go/compute/metadata"