Skip to content

Instantly share code, notes, and snippets.

View chrisglass's full-sized avatar

Chris Glass chrisglass

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / export_pls.py
Created January 10, 2013 22:04
Copy all files from a .pls to some folder (in /tmp)
#!/usr/bin/python
import os
import urllib
import shutil
lines = []
playlist = "/tmp/Test.pls"
playlist_name = playlist.split("/")[-1]
playlist_name = playlist_name.split(".")[0]
destination_folder = "/tmp/%s" % playlist_name
@chrisglass
chrisglass / playlist-export.py
Created February 8, 2013 07:45
Given a playlist, copy all the music files it contains to a /tmp folder.
#!/usr/bin/python
import os
import urllib
import shutil
lines = []
playlist = "/tmp/Test.pls"
playlist_name = playlist.split("/")[-1]
playlist_name = playlist_name.split(".")[0]
destination_folder = "/tmp/%s" % playlist_name
@chrisglass
chrisglass / random.js
Created March 15, 2013 10:53
Random background color for element using jQuery
$('*').each(function() { $(this).css({background: "#"+((1<<24)*Math.random()|0).toString(16)});});
@chrisglass
chrisglass / spin_up.sh
Created June 7, 2013 09:19
Spin up an LXC container for some version of ubuntu
lxc-create -n <NAME> -t ubuntu -- --release <RELEASE ie. precise, raring...> -b <USERNAME to bind home to in the VM>