Skip to content

Instantly share code, notes, and snippets.

View andrewmeissner's full-sized avatar

Andrew Meissner andrewmeissner

  • CrowdStrike
  • Mesa, AZ
View GitHub Profile
@andrewmeissner
andrewmeissner / goimports2.sh
Created July 29, 2021 22:44
remove all blank lines in go 'imports' statements, then sort with `goimports`
#!/bin/bash
# remove all blank lines in go 'imports' statements,
# then sort with goimports
if [ $# != 1 ] ; then
echo "usage: $0 <filename>"
exit 1
fi
@andrewmeissner
andrewmeissner / arrayFlags.go
Last active December 8, 2020 19:09
CLI array flags using stdlib
type arrayFlags []string
func (i *arrayFlags) String() string {
return strings.Join(*i, ",")
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, strings.Split(value, ",")...)
return nil
}
@andrewmeissner
andrewmeissner / casePerm.go
Created December 1, 2020 20:50
Case permutations of a given word
package main
import (
"fmt"
)
func main() {
key := "hello"
words := letterCasePermutation(key)
fmt.Println(words)
@andrewmeissner
andrewmeissner / awsPolicyDocUnmarshal.go
Last active November 24, 2020 18:35
AWS Policy Documents can have string/[]string Resource attributes
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"strings"
)
" Install vim-plug if not found
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
@andrewmeissner
andrewmeissner / setPath.sh
Created March 18, 2020 16:40
adds param to path if it isn't already in the path
#!/bin/bash
function setPath {
echo $PATH | grep -q "$1"
if [ $? -ne 0 ]; then
PATH="$PATH:$1"
fi
export PATH
}
@andrewmeissner
andrewmeissner / envVarsWithFlags.go
Created October 23, 2018 05:02
Attach environment variables to standard library flags
package main
import (
"flag"
"fmt"
"os"
"strings"
)
package main() {
@andrewmeissner
andrewmeissner / powerset.go
Last active February 16, 2021 20:32
Golang powerset implementation
// BROKEN - 18 MARCH 2020 - 1,2,3,4,5 PRODUCES INCORRECT RESULTS
package main
import "fmt"
func main() {
powerset := powerSet([]string{"1", "2", "3", "4"})
fmt.Println(powerset)
}
@andrewmeissner
andrewmeissner / keybase.md
Created April 27, 2018 01:40
Keybase Proof

Keybase proof

I hereby claim:

  • I am andrewmeissner on github.
  • I am andrewmeissner (https://keybase.io/andrewmeissner) on keybase.
  • I have a public key ASCyBgbG9I2NgE1l82pkgjKngE2E3AME1wb-xc6Xm_1J2wo

To claim this, I am signing this object:

@andrewmeissner
andrewmeissner / viperWatchingConsul.go
Created March 19, 2018 05:41
Viper watching remote config backend Consul
package main
import (
"log"
"time"
"github.com/spf13/viper"
_ "github.com/spf13/viper/remote"
)