Skip to content

Instantly share code, notes, and snippets.

View chrisglass's full-sized avatar

Chris Glass chrisglass

View GitHub Profile
@chrisglass
chrisglass / ceph_stats.py
Last active December 10, 2015 22:49
Display full Ceph ring usage statistics using the python API
#!/usr/bin/python
# This requires rados.py to be at least as recent as
# https://raw.github.com/chrisglass/ceph/expose_cluster_stats_to_python/src/pybind/rados.py
import rados
stats = {}
with rados.Rados(conffile='/etc/ceph/ceph.conf') as cluster:
stats = cluster.get_cluster_stats()
print stats
@chrisglass
chrisglass / run_revel_on_heroku.sh
Created December 4, 2012 21:38 — forked from tmc/run_revel_on_heroku.sh
run revel apps on heroku
☭ ~ $ revel new src/sweet_app
☭ ~ $ cd src/sweet_app/
☭ ~/sweet_app $ git init
☭ ~/sweet_app (master)$ cat > .godir
sweet_app
^C
☭ ~/sweet_app (master)$ git add .godir *
☭ ~/sweet_app (master)$ git ci -m"Initial"
☭ ~/sweet_app (master)$ heroku create --buildpack https://github.com/traviscline/heroku-buildpack-go-revel.git
☭ ~/sweet_app (master)$ git push heroku master
@chrisglass
chrisglass / tree.md
Created April 24, 2012 07:18 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@chrisglass
chrisglass / gist:1063056
Created July 4, 2011 08:21 — forked from atamurad/gist:1062584
mutex with redis
def acquire(name):
tries = 0
while True:
tries += 1
if tries >= 30:
raise Exception("Couldn't acquire lock on mutex "+name)
try:
n = r.incr("lock-"+name)
if n == 1:
return True
@chrisglass
chrisglass / certificate.txt
Created June 15, 2011 08:34
Generate a self-signed SSL certificate for use with Nginx
# generate super secret private key
# (not really, this key and the certificate are "throwaway" items)
openssl genrsa -des3 -out ssl.key 1024
# generate the self-signed certificate
openssl req -new -x509 -nodes -sha1 -days 365 -key ssl.key -out ssl.crt
# create decrypted version of key so that nginx can be started without a passphrase
openssl rsa -in ssl.key -out ssl.key.insecure
chmod 600 ssl.key.insecure
@chrisglass
chrisglass / wisdom.txt
Created May 26, 2011 14:31
Engineering Wisdom
1. Knowledge is Power.
2. Time is Money.
As every engineer knows:
Power = Work / Time
Since:
Knowledge = Power
Time = Money
@chrisglass
chrisglass / django-shop-polymorphic.txt
Created April 20, 2011 18:01
django-polymorphic discussion log of IRC
<ionelmc> single currency, mail shiping for start - however there's need for some various discounting schemes for products and some fancy category scheme i think
<ionelmc> so the Product.get_specific implementation is going to be replaced by djnago-polymorphic ?
<Tribaal> ionelmc, I'll keep the polymorphic branhc around, I think it's really elegan
<Tribaal> so I'll test more before I make a decision
<ionelmc> if i need to manage stock i have to build my own models for that right?
<Tribaal> but generally I thin kit's the right way to go, yeah
<Tribaal> ionelmc, yes, for the time being
<Tribaal> for stock I think there should be a new type of plugin almost (like a transaction plugin)
<Tribaal> it would be useful for vouchers too, for instance
<Tribaal> for the time being the stock needs to be handled in your own models, however
@chrisglass
chrisglass / inspect_urls.py
Created February 13, 2011 16:42
Creates a flat list of all your url resolvers in Django
from django.core.urlresolvers import get_resolver
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
def _recurse_resolver(resolver, prefix=[]):
patterns = []
for obj in resolver.url_patterns:
if isinstance(obj, RegexURLPattern):
patterns.append(prefix + [obj.regex.pattern])
elif isinstance(obj, RegexURLResolver):
@chrisglass
chrisglass / install_django_cms.sh
Created January 12, 2011 18:18
This will install a "naked" version of Django-CMS to use as a demonstration.
#!/bin/bash
# This should be run on a relatvely modern version of Ubuntu (9.10 or later,
# without any sort of confidence)
PROJECT_NAME=$1
if [ x$PROJECT_NAME = "x" ] ; then
# No project name!
echo "Usage: $0 <project name>"
exit 1
@chrisglass
chrisglass / autodiscover_local_memcaches
Created December 21, 2010 08:49
This makes Django settings autodiscover local memcaches! :)
import os
import socket
class IP(object):
def __init__(self):
self.base = None
def get(self, end):
if not self.base: