Skip to content

Instantly share code, notes, and snippets.

I write code with my bare hands

Matt Holt mholt

I write code with my bare hands
Block or report user

Report or block mholt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mholt / macapp.go
Created May 18, 2018
Distribute your Go program (or any single binary) as a native macOS application
View macapp.go
// Package main is a sample macOS-app-bundling program to demonstrate how to
// automate the process described in this tutorial:
// Bundling the .app is the first thing it does, and creating the DMG is the
// second. Making the DMG is optional, and is only done if you provide
// the template DMG file, which you have to create beforehand.
// Example use:
mholt / stringscontext.go
Last active Jan 25, 2020
Functions from the 'strings' package as template actions. Feel free to copy+paste into your project as a starting point.
View stringscontext.go
// Functions from Go's strings package usable as template actions
// with text/template.
// This approach assumes you have some context type as a receiver,
// but if you just need the functions check out the FuncMap variant
// below.
// Commented functions are not deemed useful in template actions.
// Haven't actually used this, but this is one possible way of doing it.
// Another option is to fill a FuncMap with most of the strings package.
mholt / main.go
Created Oct 16, 2018 — forked from LiamHaworth/main.go
Example of run an interactive process on the current user from system service on windows (Golang)
View main.go
package main
import (
type Service struct {}
mholt / everything.go
Last active Dec 17, 2019
Implements 103 of the 114 Go 1.3 standard library interfaces
View everything.go
package interfaces
import (
mholt /
Created Oct 18, 2019 — forked from sleevi/
CT Best Practices (April 2017)

CT For Server (Developers)


Similar to my advice regarding OCSP Stapling for servers/server developers, based on questions I've received about "CT best practices," I wanted to write something similar for those writing server software. That is, this isn't targeted at server operators, but for those writing software like Apache, nginx, Caddy, etc.

At the most basic level, the deployment of Certificate Transparency to date has largely tried to focus the burden on CAs, rather than on server developers. If the CA is doing everything right,

View gen.go
// Handler that calls generate
func ok(w http.ResponseWriter, r *http.Request) {
// res := make([]int64, 0, 100000)
var res [100000]int64
// fmt.Println(suc)
// fmt.Printf("%T", res)
// fmt.Println(res[50])
fmt.Fprintf(w, "OK")
mholt /
Last active Jul 9, 2019
How do you like your handler configs?

Caddy 2 HTTP handlers come in two flavors: middleware and responders.

  • Middleware are in the middle of a request chain; i.e. they have a next handler to invoke.
  • Responders are content origins, at the end of a request chain; i.e. there is no next handler. Any handlers defined after it would not be invoked.

Caveat: Sometimes a handler's role is ambiguous. For example, a caching handler would be middleware on a cache miss (it needs to invoke the upstream handlers for a response, then cache it), but on a cache hit it would be a responder, since no further handlers would be invoked (it would simply write the response).

mholt / apply-license.bash
Created Mar 27, 2018
Apply the Apache 2.0 license to all your .go files
View apply-license.bash
FILES=$(find . -name "*.go" -not -path "./vendor/*" -type f)
for f in $FILES
echo "processing: $f"
ed -s $f << EOF
// Copyright YEAR YOU
mholt / interface_spider.go
Created Aug 4, 2014
Crawls for interfaces and writes them to a file.
View interface_spider.go
package main
import (
gq ""
mholt / transcript
Created Feb 26, 2016
Is it necessary to consume response body before closing it (net/http client code)?
View transcript
mholt [9:10 AM]
When using http.Get(), is it really necessary to read the full response body just to close it later?
The docs keep saying `Caller should close resp.Body when done reading from it.` and I keep seeing code like this:
io.Copy(ioutil.Discard, resp.Body)
You can’t perform that action at this time.