Skip to content

Instantly share code, notes, and snippets.

def connect_retry(exceptions, max=5, first=2, multiplier=2):
def decorator(fun):
@functools.wraps(fun)
def retrier(*args, **kwargs):
tried = 0
wait = first
while tried <= max:
try:
conn = fun(*args, **kwargs)
print "reconnected!"
import Queue
import random
class RandomQueue(Queue.Queue):
"""A queue that gets a random item from the queue
"""
def _init(self, maxsize):
self.queue = []
@minimal
minimal / .slate
Created October 3, 2012 13:45
initial slate config
# This is the default .slate file.
# If no ~/.slate file exists this is the file that will be used.
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
# Resize Bindings
# bind right:alt resize +10% +0
# bind left:alt resize -10% +0
@minimal
minimal / githubstatus.py
Created September 28, 2012 11:18
set github commit status from command line
import logging
import json
import argparse
import requests
github_base = "https://api.github.com"
github_status_url = github_base + "/repos/{repo_name}/statuses/{sha}?access_token={token}"
token = ''
@minimal
minimal / s3_update_futures.py
Created August 15, 2012 11:27
Update s3 metadata concurrently with futures
from boto.s3.connection import S3Connection
from futures import ThreadPoolExecutor
import futures
connection = S3Connection('id', 'key')
import logging
logging.basicConfig(level=logging.INFO)
@minimal
minimal / test_importer.py
Created August 10, 2012 14:51
Await data from non blocking function
import time
def await_data(func, *args, **kwargs):
"""
Given a function and its args keep calling until data is returned
Tries do deal with mongo slowness to show recently inserted data
"""
thefunc = partial(func, *args, **kwargs)
max_times = 10
@minimal
minimal / cuberoot.go
Last active October 6, 2015 00:57
Go tour exercises
package main
import "fmt"
import "math/cmplx"
func Cbrt(x complex128) complex128 {
z := 1.0+0i
zold := z
cont := true
for i := 0; cont == true ; i++ {
@minimal
minimal / fabfile.py
Created March 16, 2012 15:49
Write git revision during fab deploy
# todo: check working copy is clean, master branch etc
@runs_once
def build():
"Build source distribution locally"
store_git_revision()
with settings(warn_only=True):
local("rm dist/*")
local("python setup.py sdist")
@minimal
minimal / knotify_log.py
Created November 23, 2011 15:14
KDE knotify logging handler
"""KDE knotify logging handler"""
import logging
import dbus
class KNotifyHandler(logging.Handler):
"""Log messages to kde notifications"""
def __init__(self, level=logging.NOTSET):
@minimal
minimal / paratail.py
Created October 26, 2011 18:27
Fabric Parallel remote logs
"""
Parallel remote logs
$ fab hoststask tail_log --linewise
"""
from fabric.decorators import parallel, task
from fabric.tasks import run
@task