Skip to content

Instantly share code, notes, and snippets.

Avatar
🐞

Ben Lopatin bennylope

🐞
View GitHub Profile
@bennylope
bennylope / djcasing.py
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.
View djcasing.py
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
else
# Download and extract libmemcached into target vendor directory.
curl -s -L -o tmp-libmemcached.tar.gz $VENDORED_MEMCACHED
View 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 Apr 6, 2015
Insertion shell script for prepending text to a file
View prepend.sh
#!/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 Aug 31, 2015
A script to chain Heroku commands for deploying Django projects
View heroku.sh
STAGINGAPP=staging-app-name
PRODUCTIONAPP=production-app-name
case "$1" in
staging)
APPNAME=$STAGINGAPP
;;
production)
APPNAME=$PRODUCTIONAPP
;;
@bennylope
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
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.
#
View in-browser-tests.py
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
Quick example of creating a recolorized (one-color) image
View gaussian_replacement.py
# 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 Oct 11, 2015
Example #1: TODO program from Gabriel Gonzalez's Basic Haskell Examples
View todo.hs
-- 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)