This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import re | |
from django import template | |
from django.utils.safestring import mark_safe | |
register = template.Library() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a loop-mounted filesystem to allow a very high inode count | |
# without having to reformat entire partition | |
# Allocate a 1.5TB file without actually having to write 1.5TB of data | |
fallocate -l 1500G /path/to/filesystem.img | |
# Make an ext4 filesystem in this file with: | |
# (-i) One inode per 1024 bytes | |
# (-F) Force creation of the filesystem even though the | |
# file is not a block special device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Extends WhiteNoise so that it always re-checks the mtimes of files before serving | |
(and updates Content-Length headers as well). | |
Possibly useful if you are using WhiteNoise in development and want to modify files | |
without restarting the server. (Note: this won't pick up added/deleted files, you'll | |
still need a restart for that.) | |
Use the Django setting `WHITENOISE_RECHECK_MTIMES` to enable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import json | |
class HashWrapper(object): | |
""" | |
Wraps a hashlib object to make it file-like (i.e. give it a `write` method) | |
""" | |
def __init__(self, hashobj=None): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
cert_file="$1" | |
if [ -z "$cert_file" ]; then | |
echo "Usage: create-startssl-cert-bundle CERTIFICATE_FILE" >&2 | |
echo >&2 | |
echo "Bundles StartSSL's intermediate certs and writes combined certificate to stdout" >&2 | |
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def limit_with_cte(queryset, limit=None): | |
if limit is None: | |
return queryset | |
sql, params = queryset.query.sql_with_params() | |
cte_query = 'WITH cte_table_a4eb61 AS ({}) '\ | |
'SELECT * FROM cte_table_a4eb61 LIMIT {:d}'.format( | |
sql, int(limit)) | |
return queryset.raw(cte_query, params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Work around bug in OpenSSH whereby the "ControlMaster" process that gets | |
# forked off fails to close stderr, causing Python's subprocess to hang forever | |
# waiting for EOF: | |
# https://bugzilla.mindrot.org/show_bug.cgi?id=1988 | |
# Created named pipe to pass stderr through | |
stderr_pipe="$(mktemp -u)" | |
mkfifo "$stderr_pipe" | |
# Keep reading from stderr pipe and writing it to actual stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import json | |
from collections import defaultdict | |
if __name__ == '__main__': | |
data = defaultdict( | |
lambda: defaultdict( | |
lambda: defaultdict( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Queue import Queue | |
import sys | |
from threading import Thread | |
END_OF_STREAM = object() | |
class QueueWithException(Queue): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make a quick 30-second gif screencast | |
alias gifcast='byzanz-record -v -c -d 30 --delay 5 screencast.gif' |