Skip to content

Instantly share code, notes, and snippets.

@asenchi
asenchi / redis_leaky_bucket.py
Created November 17, 2012 18:14 — forked from jdunck/redis_leaky_bucket.py
leaky bucket queue - redis 2.6 + lua + python
#cribbed from http://vimeo.com/52569901 (Twilio carrier call origination moderation)
# The idea is that many fan-in queues can enqueue at any rate, but
# dequeue needs to happen in a rate-controlled manner without allowing
# any individual input queue to starve other queues.
# http://en.wikipedia.org/wiki/Leaky_bucket (second sense, "This version is referred to here as the leaky bucket as a queue.")
#
# requires:
# redis 2.6+
# redis-py>=2.7.0
# anyjson
@asenchi
asenchi / logstash-mysql-query-parse.md
Created September 20, 2012 01:06 — forked from jordansissel/logstash-mysql-query-parse.md
parsing mysql's bullshit query log format with logstash

parsing mysql query logs with logstash

The problem is that some lines in the file are missing timestamps when they aren't continuations of any previous line. It's dumb, really.

The mysql query log is seriously bullshit format, but nothing logstash can't unscrew.

The main goal here is to show how we can fix the 'missing timestamp' problem.

% ruby bin/logstash agent -e '

@asenchi
asenchi / aa_instructions.md
Created May 2, 2012 03:59 — forked from NZKoz/aa_instructions.md
Back Up All Your Gmail
  • Install getmail (aptitude install getmail4)
  • Set Up Your Imap Server (tl;dr)
  • getmail
  • ruby date_based_archive.rb ~/Maildir/.Archive
@asenchi
asenchi / gist:2570828
Created May 1, 2012 19:44 — forked from technoweenie/gist:2568117
Python Master/Worker forking with ZeroMQ instead of unix signals.
# Don't use this.
import zmq
import os
class Worker:
def __init__(self):
print "parent: %d, pid: %d" % (os.getppid(), os.getpid())
self.pid = os.getppid()
self.context = zmq.Context()
self.sub = self.context.socket(zmq.SUB)
@asenchi
asenchi / Makefile
Created April 28, 2012 14:10
Go WebSocket Example
run: clean example
./example
include $(GOROOT)/src/Make.inc
TARG=example
GOFILES=\
main.go\
hub.go\
conn.go
@asenchi
asenchi / sed cheatsheet
Created April 3, 2012 13:17 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@asenchi
asenchi / maximum_battery_life.md
Created March 19, 2012 15:58 — forked from mrflip/maximum_battery_life.md
maximum battery life checklist -- use before a long plane flight

Max Battery Life Checklist

Here is a checklist to follow if you want maximum battery life -- for instance if you're about to get on a long plane flight.

10 hour battery life on a non-SSD Macbook Pro 17"

Low power use checklist

With power connected:

@asenchi
asenchi / README.md
Created March 17, 2012 03:01
Sequel::Factory

Sequel::Factory

Sequel::Factory implements a tiny DSL on Sequel::Model that allows you to create factories for objects of a model class. A factory is simply a Ruby block that gets evaluated each time a new object is generated. Inside the block you can call methods that correspond to the names of attributes of the object you're creating. If a value is given to the method, it will set the value for that attribute. Regardless, the method will always return the current value for that attribute.

Factories have names (the default name is :default) and you can include a factory in another. When you do this, the included factory will run first.

A simple factory for a User class might look like this:

User.factory do
@asenchi
asenchi / sc-dl.js
Created March 6, 2012 05:36 — forked from pheuter/sc-dl.js
Bookmarklet that generates download link for a Soundcloud upload
(function(d) {
var dl = d.createElement('a');
dl.innerText = 'Download MP3';
dl.href = "http://media.soundcloud.com/stream/"+d.querySelector('#main-content-inner img[class=waveform]').src.match(/\.com\/(.+)\_/)[1];
dl.download = d.querySelector('em').innerText+".mp3";
d.querySelector('.primary').appendChild(dl);
dl.style.marginLeft = '10px';
dl.style.color = 'red';
dl.style.fontWeight = 700;
})(document);
@asenchi
asenchi / spdy-server.go
Created February 29, 2012 04:57 — forked from bgentry/spdy-server.go
A simple SPDY server
// Based heavily on https://bitbucket.org/zombiezen/spdy, adapted for
// recent Go releases.
package main
import (
"crypto/tls"
"fmt"
"go.net/spdy"
"io"