Skip to content

Instantly share code, notes, and snippets.

@lummie
lummie / go_channel_simple_worker_pattern.go
Created September 28, 2021 14:59
Go channel based Simple Worker pattern
package main
import (
"fmt"
"log"
"sync"
)
/*
This is an example of a worker pattern for channels
@lummie
lummie / .bashrc
Last active July 14, 2022 06:49
k8s, git, full path PS1 bash prompt
# install kube-ps1 from https://github.com/jonmosco/kube-ps1
alias sn="kubectl config set-context --current --namespace" # switch namespace
# setup bash prompt
source "/usr/local/opt/kube-ps1/share/kube-ps1.sh" && k8s='$(kube_ps1)' # k8s cluster
export PS1="\n\n 🦔" # headgehog
export PS1="$PS1\n┏━━━━━┯━ 🕰 \t ━━━━━━━━━━━━━━━━━━━━━━━━━" # headgehog
export PS1="$PS1\n┃ git │ \$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')" # git branch
export PS1="$PS1\n┃ k8s │ $k8s" # k8s info
@lummie
lummie / exit.go
Created September 21, 2023 17:27
Wait for graceful exit.. [k8s, pod, cli]
/*
Waits for a terminate | interrupt signal, ctrl-c before finishing main
when creating services and adapters, I like to return a cleanup function that is deferred for
each service, thus when the app closes they are teared down in reverse order.
graceful.Exit() returns two functions:
- waitFor - which is called as the last statement of main. This will block until a signal to terminate or interrupt the executable.
- deferMe - defer this first before the service cleanups. This ensures thar stdout/err are flushed and sleeps 1 second before exiting.