Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Simple SSL forwarder designed for working with HTTPS in development
# With no arguments, it will create a self-signed certificate for
# localhost and forward SSL traffic on port 8443 to port 8000
set -e
which openssl > /dev/null || (
echo "openssl not installed, try: sudo apt-get install openssl"
exit 1
)
which stunnel4 > /dev/null || (
# Get installed packages
gzip -dc /var/log/installer/initial-status.gz | \
sed -n 's/^Package: //p' | sort | \
comm -13 - <(apt-mark showmanual | sort)
# Get the directory of the current script
script_dir="$( unset CDPATH && cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#!/usr/bin/python
"""
Build a local index of all the packages which pip has previously downloaded and
cached so you can install any of them without requiring network access.
Might be useful for creating new Virtualenvs while developing on a plane.
Usage:
* Set the environment var PIP_DOWNLOAD_CACHE (e.g., in your `.profile`)

Keybase proof

I hereby claim:

  • I am evansd on github.
  • I am evansd (https://keybase.io/evansd) on keybase.
  • I have a public key whose fingerprint is 9080 1864 3ACF D646 EF1E BBB1 6284 0EA7 FA7D 6680

To claim this, I am signing this object:

@evansd
evansd / django-csrf.js
Last active August 29, 2015 13:59
Adds support for Django's CSRF protection to jQuery's ajax method
// Adds support for Django's CSRF protection to jQuery's ajax method
(function() {
var cookieRegex = new RegExp('(?:^|;)\\s?' + 'csrftoken' + '=(.*?)(?:;|$)', 'i'),
match = document.cookie.match(cookieRegex),
csrftoken = match && decodeURIComponent(match[1]),
isSafeMethod = function(method) {
return /^(GET|HEAD|OPTIONS|TRACE)$/.test(method);
};
if (csrftoken) {
jQuery(document).ajaxSend(function(event, jqxhr, settings) {
@evansd
evansd / bootstrap-popover-clicktoclose.js
Last active August 29, 2015 13:59
Adds a 'clicktoclose' option to Bootstrap's popovers which will cause them to close if the user clicks anywhere outside of the popover
// Adds a 'clicktoclose' option to Bootstrap's popovers which will cause them
// to close if the user clicks anywhere outside of the popover
(function() {
var closeOnExternalClick = function(e) {
if ( ! this.$tip.has(e.target).length) { this.hide(); }
};
var Popover = $.fn.popover.Constructor.prototype;
var superInit = Popover.init;
Popover.init = function() {
superInit.apply(this, arguments);
@evansd
evansd / json.py
Last active August 29, 2015 14:01
from __future__ import absolute_import
import json
import re
from django import template
from django.utils.html import format_html_join
register = template.Library()
#!/usr/bin/env bash
# Installs the requested version of node on Heroku
# Example: source install_node_on_heroku '0.10.15'
# For use as part of a post_compile step
set -eo pipefail
# Pretty printing functions
[ $(uname) == "Darwin" ] && SED_FLAG='-l' || SED_FLAG='-u'
#!/usr/bin/env python
import fileinput, re
for line in fileinput.input(inplace=True):
if fileinput.isfirstline():
future_load = '{% load url from future %}'
if '{% extends' in line:
print line,
print future_load
else:
print future_load