Skip to content

Instantly share code, notes, and snippets.

View necrophonic's full-sized avatar

J Gregory necrophonic

  • UK
View GitHub Profile
@necrophonic
necrophonic / Makefile
Last active August 27, 2020 07:57
Makefile help macro for self documenting Makefiles
## Add the "help" target as the first target in your makefile. Then, any target
## that is marked up with a double hash as shown will display as a help message
## when you type just "make" or "make help"
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
my_target: ## This target does a thing
echo "hello"
@necrophonic
necrophonic / parser.go
Created June 26, 2020 09:36
Simple Java thread dump parser
package main
import (
"bufio"
"context"
"flag"
"fmt"
"os"
"os/signal"
"regexp"
@necrophonic
necrophonic / unmarshal.go
Last active April 20, 2020 14:06
Custom unmarshaling to a temporary struct
package main
type (
// The struct we actually want to unmarshal to
MyStruct {
name string `yaml:"name"`
age int `yaml:"age"`
flavour string `yaml:"flavour"`
} `yaml:"mystruct"`
@necrophonic
necrophonic / Makefile
Created January 16, 2020 11:21
Generic Makefile for compiling multi-platform Go apps
PLATFORMS := darwin/amd64 linux/amd64
package = cmd/${NAME}/main.go
binary = build/${NAME}
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
compile: clean ## Build binaries for all platforms defined in $PLATFORMS
ifndef NAME
$(error NAME is undefined)
@necrophonic
necrophonic / atoi.go
Last active October 3, 2022 01:36
Manual (slightly faster, but unsafe) implementation of Atoi for converting strings into integers
package main
import (
"fmt"
"math"
)
func main() {
n := "12345"
v := 0.0
@necrophonic
necrophonic / env2yml.sh
Created April 4, 2019 08:24
Script to create a yaml file from a set of environment vars
#!/bin/bash
set -e
usage() {
echo ""
echo "Usage: env2yml <source.env> <template.yml>"
echo ""
echo "Required:"
echo " - source.env .... file containing env vars to source"
@necrophonic
necrophonic / various.go
Created March 25, 2019 07:51
A collection of useful functions that don't fit in their own repos or libs but don't want to lose
/*
Useful functions for various random things.
Collected here as they don't justify full repos / libraries of their own
/*
// JAVA Analysis
// StringSizeInBytes determines the size of a java string in bytes given the number of chars in it.
// https://stackoverflow.com/questions/31206851/how-much-memory-does-a-string-use-in-java-8
func StringSizeInBytes(numChars int, isJava8 bool) int {

Keybase proof

I hereby claim:

  • I am necrophonic on github.
  • I am necrophonic (https://keybase.io/necrophonic) on keybase.
  • I have a public key ASAE7M6gxAuEWrq_3Gkh04rdldOIlMBH-Jv303ldr0fTAgo

To claim this, I am signing this object: