Skip to content

Instantly share code, notes, and snippets.

View lukemarsden's full-sized avatar

lukemarsden

View GitHub Profile
@lukemarsden
lukemarsden / httpRequest.py
Created February 27, 2011 21:11
Simple function to do an HTTP POST using Twisted Agent
from twisted.web.iweb import IBodyProducer
from twisted.internet import defer
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
import urllib
class StringProducer(object):
implements(IBodyProducer)
def __init__(self, body):
@lukemarsden
lukemarsden / muninprotocol.py
Created June 25, 2011 20:16
MuninClientProtocol
import re
import time
from twisted.internet import reactor
from twisted.internet import protocol
from twisted.internet import defer
class MuninClientProtocol(protocol.Protocol):
def __init__(self, out_channel, server):
@lukemarsden
lukemarsden / serialize.py
Created June 30, 2011 21:45
Serialize operations
def serialize(func):
"""
Decorator to make operations which modify state in the cluster happen one
at a time
"""
def wrap(self, *a, **kw):
return self._do_operation(func, self, *a, **kw)
return wrap
victimsToPrune = []
while len(victimsToPrune) < 10 and suggestedDeletions:
victimsToPrune.append(suggestedDeletions.pop())
for victim in victimsToPrune:
d.addCallback(lambda ign: debug(victim, msg='start'))
d.addCallback(lambda ign:
self._snapshotManipulator.prune(victim.key, local_forest))
#!/bin/sh
# $Id: zfsinstall 102 2011-03-01 23:22:04Z mm $
#
# mfsBSD ZFS install script
# Copyright (c) 2011 Martin Matuska <mm at FreeBSD.org>
#
FS_LIST="var tmp"
usage() {
echo "Usage: $0 [-h] -d geom_provider [-d geom_provider ...] -t archive_file [-r mirror|raidz] [-m mount_point] [-p zfs_pool_name] [-V zfs_pool_version] [-s swap_partition_size] [-z zfs_partition_size] [-c] [-l] [-4]"
__pyx_t_1 = PyObject_GetAttr(__pyx_v_blob, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
PyObject* sequence = __pyx_t_2;
if (likely(PyTuple_CheckExact(sequence))) {
if (unlikely(PyTuple_GET_SIZE(sequence) != 5)) {
if (PyTuple_GET_SIZE(sequence) > 5) __Pyx_RaiseTooManyValuesError(5);
@lukemarsden
lukemarsden / spreader.py
Created September 8, 2011 12:55
Twisted Spread integration
# Released under BSD 2-clause license by Luke Marsden
from twisted.internet import reactor
from twisted.application import service
from twisted.python import log
import spread
import zlib
def hex2ip(sender):
f = file(..)
nextChunk = True
def work():
while nextChunk is not None:
nextChunk = f.read(1024)
for thing in things:
thing.protocol.write(nextChunk)
yield
pid = os.fork()
if pid != 0:
# Make the original process the master
masterService = StreamServerEndpointService(
TCP4ServerEndpoint(reactor, 9881),
pb.PBServerFactory(AwesomeProxyMaster()))
masterService.setServiceParent(application)
# Name the master nicely (avoid backward compatibility with restarts/upgrades)
HybridUtils.setproctitle('AwesomeProxy')
@lukemarsden
lukemarsden / gen-btt-stats.py
Created October 11, 2011 13:40
gen-btt-stats.py
#!/usr/bin/env python
import re, sys
try:
filename, countLimit = sys.argv
except:
print "Usage: %s FILE" % (sys.argv[0],)
def main():
"""