Skip to content

Instantly share code, notes, and snippets.

View crhntr's full-sized avatar

Christopher Hunter crhntr

View GitHub Profile
@crhntr
crhntr / generate_javascript_class.go
Created December 1, 2020 06:19
This script generates Javascript classes for go structs.
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"log"
"reflect"
"strings"
@crhntr
crhntr / main.go
Last active August 13, 2020 09:00 — forked from philippta/main.go
Clean Go API example with access policies
// I saw this in a reddit post. I thought I would refactor it using a functional pattern.
// I don't think my refactor makes sense after noticing that this pattern is what chi suggests.
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
@crhntr
crhntr / generate_mysql_certs.sh
Last active June 2, 2020 21:42
Generates self-signed certificate authority (CA) and SSL keys for MySQL server (the following were tested with Percona) with localhost in subject alternative name (SAN) for text fixures
openssl req -x509 -new -batch -nodes -sha256 -days 90 -subj "/CN=ca" -keyout ca-key.pem -out ca.pem
openssl req -new -sha256 -nodes -subj "/CN=localhost" -keyout server-key.pem -out server-cert.csr
openssl x509 -req -days 90 -sha256 -CAcreateserial -extfile <(printf "subjectAltName=DNS:127.0.0.1,DNS:0.0.0.0") -in server-cert.csr -CA ca.pem -CAkey ca-key.pem -out server-cert.pem
#!/usr/bin/env bash
brew update && brew cask install google-chrome visual-studio-code cloudfoundry/tap/cf-cli go iterm2
@crhntr
crhntr / http_test.go
Last active August 13, 2019 04:38
Some helpers for mocking requests
package foo_test
import (
"bytes"
"io"
"io/ioutil"
"net/http"
)
type RoundTriper struct {
package main
type Element struct {
Name string
Attributes []Attribute
}
type Attribute string
func (attr Attribute) IsVoid() bool {
// Sort "generic"
// https://medium.com/capital-one-tech/closures-are-the-generics-for-go-cb32021fb5b5
type sorter struct {
len int
swap func(i, j int)
less func(i, j int) bool
}
func (x sorter) Len() int { return x.len }
func (x sorter) Swap(i, j int) { x.swap(i, j) }
@crhntr
crhntr / shellSort.go
Last active March 6, 2018 20:01
Shell Sort Implemented In Go Using Incremental Insertion Sort
// see https://play.golang.org/p/dB1ELVO8c69
package main
import (
"fmt"
"math/rand"
)
const MaxNum = 15
@crhntr
crhntr / httpcontext.go
Created January 6, 2018 10:27
An idea for a tool for handlers
package column
import (
"encoding/json"
"net/http"
"github.com/globalsign/mgo"
"github.com/julienschmidt/httprouter"
)
@crhntr
crhntr / mgocert.go
Last active June 25, 2018 08:15
autocert.Cert Implementation using mgo for MongoDB backend
package mgocert
import (
"context"
"golang.org/x/crypto/acme/autocert"
mgo "gopkg.in/mgo.v2"
)
type Cache struct {