Skip to content

Instantly share code, notes, and snippets.


Ben Lopatin bennylope

View GitHub Profile
bennylope /
Created Apr 16, 2014
Apply the `case_insenstive` Django view decorator if you have URLs which should match regardless of case, but you don't want those URLs hanging out there when a user visits.
import string
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
def case_insensitive(func, case='lower', code=301):
Django view function decorator which can enforce the case of a URL path by
redirecting to the properly cased URL. This *allows* for case insensitive
matches while ensuring that only a commonly cased-URL is used and seen.
View pylibmc.bash
# If pylibmc exists within requirements, use vendored libmemcached.
if (grep -Eiq "\s*pylibmc" requirements.txt) then
echo "-----> Noticed pylibmc. Bootstrapping libmemcached."
cd .heroku
if [ -d "vendor/lib/sasl2" ]; then
export LIBMEMCACHED=$(pwd)/vendor
# Download and extract libmemcached into target vendor directory.
curl -s -L -o tmp-libmemcached.tar.gz $VENDORED_MEMCACHED

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url =

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

bennylope /
Created Apr 6, 2015
Insertion shell script for prepending text to a file
#!/usr/bin/env sh
# Prepend the text from file in argument $1 to file in argument $2
# Usage, inserting license front matter into all Python files in a directory,
# including subdirectories:
# find . -name "*.py" -print0 | xargs -0 -n 1 ./ frontmatter.txt
bennylope /
Last active Aug 31, 2015
A script to chain Heroku commands for deploying Django projects
case "$1" in
bennylope / blogspot_to_jekyll.rb
Created Oct 5, 2011 — forked from kennym/blogspot_to_jekyll.rb
Migrate your blogger blog posts to jekyll.
View blogspot_to_jekyll.rb
#!/usr/bin/env ruby
# Convert blogger (blogspot) posts to jekyll posts
# Basic Usage
# -----------
# ./blogger_to_jekyll.rb feed_url
# where `feed_url` can have the following format:
bennylope / pagination.rb
Created Oct 18, 2011
Jekyll pagination, pageN pages into /blog/ directory
View pagination.rb
module Jekyll
class Pagination < Generator
# This generator is safe from arbitrary code execution.
safe true
# Generate paginated pages if necessary.
# site - The Site.
from django.test import LiveServerTestCase
from import By
from selenium.webdriver.firefox.webdriver import WebDriver
class MySeleniumTests(LiveServerTestCase):
def setUpClass(cls):
bennylope /
Created May 18, 2012
Quick example of creating a recolorized (one-color) image
# Replacement for ImageFilter.GaussianBlur which always sets the
# blur radius to the default of 2.
# Code from
import ImageFilter
class MyGaussianBlur(ImageFilter.Filter):
name = "GaussianBlur"
bennylope / todo.hs
Created Oct 11, 2015
Example #1: TODO program from Gabriel Gonzalez's Basic Haskell Examples
View todo.hs
-- From
putTodo :: (Int, String) -> IO ()
putTodo (n, todo) = putStrLn (show n ++ ": " ++ todo)
prompt :: [String] -> IO ()
prompt todos = do
putStrLn ""
putStrLn "Current TODO list:"
mapM_ putTodo (zip [0..] todos)