Skip to content

Instantly share code, notes, and snippets.

View taylortrimble's full-sized avatar

Taylor Trimble taylortrimble

  • San Francisco, CA
  • 22:54 (UTC -07:00)
View GitHub Profile
@taylortrimble
taylortrimble / config.yaml
Last active February 25, 2023 20:14
Recursive code config
# Configure your own custom Rec Mono for Code font
#
# /$$$$$$ /$$
# /$$ / / / $$$
# /$$$$$$$ /$$$$$$$ /$$ $$$$$ /$$$$$$$$$ /$$$$$ /$$$$$$$ /
# /$$_____/ /$$____ $$ | $$$___ $$ |___ $$__/ |___ $$ /$$ $$
# | $$ | $$ | $$ | $$ | $$ | $$ | $$ \ $$$$$$$
# | $$ | $$ | $$ | $$ | $$ | $$ | $$ \ $$ /
# \ $$$$$$$ \ $$$$$$$ | $$ | $$ /$$$$$$$$$ /$$$$$$$$$ / $$$$$$$$
@taylortrimble
taylortrimble / p-256-csr.sh
Created October 13, 2020 22:56
One-liner to generate a P-256 private key and CSR
openssl req -new -newkey ec:<(openssl ecparam -name prime256v1) -nodes -keyout key.pem -out csr.pem
@taylortrimble
taylortrimble / damm.go
Created April 1, 2018 22:22
Damm check digit package for golang
package damm
import "strconv"
// DefaultDamm10 has as its Matrix a 10x10 totally anti-symmetric quasigroup
// retrieved from Damm's doctoral dissertation.
//
// https://en.wikipedia.org/wiki/Damm_algorithm
var DefaultDamm10 = Damm{Matrix: [][]int{
[]int{0, 3, 1, 7, 5, 9, 8, 6, 4, 2},
@taylortrimble
taylortrimble / kdf.go
Created April 1, 2018 00:34
An implementation of the NIST concat KDF from SP 800-56A rev 2
package ecies
import (
"encoding/binary"
"hash"
"io"
)
type nistConcatKDF struct {
hash hash.Hash
@taylortrimble
taylortrimble / framing.proto
Created February 21, 2017 00:32
An idea for framing gRPC requests from JavaScript WebSockets to a generic proxy.
syntax = "proto3";
option go_package = "proxy";
// Frames an API request message.
//
// Each request to the API has a unique stream id per-connection, starting at one.
// This stream id associates all request and response messages for a single request
// together.
//
@taylortrimble
taylortrimble / mock.go
Created December 30, 2014 17:14
Mock sentry server that responds with success no matter what
package raven
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
)
@taylortrimble
taylortrimble / main.go
Last active August 29, 2015 14:06
A Go web server that redirects URLs which don't correspond to a file to index.html or some other suitable page.
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)
@taylortrimble
taylortrimble / basic_auth.go
Created August 16, 2014 21:34
Get Basic Auth username and password in Go
// GetBasicAuth parses the username and password from an HTTP request Basic Authorization header.
// See RFC 2617.
func GetBasicAuth(r *http.Request) (username, password string, err error) {
// Get the Authorization header.
authHeader := r.Header.Get("Authorization")
if authHeader == "" {
return "", "", errors.New("authorization header was not provided")
}
// Check the Authorization type is "Basic"
@taylortrimble
taylortrimble / errors.go
Last active August 29, 2015 14:03
Golang errors and such
package main
// UserError contains error information presented to the users of our API
type UserError struct {
Msg string `json:"message"`
Code int `json:"error"`
}
// ApplicationError contains information about errors that arise while accessing resources.
type ApplicationError struct {
@taylortrimble
taylortrimble / iptables.sh
Created March 14, 2014 14:29
A simple iptables config script, using some tutorial's best practices.
sudo iptables -A INPUT -i lo -j ACCEPT # Local loopback
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Established connections
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # SSH
sudo iptables -A INPUT -p tcp --dport 28600:28699 -j DROP # Block 286XX
sudo iptables -A INPUT -j DROP # Drop everything else