Skip to content

Instantly share code, notes, and snippets.

@rcrowley
rcrowley / bad-side-effects-on-mac-osx.sh
Last active August 29, 2015 13:56
A protip for authors of shell programs. I use this pattern *all the time* for working in a temporary directory and cleaning it up after I'm done but a quirk in how shells interpret failures in command substitution caused a program like these to remove my coworker's home directory when he ran said program on Mac OS X, which doesn't have `mktemp -d`.
set -e
# Looks clever, is short, but removes your working directory on Mac OS X
# where `mktemp -d` fails.
cd "$(mktemp -d)"
trap "rm -rf \"$PWD\"" EXIT INT QUIT TERM
# ...
@rcrowley
rcrowley / gist:9192703
Last active August 29, 2015 13:56
Benchmarks for Go CL 67730046

Benchmarks before CL 67730046

./bench -bench=http

2014/02/24 10:21:20 Benchmarking 1 iterations
2014/02/24 10:21:20 Benchmarking 100 iterations
2014/02/24 10:21:20 Benchmarking 10000 iterations

Benchmark of two graceful stop implementations

The server for each of these benchmarks is based on https://github.com/rcrowley/go-tigertonic/tree/master/example. It was run as ./example >/dev/null 2>/dev/null.

The client for each of these benchmarks is ab -H"Host: example.com" -c"100" -n"1000000" "http://127.0.0.1:8000/stuff/ID".

Baseline

BUILD="betable3"
set -e -x
cd "$(mktemp -d)"
trap "rm -rf \"$PWD\"" EXIT INT QUIT TERM
git clone "git://github.com/s3tools/s3cmd.git"
mkdir -p "usr/bin" "usr/lib/python2.7/dist-packages" "usr/share/man/man1"
export PYTHONPATH="usr/lib/python2.7/dist-packages"

Keybase proof

I hereby claim:

  • I am rcrowley on github.
  • I am rcrowley (https://keybase.io/rcrowley) on keybase.
  • I have a public key whose fingerprint is 16BF 2FED 3AEF 25E7 C901 FAA8 37AA AB88 53D2 F050

To claim this, I am signing this object:

@rcrowley
rcrowley / lra.go
Created July 23, 2014 00:59
Least-Recently Accessed
package lra
// LRA is a fixed-size cache which expires the least-recently added string.
type LRA struct {
i int
m map[string]struct{}
ss []string
}
func NewLRA(n int) *LRA {
@rcrowley
rcrowley / gist:22687
Created November 6, 2008 19:46
Allow Flickr Uploadr Extensions to store extra information for a user
var data = {
_xpcom: Cc['@mozilla.org/preferences-service;1']
.getService(Ci.nsIPrefService)
.getBranch('opendns.'),
get: function(k) {
var t = this._xpcom.getPrefType(k);
var fn;
if (Ci.nsIPrefBranch.PREF_BOOL == t) { fn = 'getBoolPref'; }
@rcrowley
rcrowley / gist:23535
Created November 10, 2008 16:39
Firewall ports so MS Office will run twice on the same subnet
#!/bin/sh
ipfw add deny udp from any to any 2222
ipfw add deny udp from any to any 2223
@rcrowley
rcrowley / foo
Created March 14, 2009 19:31
Django Shell Script
#!/usr/bin/env python
"""
Django Shell Script
Richard Crowley <r@rcrowley.org>
I like organized directory structures. Because of the way the Python
path works, there wasn't a readily-available way to stash shell scripts
that needed access to Django goodness away in bin/. This is a bit
heavy on the scaffolding code (six lines, geez) but works.
@rcrowley
rcrowley / deps.sh
Created April 1, 2009 00:11
Drizzle dependency installer for Ubuntu Intrepid
#!/bin/sh
#
# Drizzle dependency installer for Ubuntu Intrepid
# Richard Crowley <r@rcrowley.org>
#
if [ "." != $(dirname "$0") ] ; then
echo "[deps.sh] you must run deps.sh from the directory it is in" >&2
exit 1