Skip to content

Instantly share code, notes, and snippets.

View pipermerriam's full-sized avatar

Piper Merriam pipermerriam

  • Ethereum Foundation
  • Boulder Colorado
View GitHub Profile
$ brew install macvim
==> Downloading https://github.com/b4winckler/macvim/tarball/snapshot-63
File already downloaded in /Users/jillkatzenberger/Library/Caches/Homebrew
==> ./configure --with-features=huge --with-tlib=ncurses --enable-multibyte --with-macarchs=x86_
==> make
Starting make in the src directory.
If there are problems, cd to the src directory and run make there
cd src && make first
mkdir objects
CC="gcc -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X_UNIX -no-cpp-precomp -I/System/Library/Frameworks/Tcl.framework/Headers -D_REENTRANT=1 -D_THREAD_SAFE=1 -D_DARWIN_C_SOURCE=1 " srcdir=. sh ./osdef.sh
class Listing(...):
def upgrade(self):
return self.__class__.objects.select_subclasses().get(pk=self.pk)
listing = Listing.objects.get(pk=1)
buyerlisting = listing.upgrade()
# Using postgis 2.0.1
# Table creation sql
BEGIN;
CREATE TABLE "locations_location" (
"id" serial NOT NULL PRIMARY KEY,
"name" varchar(255) NOT NULL,
"location" GEOMETRY(POINT, 4326)
)
;
@pipermerriam
pipermerriam / mixins.py
Created November 7, 2012 16:07 — forked from vdboor/mixins.py
Django view initialization ordering issues
class BaseViewMixin(object):
def dispatch(self, request, *args, **kwargs):
# Set earlier to ensure that other class methods which expect
# these values to be present can be called in `init`
self.request = request
self.args = args
self.kwargs = kwargs
# Run the complete request, returning a response, but allowing
# `init` to either raise exceptions, or hijack the response if
from django.utils.http import is_safe_url
from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe
class WithNextUrlMixin(object):
"""
This view will use whatever value was submitted as `next` as the success
url, as long as the url resolves correctly.
"""

Pattern for email sending.

  • Easy to grep project for where emails get sent.
  • Easy to send the same email from multiple places.
  • Constructs urls in a reliable way such that you don't get ssl errors for missing www.
@pipermerriam
pipermerriam / fields.py
Created February 6, 2013 15:54
Various django objects and helpers.
class ClearableFileInput(widgets.ClearableFileInput):
"""
Changes the default file widget to be easier to target with CSS
"""
template_with_initial = u'<div class="fileField"><span class="currently">%(initial_text)s:</span> %(initial)s %(clear_template)s<span class="change">%(input_text)s:</span> %(input)s</div>'
template_with_clear = u'<div class="clear">%(clear)s <label for="%(clear_checkbox_id)s">%(clear_checkbox_label)s</label></div>'
initial_template = u'<a href="{{url}}">{{name}}</a>'
def render(self, name, value, attrs=None):
@pipermerriam
pipermerriam / pycon.py
Created March 13, 2013 02:55
Wanted to scrape some data about the pycon talks I was interested in.
import requests
import csv
from dateutil import parser
from BeautifulSoup import BeautifulSoup
CACHE = {}
"""
https://us.pycon.org/2013/schedule/presentation/35/
https://us.pycon.org/2013/schedule/presentation/68/
@pipermerriam
pipermerriam / emails.py
Created June 12, 2013 17:17
An example of sending a password reset email in django as a class-based email.
from urlparse import urljoin
from django.contrib.auth.tokens import default_token_generator
from django.utils.http import int_to_base36
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from emailtools import MarkdownEmail
@pipermerriam
pipermerriam / tasks.py
Last active January 1, 2016 08:29
celery chaining issue
@celery.task
def first():
# generates an iterable
return 1, 2, 3
@celery.task
def second(thing):
"""
Takes a single item from the iterable from `first`, does some computation,