Skip to content

Instantly share code, notes, and snippets.

View davesque's full-sized avatar

David Sanders davesque

  • Seattle, WA
View GitHub Profile
@davesque
davesque / vassal.ini
Created January 7, 2013 18:33
Uwsgi ini file for django
[uwsgi]
socket = /tmp/example.com.sock
; Worker processes
master = 1
processes = 4
; Virtualenv and home directory
virtualenv = /var/virtualenvs/example.com
chdir = /var/www/example.com
@davesque
davesque / uwsgi.sh
Created January 7, 2013 18:34
Daemonize uwsgi
#!/bin/bash
#/etc/init.d/uwsgi
daemon=/usr/local/bin/uwsgi
pid=/var/run/uwsgi.pid
args="--master --emperor /etc/vassals/ --uid www-data --daemonize /var/log/uwsgi/uwsgi.log"
case "$1" in
start)
echo "Starting uwsgi"
@davesque
davesque / nginx.conf
Created January 7, 2013 18:35
Basic nginx conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@davesque
davesque / strip_tag.py
Created January 25, 2013 19:38
Django template tag to strip or trim leading and trailing characters.
import ast
from django import template
register = template.Library()
class StripNode(template.Node):
"""
Strips leading and trailing characters in the enclosed content.
@davesque
davesque / rename.py
Last active December 12, 2015 08:59
Adjust file names based on time zone info
#!/usr/bin/env python
from dateutil import parser
from dateutil.tz import gettz
import csv
import os
import sys
FORMAT = '%Y-%m-%d %H.%M.%SZ.pdf'
@davesque
davesque / rename_to_time.py
Created February 12, 2013 03:38
Rename files based on timestamp info
#!/usr/bin/env python
from dateutil import parser
from dateutil.tz import gettz
import csv
import os
import sys
FORMAT = '%Y-%m-%d %H.%M.%SZ.pdf'
@davesque
davesque / se.zsh
Created February 12, 2013 17:08
Grep wrapper
local base_cmd="grep --exclude-dir=CACHE --exclude-dir=ckeditor --binary-files=without-match --colour -Enr"
if [[ $# -eq 1 ]]; then
eval "$base_cmd $1 *"
elif [[ $# -gt 1 ]]; then
eval "$base_cmd $@"
else
echo "usage: se SEARCH_STRING [FILE_PATTERN]"
fi
@davesque
davesque / rich_text_utils.py
Created March 12, 2013 04:07
Utilities for updating links in rich text content
"""
Utilities for dynamically updating links in rich text fields.
We had a project in which many models had rich text fields. These rich text
fields contained links to model instance detail pages. Since these links were
being entered by hand, we needed a way to update them in the event that the
instance for the detail page they were pointing to changed.
The routines in this file allow links in rich text content to be automatically
updated with a python html parsing library called `BeautifulSoup`.
@davesque
davesque / plane_timer.py
Created March 23, 2013 06:12
A little timer for international airplane flights
import sys
import time
from datetime import datetime, timedelta
START_TIME = datetime(2013, 3, 23, 0, 0, 0, 0)
TRIP_TIME = timedelta(minutes=8.7 * 60)
END_TIME = START_TIME + TRIP_TIME
BAR_WIDTH = 100
@davesque
davesque / anagrams.py
Created April 16, 2013 20:08
My solution to the Thumbtack PyCon challenge 2013
#!/usr/bin/env python
import itertools
import sys
from collections import defaultdict
from pyparsing import CharsNotIn, Group, Optional, Word, ZeroOrMore, alphanums
word = Word(alphanums)
space = CharsNotIn(alphanums)
doc = ZeroOrMore(Group(word + Optional(space)))