Skip to content

Instantly share code, notes, and snippets.

@zgohr
zgohr / admin.py
Last active April 17, 2019 10:01
Remove Tastypie from Django admin
from django.contrib import admin
from tastypie.models import ApiKey, ApiAccess
admin.site.unregister(ApiKey)
admin.site.unregister(ApiAccess)
@zgohr
zgohr / post-checkout.sh
Created January 17, 2013 17:45
Post-checkout git hook to auto-add a commit when new branch is created from ```develop```. Useful because ```reflog``` doesn't stay around forever, and we don't want to hold onto defunct feature branches until we are able to run reports. There is an existing flaw in this code, can you spot it?
#! /bin/sh
from_hash=$1
to_hash=$2
checkout_type=$3
ignored=("develop" "staging" "production")
develop_hash=$(git rev-parse develop)
branch_name=$(git rev-parse --abbrev-ref HEAD)
containsElement () {
@zgohr
zgohr / directives.js
Created January 26, 2013 00:22
Focus, blur, keyup, keydown, and keypress AngularJS directive
.directive( [ 'focus', 'blur', 'keyup', 'keydown', 'keypress' ].reduce( function ( container, name ) {
var directiveName = 'ng' + name[ 0 ].toUpperCase( ) + name.substr( 1 );
container[ directiveName ] = [ '$parse', function ( $parse ) {
return function ( scope, element, attr ) {
var fn = $parse( attr[ directiveName ] );
element.bind( name, function ( event ) {
scope.$apply( function ( ) {
fn( scope, {
$event : event
@zgohr
zgohr / gist:4988556
Created February 19, 2013 18:31
Javascript recursion (recursive function) with promises
var getAll = function(url, page, acquired, deferred) {
var self = this;
page = page || 1;
deferred = deferred || $q.defer();
var page_url = [url, '&page=', page].join("");
$http.get(page_url).then(function(results) {
acquired = acquired ? acquired.concat(results.data) : results.data;
if (results.data.length === 100) { // Assuming the max is 100 per page...
return self.getAll(url, ++page, acquired, deferred);
} else {
@zgohr
zgohr / pre-commit
Created March 13, 2013 22:50
Pre commit hook to grep through modified files for forbidden words and reject if found. A better hook would grunt your repo with things like jshint and follow a set of static analysis project standards.
#!/bin/bash
# Grep through modified files for forbidden words and reject commit if found
FILE_PATTERN='\.(js)(\..+)?$' # Separate more file types with pipes here
FORBIDDEN=( debugger ) # Separate more forbidden strings with spaces here
for i in "${FORBIDDEN[@]}"
do
git diff --cached --name-only | \
@zgohr
zgohr / kill_docker.sh
Created May 24, 2013 16:12
Remove all non-running docker containers
docker ps -a -q | xargs -L1 docker rm -v
@zgohr
zgohr / Dockerfile
Last active December 17, 2015 17:29
MongoDB/Strider Dockerfile
#
# docker run $USER/strider strider addUser
# -e SERVER_NAME=
# -e DB_URI=
# -e GITHUB_APP_ID=
# -e GITHUB_APP_SECRET=
# -e SMTP_HOST=
# -e SMTP_PORT=
# -e SMTP_USER=
@zgohr
zgohr / supervisord.conf
Created May 26, 2013 16:59
Supervisor/Strider conf
[supervisord]
nodaemon=true
[program:mongodb]
user=mongodb
command=mongod -f /etc/mongodb.conf
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
autorestart=true
@zgohr
zgohr / pillow.md
Created August 28, 2013 15:50
OSX python pillow with jpeg support

pip install --upgrade --no-install pillow

This downloads and unpacks the library.

vim /my/venv/build/pillow/setup.py

Change JPEG_ROOT = None to JPEG_ROOT = libinclude("/Users/zach.gohr/Developer/Cellar/jpeg/8d") or wherever your libjpeg exists (I installed using brew install libjpeg and found via find / -name 'libjpeg'

If the libinclude function does not exist (exists in the case of PIL, not pillow) paste this into setup.py as well:

@zgohr
zgohr / GenerateEditLinks.gs
Created October 29, 2013 19:23
Google Apps script for adding a menu and action to a Google Spreadsheet attached to a Google Form. When used will generate edit links in the first empty column. Provides for a nice GUI for editing form values, especially helpful for forms with drop down selections where editing in the spreadsheet itself is unsatisfactory.