Skip to content

Instantly share code, notes, and snippets.

class FlexibleRequest(urllib2.Request):
VALID_METHODS = [ 'GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'TRACE', 'OPTIONS', 'CONNECT', 'PATCH' ]
def __init__(self, *args, **kwargs):
if 'method' in kwargs:
if not kwargs['method'] in self.VALID_METHODS:
raise ValueError("Invalid method specified: %s" % kwargs['method'])
self.method = kwargs.pop('method')
else:
self.method = None
urllib2.Request.__init__(self, *args, **kwargs)
@mleinart
mleinart / cloudkick_handler.rb
Created March 25, 2011 14:18
Chef report handler to push status to cloudkick
require 'rubygems'
require 'cloudkick'
require 'json'
require 'timeout'
module MC
class CloudkickHandler < Chef::Handler
CHECK_NAME = 'chef-clientRun'
TIMEOUT = 10
@mleinart
mleinart / loadclass.py
Created August 19, 2011 16:02
Sanely load a class from a classloader in python
def loadClass(self,className, classLoader):
""" loadClass(className)
Load a class in classLoader and recursively load any dependencies. """
# From what I'm told there's no better way...
try:
classLoader.findClass(className)
except LinkageError:
pass
except ClassNotFoundException:
pass # i dunno.. sometimes findClass throws this but loadClass works
@mleinart
mleinart / rewrite-rules.conf
Created January 9, 2012 21:47
Rewrite statsd metrics to be in a flat heirarchy
[pre]
# I dont like statsd's "buckets"
# separate statsd's wonky and confusing summary counts
^(stats[.])(?!timers[.])(.+?)$ = stats.statsd.\2
# Put all metrics under the 'stats' prefix
^(stats[.])(timers[.])(.+?)$ = \1\3
^(stats_counts[.])(.+?)$ = stats.\2
@mleinart
mleinart / graphite-tiny_data.patch
Created February 14, 2012 23:43
Patch to fix graphite rendering for data with super tiny difference between min and max
--- webapp/graphite/render/glyph.py.orig 2012-02-14 17:40:44.000000000 -0600
+++ webapp/graphite/render/glyph.py 2012-02-14 17:41:11.000000000 -0600
@@ -1352,6 +1352,9 @@
while f <= end:
yield f
f += step
+ if f == start:
+ yield end
+ return
@mleinart
mleinart / asPercent-0.9.9.patch
Created February 28, 2012 16:08
asPercent patch for graphite 0.9.9
=== modified file 'webapp/graphite/render/functions.py'
--- webapp/graphite/render/functions.py 2011-10-04 21:06:09 +0000
+++ webapp/graphite/render/functions.py 2012-02-28 16:05:35 +0000
@@ -225,44 +225,49 @@
series[i] = value
return seriesList
-def asPercent(requestContext, seriesList1, seriesList2orNumber):
+def asPercent(requestContext, seriesList, total=None):
"""
@mleinart
mleinart / whisper-resize-filtered.py
Created April 19, 2012 18:34
Whisper-resize with a filter option
#!/usr/bin/env python
import sys, os, time, traceback
import whisper
from optparse import OptionParser
now = int(time.time())
option_parser = OptionParser(
usage='''%prog path timePerPoint:timeToStore [timePerPoint:timeToStore]*
@mleinart
mleinart / carbon_link_pool_example.py
Created April 19, 2012 21:16
Example test usage of CarbonLinkPool
@mleinart
mleinart / derived-value-migrate.py
Created April 20, 2012 15:13
Modify data in existing whisper files to be derived from existing counter values
#!/usr/bin/env python
import sys, time, whisper, shutil
from optparse import OptionParser
now = int( time.time() )
option_parser = OptionParser(
usage='''%prog path from''')
@mleinart
mleinart / gist:2559530
Created April 30, 2012 15:58
Sample metadata in graphite SVG
<script>
<![CDATA[
metadata = {
"area": {
"xmin": 39.195507812499997,
"ymin": 33.96875,
"ymax": 623.794921875,
"xmax": 1122
},
"series": [