Skip to content

Instantly share code, notes, and snippets.

View nilium's full-sized avatar
🍉
internal screaming intensifies

Noel nilium

🍉
internal screaming intensifies
View GitHub Profile
@nilium
nilium / withtemp
Last active August 10, 2019 19:13
Script to generate an eval-able line to create a temporary file, assign it to a variable, and remove it upon exit.
#!/bin/bash
# Usage: eval "$(withtemp [varname [mktempargs]])
#
# If varname is given, a tempfile is generated, its path assigned to the
# variable $varname, and deleted upon exit. Otherwise, no varname
# becomes 'tempfile' and no arguments are passed to mktemp. Varname is
# not exported or local, but you may evaluate using either
#
# $ eval "local $(withtemp ...)"
#
@nilium
nilium / twitter.json
Created July 23, 2019 02:17
Twitter init-data
{
"keyboardShortcuts": [
{
"name": "Actions",
"description": "Shortcuts for common actions.",
"shortcuts": [
{
"keys": [
"Enter"
],
@nilium
nilium / main.go
Last active June 14, 2019 21:15
Example of parsing environment variables and CLI flags using the flag package
package main
import (
"flag"
"log"
"os"
"strings"
"unicode"
)

Build server notes

Any use of "we" in this document is the authorial we because using "I" sounds weird. This is intended to cover building packages under spiff-packages and not necessarily supporting the entirety of void-packages (due to size, complexity, and not having a good idea of every weird quirk of every package in it).

All jobs are intended to run using parametrized nomad tasks. This is not necessarily a requirement but is how it's planned out for now due to the homelab setup.

When building a package, we first need to request a list of all dependencies that package has and fetch all of them

If any package is not already in either the main or build repo, we need to build it, so we have to submit additional jobs to build those packages.

@nilium
nilium / git-instat
Last active May 20, 2019 23:08
Git script to scan diff --numstat output and sum it.
#!/bin/bash
usage() {
cat >&2 <<-'EOF'
Usage: git-instat [range] [path...] [-path pattern...] [-only pattern...] [-omit pattern...]
Print a stat summary for the given paths in a ref.
If no range is given, the default is 'HEAD^1..HEAD'.
-only and -omit may be passed to filter lines of the numstat, such that
@nilium
nilium / gomodver
Created April 12, 2019 16:59
Script to print Go module v0.0.0-DATE-SHA version strings
#!/bin/bash
# Usage: gomodver [REF...]
# Prints a Go modules v0.0.0-DATE-SHA version string for the given Git refs.
# If no REF is given, gomodver defaults to HEAD.
datearg=d@
case "$(uname -s | tr A-Z a-z)" in
*bsd|darwin) datearg=r;
esac
@nilium
nilium / lssrc
Created March 27, 2019 15:49
Short script to list all non-stdlib sources used by a Go package
#!/usr/bin/env bash
comm -23 \
<(go list -f '{{.ImportPath}}{{"\n"}}{{range .Deps}}{{.}}{{"\n"}}{{end}}' "$@" | sort | uniq) \
<(go list std | sort) |
xargs go list -f '{{$dir := .Dir}}{{range .GoFiles}}{{$dir}}/{{.}}{{"\n"}}{{end}}' |
sort | uniq
@nilium
nilium / gen-go-test-stubs
Created March 21, 2019 16:07
Script to generate stub_test.go files for any package without tests to produce 0% coverage for those packages
#!/usr/bin/env bash
gen_stub() {
set -e
local pkg="$1"
local pkgdir="$(go list -f '{{.Dir}}' "$pkg")"
local pkgname="$(go list -f '{{.Name}}' "$pkg")"
local stub="$pkgdir/stub_test.go"
if [ -e "$stub" ]; then
echo "# Cannot create $stub: file already exists" >&2
return 1
@nilium
nilium / gomodgraph
Created March 20, 2019 20:43
Tool to generate graphs of Go module dependencies
#!/usr/bin/env bash
# Based on https://github.com/go-modules-by-example/index/blob/master/014_mod_graph/README.md
OPEN=0
TYPE=svg
case "$1" in
-)
OUT=/dev/stdout
;;
'')
@nilium
nilium / Dockerfile
Last active February 18, 2019 16:09
Dockerfile to cross-compile Go binaries for a target platform and produce a Docker image for the target platform
# Dockerfile to cross-compile Go binaries for a target platform
#
# Usage:
# $ docker build --platform linux/arm .
# Cross-compile package for target platform from build platform
FROM --platform=${BUILDPLATFORM} golang:1-alpine AS build
ADD . /tmp/go
WORKDIR /tmp/go