Skip to content

Instantly share code, notes, and snippets.

@jeddenlea
jeddenlea / chash.py
Created October 8, 2018 19:07
Models consistent hash bias
#!/usr/bin/python
import argparse
import hashlib
import struct
import sys
p = argparse.ArgumentParser()
p.add_argument('nodes', type=int)
p.add_argument('vnodes', type=int, nargs='?', default=256)
@jeddenlea
jeddenlea / stupidproxy.go
Created May 13, 2015 23:11
Stupid http proxy
package main
import (
"flag"
"log"
"net/http"
"net/http/httputil"
"strings"
)
@jeddenlea
jeddenlea / statichttp.go
Created June 19, 2014 20:12
Quick and dirty file server
package main
import (
"flag"
"log"
"net/http"
)
var (
flagLog = flag.Bool("log", false, "Log requests")
/*
jed@thevm:~/go/src/bench/copy$ go test --test.bench=. --test.benchtime=10s .
testing: warning: no tests to run
PASS
BenchmarkAppendNil 50000 627957 ns/op
BenchmarkMakeCopy 50000 627037 ns/op
BenchmarkAppendMake 50000 611550 ns/op'
And using a 1k 's'...
BenchmarkAppendNil 50000000 563 ns/op
@jeddenlea
jeddenlea / gist:9381209
Created March 6, 2014 02:40
cpanm dependency tree bug
$ ls
cpanfile
$ cat cpanfile
requires 'Module::Refresh', '== 0.17';
requires 'Path::Class', '== 0.26';
$ cpanm -L local --cpanfile cpanfile --installdeps .
--> Working on .
Configuring /home/jed/test ... OK
==> Found dependencies: Module::Refresh, Path::Class
--> Working on Module::Refresh
@jeddenlea
jeddenlea / fmtcomment
Last active January 3, 2016 12:49
Simple little script to aid formatting of comments in vim.
#!/usr/bin/env python
"""
Select some text and then "!fmtcomment". It understands "//" and
"#" comments, works with indenting in spaces and tabs. It assumes
you want to squeeze your text within 80-chars, and treats tabs as
4 spaces thusly.
E.g., will turn
// Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
@jeddenlea
jeddenlea / benchpcre.c
Last active January 2, 2016 21:39
Shitty PCRE benchmarking
/* Shitty PCRE regexp benchmarking!
* $ gcc -o benchpcre benchpcre.c -ltr -lpcre
* $ ./benchpcre "^f.o$" "foo"
* result: 0
* Without extras:
* 0.060841s elapsed
* With extras:
* 0.058072s elapsed
*/