Skip to content

Instantly share code, notes, and snippets.

@craigbeck
craigbeck / ServiceBisSpike.cs
Created May 25, 2012 16:31
MassTransit and Autofac integration spike
using System;
using Autofac;
using NUnit.Framework;
using MassTransit;
namespace ServiceBusSpike.Sandbox
{
public class ServiceMessage
{
public int Id { get; set; }
@craigbeck
craigbeck / gist:4166088
Created November 29, 2012 01:19
creating empty git commits
This is how you create empty commit (it won't have any file changes, but still has message, who, when &c.) I think this can be used to start empty pull requests.
git commit -m "what?" --allow-empty
@craigbeck
craigbeck / debug_timing.py
Created December 6, 2012 00:31
python decorator to time method execution
# timing func
import time
import logging
def log_timing(func):
def inner(*args, **kwargs):
t1 = time.time()
res = func(*args, **kwargs)
t2 = time.time()
logging.getLogger().debug('%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0))
return res
@craigbeck
craigbeck / test.sh
Created December 7, 2012 21:11
Python unittest colorized output
#!/bin/sh
RED=`echo '\x1b[31m'`
GREEN=`echo '\x1b[32m'`
CYAN=`echo '\x1b[34m'`
RESET=`echo '\x1b[0m'`
MAGENTA=`echo '\x1b[35m'`
python -m unittest discover $@ 2>&1 | sed "s/.*[oO][kK]$/$GREEN&$RESET/" \
| sed "s/.*ERROR$/$MAGENTA&$RESET/" \
@craigbeck
craigbeck / show-colors.sh
Created December 11, 2012 17:27
Show all terminal colors
#!/usr/bin/env python
import sys
terse = "-t" in sys.argv[1:] or "--terse" in sys.argv[1:]
for i in range(2 if terse else 10):
for j in range(30, 38):
for k in range(40, 48):
if terse:
print "\33[%d;%d;%dm%d;%d;%d\33[m " % (i, j, k, i, j, k),
else:
@craigbeck
craigbeck / increase_hadoop_heap_size.sh
Created December 17, 2012 23:58
increase_hadoop_heap_size
#!/bin/bash
if [ $# -lt 1 ]; then
SIZE="2048"
else
SIZE=$1
fi
echo "export HADOOP_HEAPSIZE=${SIZE}" >> /home/hadoop/conf/hadoop-user-env.sh
@craigbeck
craigbeck / gist:4349721
Created December 21, 2012 00:02
NSQ output when nsq_to_file cannot connect to nsqd
merlin.local ~> $ nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161
2012/12/20 15:42:16 starting AsyncHandler go-routine
2012/12/20 15:42:16 lookupd addr 127.0.0.1:4161
2012/12/20 15:42:16 LOOKUPD: querying http://127.0.0.1:4161/lookup?topic=test
2012/12/20 15:42:16 [merlin.local:4150] connecting to nsqd
2012/12/20 15:42:17 ERROR: failed to connect to nsqd (merlin.local:4150) - dial tcp merlin.local:4150: i/o timeout
2012/12/20 15:42:46 old new test.merlin.2012-12-20_15.log
2012/12/20 15:42:46 opening /tmp/test.merlin.2012-12-20_15.log
2012/12/20 15:44:20 LOOKUPD: querying http://127.0.0.1:4161/lookup?topic=test
2012/12/20 15:44:20 [merlin.local:4150] connecting to nsqd
@craigbeck
craigbeck / nsq_to_file.log
Created December 21, 2012 05:02
nsq success logs
merlin.local ~> $ nsq_to_file --nsqd-tcp-address=127.0.0.1:4150 --topic=test
2012/12/20 21:00:09 starting AsyncHandler go-routine
2012/12/20 21:00:09 [127.0.0.1:4150] connecting to nsqd
2012/12/20 21:00:09 old new test.merlin.2012-12-20_21.log
2012/12/20 21:00:09 opening /tmp/test.merlin.2012-12-20_21.log
2012/12/20 21:00:09 syncing 1 records to disk
2012/12/20 21:00:39 syncing 51 records to disk
2012/12/20 21:00:39 [127.0.0.1:4150] received heartbeat from nsqd
@craigbeck
craigbeck / query-syntax.peg
Last active December 11, 2015 21:08
updated to return tree
start =
compoundExp
/ exp
op =
equals
/ logicalOp
/ stringOp
@craigbeck
craigbeck / gist:5376338
Created April 13, 2013 00:58
Elasticsearch file descriptor limits in AWS EC2 Ubuntu instance - how to fix when running under daemontools
1. change `/etc/init/sfsvscan.conf` and add `limit nofile 32000 32000`
2. change `/etc/security/limits.conf` and add
`* hard nofile 40960`
`* soft nofile 40960`
3. confirm by adding `-Des.max-open-files=true` to run file of elasticsearch