Skip to content

Instantly share code, notes, and snippets.

View mkelley33's full-sized avatar
🎯
Focusing

Michaux Kelley mkelley33

🎯
Focusing
View GitHub Profile
@mkelley33
mkelley33 / grep_and_go_to_line_number
Created November 1, 2010 16:32
A one-two combo for searching in files, and then going to match at a supplied line-number.
grep . -RHn --include="tests.py" -e "MyTestCase"
mvim some_django_app/tests.py +1329
@mkelley33
mkelley33 / bt1.py
Created March 23, 2011 16:08
A partial implementation of transparent redirect for braintree payments
def register_new_account(request):
result = TransactionForm.get_result(request)
if result:
if result.is_success:
result = braintree.TransparentRedirect.confirm(request.META["QUERY_STRING"])
# TODO: store customer info in vault
# TODO: create a subscription
return redirect('cream_thank_you')
elif result.errors:
pass
@mkelley33
mkelley33 / recursivedefaultdict.py
Created March 23, 2011 23:16
create a defaultdict whose values are also defaultdicts, nested arbitrarily deep
from:
http://personalpages.tds.net/~kent37/kk/00013.html
class recursivedefaultdict(defaultdict):
def __init__(self):
self.default_factory = type(self)
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell()
@mkelley33
mkelley33 / django_braintree_almost_working.py
Created March 28, 2011 19:16
An almost working view for django-braintree
# Note: this is just for testing, and doesn't do stuff like set the amount or redirect if successful.
#
# This tidbit was created primarily to troubleshoot why I couldn't submit a form with validation errors
# twice without being redirected to https://sandbox.braintreegateway.com/login
#
# Tested using Python 2.6.6, django 1.2.5, django-braintree 1.5, and braintree 1.8
def make_payment(request):
result = TransactionForm.get_result(request)
form = TransactionForm(result, redirect_url='http://127.0.0.1:8000/make_payment/')
form.generate_tr_data()

SciPy, PyQt and Matplotlib on OS X Snow Leopard

The squeeky-clean way with homebrew and pip/virtualenv.

$ easy_install pip
$ pip install virtualenvwrapper mercurial
$ brew install gfortran && brew install pyqt
# Have a nice long coffee break -- compiling Qt took 67 minutes on my

quad-core i7 MBP, PyQt another 8.

@mkelley33
mkelley33 / settings.py
Created August 20, 2011 19:22 — forked from dfeeney/settings.py
Working django-cms settings with django 1.3 staticfiles
# -*- coding: utf-8 -*-
import os
gettext = lambda s: s
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
@mkelley33
mkelley33 / contact-us-fields.html
Created September 3, 2011 03:31
django 1.3 ajax contact form post using jQuery
<!-- this will be requested and rendered via ajax so we only want the form fields
so we can replace them later using jQuery with the fields PLUS the errors. -->
<div id="form-fields">
{{ form.as_p }}
</div>
#!/usr/bin/env python
from __future__ import with_statement # needed for python 2.5
from fabric.api import *
from fabric.contrib.console import confirm
from fabric.contrib import files
USAGE = """
================================================================
NOTE:
using this fabfile expects that you have the python utility
@mkelley33
mkelley33 / strip_tags.py
Created April 1, 2012 15:00 — forked from braveulysses/strip_tags.py
Strip HTML tags using BeautifulSoup
def strip(untrusted_html):
"""Strips out all tags from untrusted_html, leaving only text.
Converts XML entities to Unicode characters. This is desirable because it
reduces the likelihood that a filter further down the text processing chain
will double-encode the XML entities."""
soup = BeautifulStoneSoup(untrusted_html, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)
safe_html = ''.join(soup.findAll(text=True))
return safe_html