Skip to content

Instantly share code, notes, and snippets.

View AndrewIngram's full-sized avatar
🦊
Being foxy

Andy Ingram AndrewIngram

🦊
Being foxy
View GitHub Profile
from distutils.core import setup
import os
# Compile the list of packages available, because distutils doesn't have
# an easy way to do this.
packages, data_files = [], []
root_dir = os.path.dirname(__file__)
if root_dir:
os.chdir(root_dir)
@AndrewIngram
AndrewIngram / Make Python Behave Good on OSX
Created June 24, 2011 14:32
How to get Python working properly on a Mac
1. Install Xcode 4
2. Install homebrew.
3. brew install python --framework
4. brew install libjpeg (for PIL)
5. sudo unlink /System/Library/Frameworks/Python.framework/Versions/Current
6. sudo ln -s /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/Current /System/Library/Frameworks/Python.framework/Versions/Current
7. nano ~/.bash_profile
8. add: export PATH=/usr/local/share/python:/usr/local/bin:$PATH
9. source ~/.bash_profile (or you can load a new terminal window)
10. easy_install pip
@AndrewIngram
AndrewIngram / gist:1098398
Created July 21, 2011 22:34
Breadcrumb Selection
<!DOCTYPE html>
<html>
<body>
<select class="drilldown">
<option value="">------</option>
<option value="1">Books</option>
<option value="2">Books > Fiction</option>
<option value="3">Books > Fiction > Sci-Fi</option>
<option value="4">Books > Fiction > Fantasy</option>
@AndrewIngram
AndrewIngram / gist:1822479
Created February 14, 2012 02:05
Trying to make it possible to override a Django model
from django.db.models.loading import cache
from django.db.models.base import ModelBase
import sys
def override_model(app_label, model_name):
caller = sys._getframe(1) # Obtain calling frame
module_name = caller.f_globals['__name__']
def decorator(orig_cls):
@AndrewIngram
AndrewIngram / hack.sh
Created April 10, 2012 23:14 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@AndrewIngram
AndrewIngram / gist:2585766
Created May 3, 2012 13:48
Django mobile (not tablet) redirection
import datetime
import re
from django.http import HttpResponseRedirect
import requests
from django.utils import simplejson
reg_b = re.compile(r"android.+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino", re.I|re.M)
reg_v = re.compile(r"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma
@AndrewIngram
AndrewIngram / gist:3061391
Created July 6, 2012 17:11
nanoScroller not behaving
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="nanoscroller.css">
<style>
@AndrewIngram
AndrewIngram / gist:3231297
Created August 1, 2012 22:33
supervisor script
;[program:andrewingram-gunicorn]
;command=/var/www/andrewingram.net/bin/gunicorn_django /var/www/andrewingram.net/src/andrewingram/andrewingram/settings.py
;directory=/var/www/andrewingram.net
;logfile=/var/www/andrewingram.net/log/supervisor.log
;user=deployer
;autostart=true
;autorestart=true
;redirect_stderr=True
[program:andrewingram-uwsgi]
@AndrewIngram
AndrewIngram / gist:3283867
Created August 7, 2012 09:36
nginx config
server {
listen 80;
client_max_body_size 4G;
server_name andrewingram.net localhost 127.0.0.1;
gzip on;
gzip_proxied any;
gzip_types text/plain application/xml application/x-javascript text/javascript text/css;
keepalive_timeout 5;
@AndrewIngram
AndrewIngram / gist:3905739
Created October 17, 2012 14:17
MimeTemplateView
class MimeTemplateView(TemplateView):
@classonlymethod
def as_view(cls, **kwargs):
setattr(cls, 'mimetype', kwargs.pop('mimetype','text/html'))
return super(MimeTemplateView, cls).as_view(**kwargs)
def render_to_response(self, context, **kwargs):
kwargs['mimetype'] = self.mimetype
return super(MimeTemplateView, self).render_to_response(context, **kwargs)