Skip to content

Instantly share code, notes, and snippets.

View johnnadratowski's full-sized avatar

John Nadratowski johnnadratowski

  • Unified Social
  • New York, NY
View GitHub Profile
@johnnadratowski
johnnadratowski / vimdo.sh
Last active July 28, 2017 04:16
vimdo - Terminal apply vim normal command to files in batch. Automatically apply vim commands to multiple files.
#!/bin/sh
# Basically just runs vim commands as ":execute normal", saves the file, and quits for each file in a loop
vimdo() {
local CMD=$1
shift
for f
do
vim -N -u NONE -n -c "set nomore" -c ":execute \"norm! $CMD\"" -cwq! $f
@johnnadratowski
johnnadratowski / gist:9849824
Created March 29, 2014 06:55
Supervisord Program Template
;[program:theprogramname]
;command=/bin/cat ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1 ; number of processes copies to start (def 1)
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask=022 ; umask for process (default None)
;priority=999 ; the relative start priority (default 999)
;autostart=true ; start at supervisord start (default: true)
;autorestart=true ; retstart at unexpected quit (default: true)
;startsecs=10 ; number of secs prog must stay running (def. 1)
@johnnadratowski
johnnadratowski / cross_site_xhr.py
Created November 22, 2013 14:16
Cross-Site XHR Django Middleware
from django import http
from django.conf import settings
ALL_ORIGINS = ['*', ]
ALL_METHODS = ['POST', 'GET', 'OPTIONS', 'PUT', 'DELETE']
ALL_HEADERS = ['Content-Type', '*']
ALLOWED_CREDENTIALS = 'true'
DEFAULT_XS_SHARING = getattr(settings, 'DEFAULT_XS_SHARING', None)
@johnnadratowski
johnnadratowski / response_exception.py
Created November 22, 2013 14:14
Response Exception - Middleware for Django to return responses using exceptions
"""
Contains the middleware class implementation for the ResponseException
"""
class ResponseException(Exception):
def __init__(self, response):
super(Exception, self).__init__()
self.response = response
class ResponseExceptionMiddleware(object):