Skip to content

Instantly share code, notes, and snippets.

@matejb
matejb / bash_debug_trace.sh
Created October 9, 2020 13:33
bash debug trace
#!/bin/bash
# cp from https://twitter.com/b0rk/status/1312413117436104705
trap '(read -p "[$BASH_SOURCE:$LINENO] $BASH_COMMAND?")' DEBUG
@matejb
matejb / remove_extra_lines.sh
Created August 7, 2020 11:03
remove extra lines
sed '/^$/N;/^\n$/D'
@matejb
matejb / clean_tf_plan.sh
Created August 7, 2020 11:01
terraform plan cleanup
grep -E "^(\w+|\s+~|\s+\+|\s+\-|\s+#|\s+<=|$)
@matejb
matejb / MakeFile_help
Created January 15, 2019 12:52
MakeFile help
# from https://github.com/docker/cli/blob/master/Makefile#L74-L76 found by @breml
.PHONY: help
help: ## print this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@matejb
matejb / chain.go
Created August 21, 2018 11:42
chain golang
package main
import (
"fmt"
)
func main() {
chain(a).chain(b).chain(c)()
}
// normalizeLocalTime will normalize local time expressed in number of seconds
// from UNIX Epoch but not in UTC but counted in local location to the one
// counted correctly from UTC location.
func normalizeLocalTime(localNumOfSeconds int64, location *time.Location) time.Time {
t := time.Unix(localNumOfSeconds, 0).In(location)
_, offset := t.Zone()
// we apply offset in reverse to correct time
return t.Add(-1 * time.Duration(offset) * time.Second)
}
@matejb
matejb / pipe_executor.go
Created August 10, 2017 08:27
simple Go pipe executor
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
"strings"
)
@matejb
matejb / sigterm_context.go
Created May 20, 2017 12:21
Golang context with cancellation on signal receive
func contextWithSigterm(ctx context.Context) context.Context {
ctxWithCancel, cancel := context.WithCancel(ctx)
go func() {
defer cancel()
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
select {
case <-signalCh:
@matejb
matejb / gist:bbdf107d97ebb06fd310d7a2c5c5834c
Created December 16, 2016 15:38
man without styles, useful for emacs tramp
man man | col -bx
col -b removes backspaces.
col -x replaces tabs with spaces
wget -q -O- http://url | grep string