Skip to content

Instantly share code, notes, and snippets.

View smerritt's full-sized avatar

Sam Merritt smerritt

View GitHub Profile
#!/usr/bin/env python
#
# Parse the output of lnstat(8) into something perhaps slightly
# human-readable.
#
# Can take input from a file or on stdin.
import sys
lnstat_output = open(sys.argv[1]) if len(sys.argv) >= 2 else sys.stdin
# Recursive expansion attack (aka "billion laughs") on a YAML parser
#
# See http://en.wikipedia.org/wiki/Billion_laughs
#
# Want to quadruple the result size? Just add another section.
---
s1: &s1
a:
- 1
- 2
@smerritt
smerritt / _etc_apache2_conf.d_swift_wsgi.conf
Created March 6, 2013 20:33
SAIO configs with apache stuff
# Proxy
NameVirtualHost *:8080
Listen 8080
<VirtualHost *:8080>
ServerName proxy-server
LimitRequestBody 5368709122
WSGIDaemonProcess proxy-server processes=5 threads=1
WSGIProcessGroup proxy-server
WSGIScriptAlias / /var/www/swift/proxy-server.wsgi
LimitRequestFields 200
@smerritt
smerritt / gist:5615053
Created May 20, 2013 20:02
OpenStack review stats. Started life as http://173.203.107.207/~soren/stats/stats.py.txt, then I went and hacked it up a bunch to do what I wanted.
#!/usr/bin/python
from collections import defaultdict
import calendar
import datetime
import json
import operator
import optparse
import paramiko
from pprint import pprint
from tabulate import tabulate
#!/usr/bin/env python
# Brute-force MD5 cycle-finder. Good for keeping your laptop warm, but not
# much else.
import hashlib
import random
def h(s):
return hashlib.md5(s).hexdigest()
def get_account_info(app, req, account):
return get_info(app, req, account)
def get_container_info(app, req, account, container):
if not container:
raise ValueError("container must be specified, but was %r" % container)
return get_info(app, req, account, container)
Let's examine how the account and container caching works for a simple
middleware like container_quotas.
Abbreviations used:
s.c.m --> swift.common.middleware
s.c.p.a --> swift.controllers.proxy.account
s.c.p.b --> swift.controllers.proxy.base
s.c.p.c --> swift.controllers.proxy.container
s.c.p.o --> swift.controllers.proxy.object
diff --git a/swift/obj/auditor.py b/swift/obj/auditor.py
index c672928..4ffb98e 100644
--- a/swift/obj/auditor.py
+++ b/swift/obj/auditor.py
@@ -158,7 +158,8 @@ class AuditorWorker(object):
:param partition: the partition the path is on
"""
try:
- assert isinstance(path, basestring)
+ if not path:
@smerritt
smerritt / jsons.py
Created July 23, 2013 23:16
shows differences in JSON decoding between simplejson and stdlib json
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import simplejson
data = {'hello': 'world', u'ok': u'✓',
'nested': {'array': [1, 2, 3, {'potato': 'potato',
'tomato': 'tomato'}],
"that's": 'Numberwäng!'}}
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
#
# Benchmark the relative performance of stdlib's json, simplejson, and a
# wrapped simplejson that gives the same API as stdlib's json.
import benchmark
import hashlib
import json as stdjson
import simplejson