Skip to content

Instantly share code, notes, and snippets.

@agriffis
agriffis / keybase.md
Created October 29, 2016 00:48
keybase.md

Keybase proof

I hereby claim:

  • I am agriffis on github.
  • I am agriffis (https://keybase.io/agriffis) on keybase.
  • I have a public key ASAG-vNw34R-v-jUZ7WrUrAU7E0UD16csjTPJMRQegh-sgo

To claim this, I am signing this object:

@agriffis
agriffis / gist:8240913
Last active January 2, 2016 02:59
Chrome vs. Firefox
from django.core.cache import get_cache
class KeyedCache(object):
"""
Proxied cache object to allow objects to implement their own keying,
for example a Django model can implement per-row caching with:
def cache_key(self, key):
return '{}.{}.{}'.format(self.__class__.__name__, self.pk, key)
@agriffis
agriffis / wait_for_it.bash
Last active December 16, 2015 14:59
wait_for_it.bash 30m deploy
#!/bin/bash
sleep_for=$1
shift
(
"$@"
status=$?
if [[ $status == 0 ]]; then
@agriffis
agriffis / stdout.py
Created April 22, 2013 21:07
Patch Python's sys.stdout and sys.stderr to honor locale variables regardless of tty, and fall back to UTF-8 instead of ASCII in the absence of more information.
"""
Patch Python's sys.stdout and sys.stderr to encode to UTF-8
The short story is that sys.stdout.encoding is set based on the environment
variable LC_CTYPE (or LANG/LC_ALL) but only when stdout.isatty().
Otherwise those variables are ignored and stdout has no encoding, and it
CANNOT be set.
The long story is here (especially in the comments):
http://drj11.wordpress.com/2007/05/14/python-how-is-sysstdoutencoding-chosen/
#!/bin/bash
#
# gpgsig, a little script to sign your gpg/pgp keys
#
# Copyright 2006,2013 Aron Griffis <agriffis@n01se net>
# Released under the GNU GPL v2
#
# Based loosely on ideas Damien Chrisment's gpgsig, but written from scratch to
# be simpler and just do what I need. Simply:
#
@agriffis
agriffis / urls.py
Created February 28, 2013 13:41
Force django admin to SSL
def walk_url_tree(urls):
"""
Generator to walk a tree consisting of RegexURLPattern (with callback)
and RegexURLResolver (with nested url_patterns).
"""
for u in urls:
if hasattr(u, 'url_patterns'):
for u2 in walk_url_tree(u.url_patterns):
yield u2
else:
@agriffis
agriffis / walk_url_tree.py
Last active December 14, 2015 07:59
URL tree walkers, recursive and non-recursive.
def walk_url_tree(urls):
"""
Generator to walk a tree consisting of RegexURLPattern (with callback)
and RegexURLResolver (with nested url_patterns).
Recursive depth-first.
"""
for u in urls:
if hasattr(u, 'url_patterns'):
for u2 in walk_url_tree(u.url_patterns):
@agriffis
agriffis / xorg.conf
Created April 1, 2012 20:25
sitdown (or standup) with nvidia proprietary driver
#!/bin/bash
if glxinfo | grep -q 'NVIDIA Corporation'; then
case /$0 in
*/sitdown) xrandr -s 1 ;;
*/standup) xrandr -s 0 ;;
esac
else
hdmi=HDMI-1
dvi=DVI-D-1
@agriffis
agriffis / gist:2206093
Created March 26, 2012 15:48
sitdown (or standup)
#!/bin/bash
hdmi=HDMI-1
dvi=DVI-D-1
case /$0 in
*/sitdown) xrandr --output $hdmi --auto ; xrandr --output $dvi --off ;;
*/standup) xrandr --output $dvi --auto ; xrandr --output $hdmi --off ;;
esac