Skip to content

Instantly share code, notes, and snippets.

@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/
@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
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 / gist:8240913
Last active January 2, 2016 02:59
Chrome vs. Firefox
@agriffis
agriffis / gist:9798319
Created March 27, 2014 01:51
Test script for signal handling in heroku-buildpack-pgbouncer
#!/bin/bash
psmgr=/tmp/waiting-fifo
rm -f $psmgr
mkfifo $psmgr
pids=( $$ )
(
echo one-start
@agriffis
agriffis / lazy_collection.py
Last active August 29, 2015 14:20
LazyCollectionMixin
class LazyCollectionMixin(object):
__len__ = new_method_proxy(len)
__contains__ = new_method_proxy(operator.contains)
def __iter__(self):
# Don't define this as
# __iter__ = new_method_proxy(iter)
# because that creates a method which doesn't call yield,
# so it executes setup immediately.
if self._wrapped is empty:
@agriffis
agriffis / gist:bae5c8c86e57cd3bf070
Created July 18, 2015 15:33
verify_weebly_install_params
import hashlib
import hmac
def verify_weebly_install_params(params, secret):
"""
Verifies the hmac of params on the Weebly install URL.
"""
# https://dev.weebly.com/oauth2.html
@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 / bread.md
Last active December 18, 2016 22:16
bread recipe

Wheat Bread

  • 1 package (1/4 oz) active dry yeast
  • 2¼ cups warm water (115°F)
  • 2 Tbsp sugar
  • 1 Tbsp salt
  • 2 Tbsp safflower oil
  • 2½ cups bread flour
  • 2½-3 cups whole wheat flour
@agriffis
agriffis / settings.py
Last active February 4, 2017 22:06
envbash/bienvenue example
from bienvenue import make_env_reader
from envbash import load_envbash
# Where are we?
DREAMHOST = 'dreamhost' in open('/etc/resolv.conf').read()
DEVELOPMENT = not DREAMHOST
# Load env.bash
if DREAMHOST:
load_envbash(os.path.expanduser('~/env.bash'))