Skip to content

Instantly share code, notes, and snippets.

View piotrpersona's full-sized avatar
🎯
Focusing

Piotr Persona piotrpersona

🎯
Focusing
View GitHub Profile
@piotrpersona
piotrpersona / parse_args.bash
Created April 18, 2019 14:31
Bash arguments parsing
while [[ "${#}" -gt 0 ]]; do
case "${1}" in
-i|--inventory) INVENTORY="${2}"; shift 2;;
-h|--help) display_help; exit 1;;
esac
done
@piotrpersona
piotrpersona / Dockerfile
Last active October 10, 2019 15:05
Multistage Dockerfile for golang binaries
FROM golang@sha256:2b3ca6f02d74eaf6f2d1788a16c1ccf551fe2407cb457636f3826f0108fed8ff AS stage-build
WORKDIR "/go/src/package"
RUN apk update && apk add dep git
COPY Gopkg.* ./
RUN dep ensure --vendor-only
COPY main.go .
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build \
@piotrpersona
piotrpersona / handle_interrupt.go
Created April 18, 2019 15:02
Golang signal handling
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt)
go func(){
for sig := range signalChannel {
// fmt.Println(sig)
}
}()
@piotrpersona
piotrpersona / git-fixup.sh
Created April 18, 2019 21:35
Create fixup for topmost non-fixup commit - this will allow to stack fixups
# Git log:
#
# am3xn47 'fixup! Add file B'
# 302mx47 'Add file B'
# xn4273x 'Add file A'
NON_FIXUP_HEAD_COMMIT="$(
git log --oneline
| grep --invert-match 'fixup'
| head -1
@piotrpersona
piotrpersona / ssh-ports.sh
Created May 10, 2019 09:58
Tunnel with ssh - local port -> remote host's port
# Origin: https://github.com/engineer-man/youtube/blob/master/058/commands.sh
# 6. Tunnel with ssh (local port 3337 -> remote host's 127.0.0.1 on port 6379)
ssh -L 3337:127.0.0.1:6379 root@emkc.org -N
@piotrpersona
piotrpersona / build.sh
Last active May 10, 2024 01:42
Golang build ldflags
GIT_TAG="$( git describe --abbrev=0 )"
GIT_HASH="$( git rev-parse HEAD )"
BUILD_DATE="$( date +%F )" # Note: An ldflag cannot contain whitespace
REPO="github.com/user/repo"
OUTPUT_NAME="build-artifact"
PACKAGE="main.go"
read -r -d '' LDFLAGS << EOM
-X ${REPO}/cmd.gitVersionTag=${GIT_TAG}
@piotrpersona
piotrpersona / docker-run.sh
Last active August 29, 2019 14:19 — forked from dctrwatson/nginx.conf
Caching PyPi packages locally with nginx
docker run \
-v pypi-cache:/var/lib/nginx/pypi \
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf \
-p 7777:80 \
nginx
@piotrpersona
piotrpersona / k8s-short-names.md
Last active May 16, 2024 09:56
k8s resources short names

k8s resources short names

Short name Full name
csr certificatesigningrequests
cs componentstatuses
cm configmaps
ds daemonsets
deploy deployments
ep endpoints
@piotrpersona
piotrpersona / deployment.yaml
Created October 14, 2019 10:55
Kubernetes helm deployment with conifg checksum
spec:
template:
metadata:
labels:
app.kubernetes.io/name: {{ .Release.Name }}
annotations:
configChecksum: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
@piotrpersona
piotrpersona / cas.go
Last active December 25, 2019 23:58
Go hacks
type Spinlock struct {
state *int32
}
const free = int32(0)
func (l *Spinlock) Lock() {
for !atomic.CompareAndSwapInt32(l.state, free, 42) { // 42 or any other value but 0
runtime.Gosched() // Poke the scheduler
}