Skip to content

Instantly share code, notes, and snippets.

Avatar

Allan Beaufour beaufour

View GitHub Profile
@beaufour
beaufour / gzipinputstream.py
Created Dec 4, 2012
Python: Streaming Gzip reader
View gzipinputstream.py
import zlib
import string
BLOCK_SIZE = 16384
"""Read block size"""
WINDOW_BUFFER_SIZE = 16 + zlib.MAX_WBITS
"""zlib window buffer size, set to gzip's format"""
@beaufour
beaufour / language.py
Created Nov 30, 2012
Django Middleware to choose language based on subdomain
View language.py
import logging
from django.utils import translation
class SubdomainLanguageMiddleware(object):
"""
Set the language for the site based on the subdomain the request
is being served on. For example, serving on 'fr.domain.com' would
make the language French (fr).
@beaufour
beaufour / ebs_stats.py
Created Feb 16, 2012
Get CloudWatch metrics for Amazon EBS volumes
View ebs_stats.py
#!/usr/bin/python
#
# Get Cloudwatch metrics for the EBS volumes attached to an instance
#
import datetime
import logging
import sys
import urllib
@beaufour
beaufour / elb_cloudwatch.py
Created Feb 15, 2012
Get CloudWatch metrics for an Amazon ELB
View elb_cloudwatch.py
#!/usr/bin/python
#
# Get Cloudwatch metrics for an ELB
#
# Inspired by http://onemoredigit.com/post/3263274796/single-instance-cloudwatch-stats-with-boto
#
import datetime
import sys