Skip to content

Instantly share code, notes, and snippets.

@mgaitan
mgaitan / hostname_middleware.py
Last active April 16, 2017 17:17 — forked from pmclanahan/hostname_middleware.py
Django middleware for enforcing a hostname. Using at epio until they provide options for redirects at the loadbalancers.
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
from django.utils import six
def enforce_hostname(get_response):
"""
Enforce the hostname per the ENFORCE_HOSTNAME setting in the project's settings
The ENFORCE_HOSTNAME can either be a single host or a list of acceptable hosts
"""
@mgaitan
mgaitan / post-checkout.py
Created March 3, 2016 12:42 — forked from inklesspen/post-checkout.py
Post-checkout hook to detect alembic issues when switching branches.
#!/usr/bin/env python
"""
Provide useful alembic information after switching branches.
"""
import argparse
import subprocess
import os
import os.path
import py.path
#!/usr/bin/env python
"""
no more embarrasing "removed pdb, sorry" commits
install
-------
save it as .git/hooks/pre-commit giving +x permission
"""
@mgaitan
mgaitan / sse.py
Last active December 19, 2015 04:18
See http://stackoverflow.com/a/13429719 for an explanation on why uses StreamingHttpResponse
# python (django) side:
from django.http import StreamingHttpResponse
import time
def stream(request):
def event_stream():
while True:
time.sleep(3)
yield 'data: %s\n\n' % 'hola mundo'
@mgaitan
mgaitan / pre-commit.py
Created November 2, 2012 19:02 — forked from nqnwebs/pre-commit.py
pep8 and pyflake as git hook
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Script to run pep8 and pyflakes via git's pre-commit hook
Based on https://github.com/lbolla/dotfiles/blob/master/githooks/pre-commit
Modified by Martin Gaitán <mgaitan@machinalis.com> for Machinalis (www.machinalis.com)
Install: