Skip to content

Instantly share code, notes, and snippets.

@truemped
truemped / async_mock_example.py
Created November 17, 2012 09:57
Tornado Asynchronous Mock
from mock import CallableMixin, NonCallableMock
class AsyncCallableMixin(CallableMixin):
"""Change the __call__ method such that it does not return but call the
`callback` kwarg with the return value.
"""
def __call__(_mock_self, *args, **kwargs):
cb = kwargs.get('callback', None)
@truemped
truemped / setup-statsd.sh
Created April 11, 2012 08:46 — forked from collegeman/setup-statsd.sh
Turn an Ubuntu 10.04 linode into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
@truemped
truemped / thumbnails.py
Created April 10, 2012 14:05
Thumbnail generation keeping the aspect ratio of the target width and height
# vim: set fileencoding: utf-8 :
#
import os
try:
from PIL import Image
except ImportError:
import Image
try:
@truemped
truemped / less2stylus.coffee
Created February 17, 2012 09:47 — forked from NHQ/less2stylus.coffee
Convert LESS to Stylus for Twitter Bootstrap
# Quick hack of regular expressions to convert twitter bootstrap from LESS to Stylus
less2stylus = (string) ->
string = string
.replace(/^(\ *)(.+)\ +\{\ *\n?\ */mg, "$1$2\n$1 ") # remove opening brackets
.replace(/^(\ *)([^\ ]+)\ +\{\ *\n?\ *?/mg, "$1$2\n$1 ") # remove opening brackets
.replace(/\ *\{\ *\n*/g, "\n") # remove opening brackets again (some random cases I'm too lazy to think through)
.replace(/\ *\}\ *\n*/g, "\n") # remove closing brackets
.replace(/\;\ *?$/gm, "") # remove semicolons
.replace(/@(\w+):(\ *)\ /g, "\$$1$2 = ") # replace @variable: with $variable =
.replace(/\@/g, "\$")
@truemped
truemped / gist:1717523
Created February 1, 2012 15:25 — forked from fennb/gist:1283573
nginx microcaching config example
# Set cache dir
proxy_cache_path /var/cache/nginx levels=1:2
keys_zone=microcache:5m max_size=1000m;
# Virtualhost/server configuration
server {
listen 80;
server_name yourhost.domain.com;
# Define cached location (may not be whole site)
@truemped
truemped / ubuntu puppet server passenger install.txt
Created September 30, 2011 04:30 — forked from andys/ubuntu puppet server passenger install.txt
Steps for installing puppet master in Ubuntu 10.04 with ruby 1.8 and passenger
Puppet Install steps for Ubuntu 10.04, ruby 1.8, and passenger
apt-get -y update
apt-get -y dist-upgrade
reboot
############################################
apt-get -y install build-essential
apt-get -y install bsubversion apache2 libcurl4-openssl-dev libssl-dev mysql-server
@truemped
truemped / sample.config
Created June 8, 2011 07:55 — forked from sidupadhyay/sample.config
Sample HA Proxy Config for Tornado/Socket.io Backends
global
maxconn 10000 # Total Max Connections. This is dependent on ulimit
nbproc 2
defaults
mode http
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
import trombi
from tornado.ioloop import IOLoop
ioloop = IOLoop.instance()
f = open('onemb.zero')
db = trombi.from_uri('http://localhost:5984/test')
def doc_created(doc):
@truemped
truemped / logsink.py
Created February 4, 2011 12:36
A sink for the pyzmq log handler
# Copyright (c) 2011 Daniel Truemper <truemped@googlemail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions: The above copyright notice and this
# permission notice shall be included in all copies or substantial portions of
# the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@truemped
truemped / zmq_tornado_download.py
Created January 13, 2011 14:06
Toy example demonstrating the usage of pyzmq and tornado's AsyncHTTPClient
#
# "THE BEER-WARE LICENSE":
# <truemped at goggle.com> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Daniel Truemper
#
import time
import zmq