Skip to content

Instantly share code, notes, and snippets.

View adamluzsi's full-sized avatar

Adam Luzsi adamluzsi

View GitHub Profile
@adamluzsi
adamluzsi / golang_completion.sh
Last active October 13, 2019 00:04
GoLang bash completion
#!/usr/bin/env bash
function _comp_go-subcmd() {
local cmd=${1:?"cmd is required"}
local cur=${COMP_WORDS[COMP_CWORD]}
# try find completion for cmd options
if _comp_go-subcmd-opts "${cmd}"; then
return 0
fi
@adamluzsi
adamluzsi / README.md
Created August 16, 2019 11:59
Draft for aiming an effective PR review process
  • Verify the high level business goals are met with the implementation from product point of view
  • Look for scalability issues
  • Outline and note down high level tasks / issues
  • Verify code longterm testability
  • Check code behavior runtime observability
  • Look for high level design principle violation
    • antipatterns against 12 factor app
    • lack view/entity/bussiness-logic layer isolation
@adamluzsi
adamluzsi / direnvrc
Last active April 2, 2019 08:36
direnv direnvrc file to source all .envrc file
#!/bin/sh
source_up_all() {
local originalPWD=$(pwd)
local currentPWD=${originalPWD}
while [ "${currentPWD}" != "/" ]; do
cd ..
currentPWD=$(pwd)
@adamluzsi
adamluzsi / behavior.bash
Created March 16, 2019 21:59
bash behavior for command evaluation in func
## I expect this to fail when string passed as first argument
"bash -i -c 'echo hello world'"
#>bash: bash -i -c 'echo hello world': command not found...
## I expect this to fail when string " is around ${@}, but well...
$ function asdf() { "${@}"; }
$ asdf bash -i -c 'echo hello world'
#>hello world
## I expect an empty string value
@adamluzsi
adamluzsi / xml-fmt.go
Created September 6, 2018 07:48
go xml fmt based on Sam Whited code
package main
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"log"
"strings"
)
@adamluzsi
adamluzsi / formats.go
Created May 10, 2018 22:36
Golang Time Format creating cheat sheet
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package time
const (
_ = iota
stdLongMonth = iota + stdNeedDate // "January"
stdMonth // "Jan"
@adamluzsi
adamluzsi / interface.go
Created May 5, 2018 08:03
Golang interface sub type based switch
package x
// interface TYpe based switch
func handlerForInterface(handler interface{}) EventHandler {
switch v := handler.(type) {
case func(*Session, interface{}):
return interfaceEventHandler(v)
case func(*Session, *ChannelCreate):
return channelCreateEventHandler(v)
case func(*Session, *ChannelDelete):
@adamluzsi
adamluzsi / terminal.md
Created April 30, 2018 10:28
terminal cheat sheet
  • CTRL+u
    • clears from cursor to beginning of line
  • CTRL+k
    • clears from cursor to end of line
  • CTRL+d
    • clears one character to the right of the cursor
  • Esc+Backspace
    • clears one word to the left of the cursor
  • Esc+d
  • clears one word to the right of the cursor
@adamluzsi
adamluzsi / build.sh
Created April 25, 2018 14:38
Totally static Go builds
CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' .
@adamluzsi
adamluzsi / main.go
Created April 25, 2018 11:17
golang flag how to create aliases for set flags such as short versions
package main
var flagAlias = map[string]string{
"long-version": "lv",
}
func init() {
for from, to := range flagAlias {
flagSet := flag.Lookup(from)
cli.Var(flagSet.Value, to, fmt.Sprintf("alias to %s", flagSet.Name))