Skip to content

Instantly share code, notes, and snippets.

@bennylope
bennylope / djcasing.py
Created April 16, 2014 00:12
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.
# 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
else
# Download and extract libmemcached into target vendor directory.
curl -s -L -o tmp-libmemcached.tar.gz $VENDORED_MEMCACHED
@bennylope
bennylope / pr.md
Last active August 29, 2015 14:14 — forked from piscisaureus/pr.md

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 = git@github.com:joyent/node.git

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
bennylope / prepend.sh
Created April 6, 2015 22:34
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 ./prepend.sh frontmatter.txt
@bennylope
bennylope / heroku.sh
Last active August 31, 2015 14:01
A script to chain Heroku commands for deploying Django projects
STAGINGAPP=staging-app-name
PRODUCTIONAPP=production-app-name
case "$1" in
staging)
APPNAME=$STAGINGAPP
;;
production)
APPNAME=$PRODUCTIONAPP
;;
@bennylope
bennylope / blogspot_to_jekyll.rb
Created October 5, 2011 15:23 — forked from kennym/blogspot_to_jekyll.rb
Migrate your blogger blog posts to jekyll.
#!/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
bennylope / pagination.rb
Created October 18, 2011 00:33
Jekyll pagination, pageN pages into /blog/ directory
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 selenium.webdriver.common.by import By
from selenium.webdriver.firefox.webdriver import WebDriver
class MySeleniumTests(LiveServerTestCase):
@classmethod
def setUpClass(cls):
@bennylope
bennylope / gaussian_replacement.py
Created May 18, 2012 20:58
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 http://aaronfay.ca/content/post/python-pil-and-gaussian-blur/
import ImageFilter
class MyGaussianBlur(ImageFilter.Filter):
name = "GaussianBlur"
@bennylope
bennylope / todo.hs
Created October 11, 2015 15:57
Example #1: TODO program from Gabriel Gonzalez's Basic Haskell Examples
-- From http://www.haskellforall.com/2015/10/basic-haskell-examples.html
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)