Skip to content

Instantly share code, notes, and snippets.

View jasonhancock's full-sized avatar
meh

Jason Hancock jasonhancock

meh
View GitHub Profile
@kirk91
kirk91 / fd_receive.go
Last active November 30, 2022 01:31
Pass File Descriptor over Unix Domain Socket
package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
"syscall"
@sdboyer
sdboyer / goslowtests.bash
Created October 30, 2017 01:57
Figure out which of your go (sub)tests are slow
# This will sort go test -v output in ascending order of time to complete the test
$ go test -v | sed -n 's#.*PASS: \([^ ]*\) (\([0-9]*\.[0-9]\{2\}\)s)#\2 \1#p' | sort -g
# Add this to e.g. ~/.bashrc, ~/.zshrc, then you can pipe to it: `go test -v | goslowtests`
function goslowtests {
sed -n 's#.*PASS: \([^ ]*\) (\([0-9]*\.[0-9]\{2\}\)s)#\2 \1#p' | sort -g
}
@jessfraz
jessfraz / j3ss.co.conf
Created October 1, 2016 21:37
nginx go-get vanity urls
server {
....
location ~ ^/x/(.*) {
if ($args = "go-get=1") {
add_header Content-Type text/html;
return 200 '<meta name="go-import" content="$host/x/$1 git https://github.com/jessfraz/$1.git">';
}
return 302 https://github.com/jessfraz/$1;
}
@clstokes
clstokes / assume-role-policy.json
Last active September 1, 2022 20:15
Example: Terraform IAM Role
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""

A Gopher Rising

Inspired by Maya Angelou's Still I Rise

You may walk through my GitHub history,
With it’s non idiomatic and fragal lines,
You may value me less than dirt,
But still, like dust, I’ll rise.
@cep21
cep21 / client_test.go
Last active June 13, 2023 04:54
Stub out RoundTripper to test HTTP client
type roundTripFunc func (r *http.Request) (*http.Response, error)
func (s roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) {
return s(r)
}
func TestSword(t *testing.T) {
var c Client
c.Client.Transport = roundTripFunc(func(r *http.Request) (*http.Response, error) {
assert.Equal(t, r.URL.Path, "/v1/item/sword")
@stoewer
stoewer / ToSnakeCase.go
Last active March 29, 2022 16:59
Convert camel case to snake case in Go http://play.golang.org/p/9ybqJat1Hr
import (
"fmt"
"strings"
"regexp"
)
var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
@EntropyWorks
EntropyWorks / aptly-mirror.sh
Last active September 17, 2021 17:46
This is my script for mirroring a bunch of apt repos. This only touches the very basics of what (aptly)[http://www.aptly.info/] can do.
#!/bin/bash
#
# Copyright 2014 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
# Authored by Yazz D. Atlas <yazz.atlas@hp.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
@michaljemala
michaljemala / tls-client.go
Last active April 10, 2024 01:57
SSL Client Authentication Golang sample
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"io/ioutil"
"log"
"net/http"
)
@m1
m1 / ferengi-apache.txt
Last active September 15, 2023 07:33
How to throttle the FCC to dial up modem speeds on your website using Apache.
# How to throttle the FCC to dial up modem speeds on your website using Apache.
# Ported from https://gist.github.com/kyledrake/e6046644115f185f7af0
## The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
##
## Current known FCC address ranges:
## https://news.ycombinator.com/item?id=7716915
##
## Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft