Skip to content

Instantly share code, notes, and snippets.

Making an impact

Mark McDonnell Integralist

Making an impact
View GitHub Profile
Integralist / Go Code
Last active Feb 25, 2021
[Go Code Generation] #go #golang #codegen
View Go Code

Files required:

├── gen.go
├── generator
│   └── gen.go

Running go generator will cause a main.go file to be created in the root directory.

Integralist / Golang Debugging with Delve GUI.bash
Created Feb 23, 2021
[Golang Debugging with Delve GUI] #go #golang #delve #gui #debug
View Golang Debugging with Delve GUI.bash
# note: the install steps presume you're using go 1.16 or newer.
go install
# dependencies required:
# xcode-select --install
# sudo /usr/sbin/DevToolsSecurity -enable
# see for details
Integralist / Display number of windows, buffers, tabs.viml
Created Feb 16, 2021
[Display number of windows, buffers, tabs] #vim #display #count #windows #buffers #tabs
View Display number of windows, buffers, tabs.viml
:echo winnr('$')
:echo bufnr('$')
:echo tabpagenr('$')
Integralist / openapi-generator.bash
Created Feb 9, 2021
[OpenAPI Generator] #openapi #api #generator
View openapi-generator.bash
#!/usr/bin/env bash
languages=("bash" "go" "javascript" "php" "python" "ruby" "rust" "typescript-fetch")
for lang in "${languages[@]}";
for filename in .source-cache/.api-documentation/schemas/*;
name=$(basename $filename | cut -f 1 -d '.')
openapi-generator generate --skip-validate-spec -i "${filename}" -g "${lang}" -o "/tmp/api-code-gen/${lang}/${name}/"
Integralist / vim pretty print json.viml
Created Feb 5, 2021
[vim pretty print json] #vim #json #pretty #print
View vim pretty print json.viml
:read !cat % | python -m json.tool
Integralist / Terraform Provider Local Dev
Last active Feb 26, 2021
[Terraform Provider Local Dev Environment] #terraform #tf #local #dev #environment
View Terraform Provider Local Dev

Terraform Documentation Reference

export TF_CLI_CONFIG_FILE=/example-project/dev.tfrc

NOTE: if you use ~/ instead of an absolute path, then be sure your shell expands it to an absolute path (e.g. echo $TF_CLI_CONFIG_FILE should show the absolute path).

The dev.tfrc file:

Integralist / Go manage external tools via go
Last active Feb 22, 2021
[Go manage external tools via go modules] #go #golang #modules #dependencies #tools #external #ci
View Go manage external tools via go

Go 1.16

As of Go version 1.16 the go command changed behaviour for get and install:

  • install: the recommended way to install packages (ignoring
  • get: adds dependencies to your project's go modules file (i.e. go.mod).

The go install command now accepts a version suffix:

Integralist / .github--workflows--pr_test.yml
Created Feb 1, 2021
[Github Action Workflow Example] #github #git #actions #workflows
View .github--workflows--pr_test.yml
go-version: [1.14.x]
node-version: [12]
rust-toolchain: [1.46.0]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
- name: Checkout code
Integralist / Go defer with os.Exit(N).go
Last active Jan 29, 2021
[Go defer with os.Exit(N)] #go #golang #defer #exit
View Go defer with os.Exit(N).go
package main
import (
Goexit terminates the goroutine that calls it. No other goroutine is affected. Goexit runs all deferred calls before terminating the goroutine. Because Goexit is not a panic, any recover calls in those deferred functions will return nil.
Integralist / Make Directory if it does not exist.go
Created Jan 28, 2021
[Make Directory if it does not exist] #go #golang #directory #create #mkdir
View Make Directory if it does not exist.go
// makeDirectoryIfNotExists asserts whether a directory exists and makes it
// if not. Returns nil if exists or successfully made.
func makeDirectoryIfNotExists(path string) error {
fi, err := os.Stat(path)
switch {
case err == nil && fi.IsDir():
return nil
case err == nil && !fi.IsDir():
return fmt.Errorf("%s already exists as a regular file", path)
case os.IsNotExist(err):