Skip to content

Instantly share code, notes, and snippets.

View athomason's full-sized avatar

Adam Thomason athomason

  • Fastly
  • San Francisco, CA
View GitHub Profile
// +build linux
package reset
import (
"net"
"strings"
"testing"
"unsafe"
@athomason
athomason / cardapprox.go
Last active October 30, 2019 09:25
Cardinality estimator
// An implementation of https://arxiv.org/abs/1512.07901
//
// Simple set cardinality estimation through random sampling
//
// We present a simple algorithm that estimates the cardinality n of a set V
// when allowed to sample elements of V uniformly and independently at random.
// Our algorithm with probability (1−δ) returns a (1±ε)−approximation of n...
package main
@athomason
athomason / mltshp.user.js
Created March 4, 2019 02:50
mltshp gif link adder
// ==UserScript==
// @name mltshp gif link adder
// @namespace http://tampermonkey.net/
// @version 0.1
// @description add a link for the .gif version of any <video>
// @author daam
// @match https://mltshp.com/*
// @grant none
// ==/UserScript==
@athomason
athomason / drain.go
Created December 17, 2018 09:41
net/http: draining response bodies to enable connection reuse
/*
Tags: golang http response drain copy close
Q. Does it matter if you drain an http.Transport's Response.Body before
Close'ing it?
A. Yes, failing to read a non-empty Body until EOF can make a connection not
reusable.
// usage: go run decrypt_pgp.go --keyfile private.key.asc file1.gz.pgp file.gz.pgp ...
package main
import (
"flag"
"io"
"log"
"os"
"strings"
#!/bin/bash
t1=`tempfile`
t2=`tempfile`
trap "rm -f $t1.go $t2.go $t2" EXIT
echo "package main; func main() { $@; }" > $t1.go
goimports $t1.go > $t2.go
if [[ $? != 0 ]]; then
package cmap
import (
"sync"
"sync/atomic"
"testing"
)
type (
Key int // any comparable type

Keybase proof

I hereby claim:

  • I am athomason on github.
  • I am athomason (https://keybase.io/athomason) on keybase.
  • I have a public key whose fingerprint is 7566 A71B A837 7771 2FAD DFD3 EDB4 D59B 7551 BF6C

To claim this, I am signing this object:

$ModLoad imtcp
$Template Fastly, "/var/log/fastly/fastly-%$YEAR%-%$MONTH%-%$DAY%.log
$RuleSet Fastly
*.* ?Fastly
$InputTCPServerBindRuleset Fastly
$InputTCPServerRun 1514
@athomason
athomason / gist:7344965
Created November 6, 2013 22:07
.vim/colors/adam.vim
" vim: tw=0 ts=4 sw=4
" Vim color file
" Derived from koehler.vim
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name = "adam"