Skip to content

Instantly share code, notes, and snippets.

View elithrar's full-sized avatar
Helping make the Internet better.

Matt Silverlock elithrar

Helping make the Internet better.
View GitHub Profile
require 'bundler/setup'
require 'sinatra/base'
require 'rack/contrib'
# The project root directory
$root = ::File.dirname(__FILE__)
class SinatraStaticServer < Sinatra::Base
get(/.+/) do
elithrar / use.go
Last active December 29, 2015 02:29
use.go — the little HTTP middleware helper that could.
// use provides a cleaner interface for chaining middleware for single routes.
// Middleware functions are simple HTTP handlers (w http.ResponseWriter, r *http.Request)
// r.HandleFunc("/login", use(loginHandler, rateLimit, csrf))
// r.HandleFunc("/form", use(formHandler, csrf))
// r.HandleFunc("/about", aboutHandler)
func use(h http.HandlerFunc, middleware ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc {
for _, m := range middleware {
h = m(h)
elithrar / stripe-config.js
Created November 27, 2013 00:40
Example Stripe Checkout - Custom Integration for #stripe
// Disable the payment/submit button until everything has loaded
// (if Stripe fails to load, we can't progress anyway)
$(document).ready(function() {
$("#payment-button").prop('disabled', false)
var handler = StripeCheckout.configure("customButtonA", {
key: '<yourpublishablekey',
token: function(token, args){
var $input = $('<input type=hidden name=stripeToken />').val(;
elithrar / ratelimit.go
Last active February 17, 2016 06:14
Quick and dirty HTTP request rate limiter (will eventually wrap this into a package!)
package main
import (
type RateStore struct {
elithrar /
Last active May 3, 2021 15:38
WAL-E + Postgres 9.x (single server + DB) Setup and Recovery

A quick "how to" on what you need to do to both setup AND recover a single-server PostgreSQL database using WAL-E

  • WAL-E:
  • Assuming Ubuntu 12.04 LTS ("Precise")
  • We'll be using S3. Make sure you have an IAM in a group with GetObject, ListBucket and PutObject on the bucket you want to use (and that it's not public).


  1. These packages:
elithrar / authserver.go
Last active June 30, 2021 07:12
HTTP Basic Auth example in Go (based on + bespoke middleware implementation)
package main
import (
func main() {
elithrar / supervisord.conf
Last active September 4, 2021 20:08
Example supervisord.conf for a Go application #golang
elithrar / use.go
Last active January 5, 2023 11:19
go/use: Little middleware chains that could. Inspired by comments here:
r := mux.NewRouter()
// Single handler
r.HandleFunc("/form", use(http.HandlerFunc(formHandler), csrf, logging)
// All handlers
http.Handle("/", recovery(r))
// Sub-routers
apiMiddleware := []func(http.Handler) http.Handler{logging, apiAuth, json}
elithrar / helpers.go
Created June 5, 2014 11:50
GenerateShortGUID() - generate a 8-byte, URL-safe ID for slightly saner URLs with a very low collision chance ( and avoid ugliness. Leverages Go's existing cryptographically secure random number generator:…
// GenerateRandomBytes generates a crytographically secure random byte string using crypto/rand.
func GenerateRandomBytes(s int) ([]byte, error) {
b := make([]byte, s)
n, err := rand.Read(b)
if n != len(b) || err != nil {
return nil, fmt.Errorf("Unable to successfully read from the system CSPRNG (%v)", err)
return b, nil
elithrar /
Created June 12, 2014 21:43

Keybase proof

I hereby claim:

  • I am elithrar on github.
  • I am silverlock ( on keybase.
  • I have a public key whose fingerprint is 73E6 AFB3 9131 E24C A140 F660 D6E8 9C78 40EB 8D6B

To claim this, I am signing this object: