Skip to content

Instantly share code, notes, and snippets.

View andrewschoen's full-sized avatar

Andrew Schoen andrewschoen

View GitHub Profile
@andrewschoen
andrewschoen / S3 bucket sync
Created February 3, 2012 21:22
Python script to sync an S3 bucket to the local file system
# -*- coding: utf-8 -*-
import os
import StringIO
import hashlib
try:
from boto.s3.connection import S3Connection
from boto.s3.key import Key
except ImportError:
raise ImproperlyConfigured, "Could not load Boto's S3 bindings."
@andrewschoen
andrewschoen / upgrade_postgres_9.0-9.1.sh
Created February 14, 2012 21:00 — forked from databyte/upgrade_postgres_9.0-9.1.sh
Upgrade PostgreSQL from 9.0 to 9.1
#!/bin/sh
#
# Upgrade PostgreSQL from 9.0 to 9.1
#
# by David Sommers
#
brew update postgres
@andrewschoen
andrewschoen / hack.sh
Created March 31, 2012 14:35 — 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
#
@andrewschoen
andrewschoen / osx_geodjango_deps.sh
Created April 3, 2012 15:34 — forked from estebistec/osx_geodjango_deps.sh
GeoDjango dependencies on OSX
# The GeoDjango installation page [1] makes the OSX setup seem kind of gnarly. homebrew has
# come a long way and can do a lot of the heavy lifting of building libs needed by GeoDjango.
# When I get some time I'll submit a patch to that page on the Django site with this info...
# [1] https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#macosx
# Freshen homebrew
brew update
brew upgrade
# The main stuff we need
@andrewschoen
andrewschoen / django-cms-requirements.txt
Created April 19, 2012 21:43
django-cms project requirements.txt
PIL==1.1.7
django==1.3
django-filer==0.8.2
easy-thumbnails==1.0-alpha-15
cmsplugin-filer==0.8.0
django-cms==2.2
django-reversion==1.4
django-debug-toolbar==0.8.4
django-tinymce==1.5.1a1
http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download
@andrewschoen
andrewschoen / future_value.py
Created May 3, 2012 18:18
Future value calculation with a increasing amount of contribution annually, up to X amount.
import numpy as np
import locale
locale.setlocale(locale.LC_ALL, '')
def sliding_payment_fv(start_pmt=100, annual_pmt_increase=100, max_pmt=300,
years=10, interest_rate=0.05, present_value=100):
future_value = 0
pmt = start_pmt
for year in range(years):
@andrewschoen
andrewschoen / custom_nav_tags.py
Created May 11, 2012 14:54
template tag for django-cms menus that roots at a given menu level
from menus.menu_pool import menu_pool
from django import template
from menus.templatetags.menu_tags import cut_after
register = template.Library()
@register.inclusion_tag('cms/dummy.html', takes_context=True)
def show_rooted_sub_menu(context, levels=100, root_level=0, template="menu/sub_menu.html"):
"""
show the sub menu of the current nav-node.
@andrewschoen
andrewschoen / middleware.py
Created May 14, 2012 14:10
Django middleware to create a 'page header' in django-cms navigation.
from django import http
class NotAPageMiddleware(object):
"""
This middleware checks to see if the cms page is assigned to a specific template
and if so will redirect to the next published child page. Needs to be after the
cms page middleware.
"""
def process_response(self, request, response):
in_admin = request.path.split('/')[1] == "admin"
@andrewschoen
andrewschoen / gist:3144320
Created July 19, 2012 14:29
Postgres Backup & Restore
Backup: $ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}
Restore: $ psql -U {user-name} -d {desintation_db} -f {dumpfilename.sql}
# makes sure the DDT never turns on
def custom_show_toolbar(request):
return False