Skip to content

Instantly share code, notes, and snippets.

@drewr
drewr / test.c
Created November 18, 2011 15:30
#include <stdio.h>
#include <string.h>
void hex2char(char *a, unsigned char *buf)
{
int ch;
char tmp[2];
int i, j;
for (i=0,j=0; i<strlen(a); i=i+2,j++) {
tmp[0] = a[i];
@drewr
drewr / linreg.clj
Created November 20, 2011 03:01
Linear regression
(defn reg [pairs]
(let [M (count pairs)
bldr (fn [acc [x y]]
(let [x (bigdec x)
y (bigdec y)]
(merge-with
+ acc
{:∑x x
:∑y y
:∑xy (* x y)
@drewr
drewr / phttperf.sh
Created December 13, 2011 23:47
parallel httperf
#!/bin/zsh
prog=$0
die() {
if [[ ! -z $1 ]]; then
print $1
fi
exit 1
}
@drewr
drewr / headrand.awk
Created March 8, 2012 14:36
Random lines from a file
#!/usr/bin/env gawk
# By Steve Huwig
# http://stackoverflow.com/questions/692312/randomly-pick-lines-from-a-file-without-slurping-it-with-unix
# Usage: gawk -f headrand.awk -v n=NNNN <file
# Waterman's Algorithm R for random sampling
# by way of Knuth's The Art of Computer Programming, volume 2
import System.Environment
import Data.List
splitN :: Int -> [a] -> [[a]]
splitN n [] = []
splitN n xs =
[y] ++ (splitN n ys)
where (y, ys) = splitAt n xs
main = do
#!/bin/zsh
#
# Building Emacs/Gnus/ERC apps on OS X 10.6 Snow Leopard.
#
# Need git mirror of emacs: git clone git://git.savannah.gnu.org/emacs.git
# And deps in MacPorts.
#
VERSION=$(git log --pretty=format:"%ai %h" -1 | perl -p -e 's,(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d) [^ ]+ ([a-z0-9]+),\1\2\3-\4\5\6-\7,')
###VERSION=$(bzr log -l 1 | grep revno | awk '{print $2}')
@drewr
drewr / master.sh
Created November 20, 2012 15:09
Check master on each node
IF=wlan0
ESPORT=9200
echo -n me: $(sudo ifconfig $IF | sed "s,.*inet addr:\([^ ]*\).*,\1,;tx;d;:x") "master: "
curl -s localhost:${ESPORT}/_cluster/state | \
jsawk -n 'out(this.master_node,
this.nodes[this.master_node].name,
this.nodes[this.master_node].transport_address)'
curl -s -X DELETE localhost:9200/test
echo
echo mapping
curl -s -X PUT localhost:9200/test -d '
{
"mappings": {
"orte": {
"dynamic": false,
"properties": {
"ort": {
foo
http_port 3128
visible_hostname betasquid
acl localnet src 127.0.0.1/32
http_access allow localnet
acl vboxnet src 192.168.56.0/24
http_access allow vboxnet