Skip to content

Instantly share code, notes, and snippets.

View SEJeff's full-sized avatar

Jeff Schroeder SEJeff

View GitHub Profile
@SEJeff
SEJeff / debugdjango_function.sh
Created November 4, 2010 19:25
This is the shell function I use to catch snowy tracebacks when a tomboy sync fails
debugdjango() {
action=${1:-traceback}
port=${2:-8000}
interface=${3:-lo}
TCPDUMP="tcpdump -i${interface} -A port ${port}"
case $action in
all)
echo "INFO: Running tcpdump on interface $interface and port $port" >&2
sudo $TCPDUMP
;;
@SEJeff
SEJeff / debug_middleware.py
Created April 8, 2011 17:41
Django debug middleware for displaying extra information when the request includes the "debug" query string.
# Originally based on: http://djangosnippets.org/snippets/1872/
# Requires sqlparse: http://pypi.python.org/pypi/sqlparse
import time
from django.test.signals import template_rendered
from django.conf import settings
from django.db import connection
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
TEMPLATE = """
@SEJeff
SEJeff / cdpy.sh
Created April 9, 2011 17:05
Shell function for automatically cd-ing into the source directory of any python module much like how you cd in the shell
# Put this in /etc/profile.d/cdpy.sh or copy the function into ~/.bashrc
# Change to the source directory of just about any python module to RTFS
#
# (c) 2011 Jeff Schroeder <jeffschroeder@computer.org> released as GPLv2
cdpy() {
module="$1"
[ -z "$module" ] && return 1
dir=$(python -c "
import os
try:
@SEJeff
SEJeff / atom_feed_gen.py
Created April 14, 2011 19:48
Atom feed generator
# Copied from the django source but added feed_url so the write actually works.
import sys
from django.utils import feedgenerator
feed = feedgenerator.Atom1Feed(
title=u"Poynter E-Media Tidbits",
link=u"http://www.poynter.org/column.asp?id=31",
feed_url=u"http://rss.feed_url/",
description=u"A group weblog by the sharpest minds in online media/journalism/publishing.",
language=u"en",
@SEJeff
SEJeff / apt.patch
Created July 7, 2011 04:11
API fix for apt.list_pkgs
jeff@desktopmonster:~/src/git/salt/salt/modules (misc-fixes)$ gdi apt.py
diff --git a/salt/modules/apt.py b/salt/modules/apt.py
index f3b0cd8..75751a4 100644
--- a/salt/modules/apt.py
+++ b/salt/modules/apt.py
@@ -196,7 +196,7 @@ def upgrade(refresh=True):
return ret_pkgs
-def list_pkgs(regex_string=""):
@SEJeff
SEJeff / settings_logging.py
Created July 8, 2011 22:19
How to enable debug logging for django_auth_ldap
############################## django-auth-ldap ##############################
if DEBUG:
import logging, logging.handlers
logfile = "/tmp/django-ldap-debug.log"
my_logger = logging.getLogger('django_auth_ldap')
my_logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(
logfile, maxBytes=1024 * 500, backupCount=5)
@SEJeff
SEJeff / settings_ldap.py
Created July 8, 2011 22:27
Example django_auth_ldap configuration
############################## django-auth-ldap ##############################
import ldap
from django_auth_ldap.config import LDAPSearch, PosixGroupType
# django-auth-ldap configuration starts here
AUTH_LDAP_SERVER_URI = "ldap://ldap.els03.loc ldap://ldap.zbw03.loc ldap://ldap.cvg03.loc"
#AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=People,o=loc"
# JW is in ou=Admin,o=loc so we search over o=loc to find him
AUTH_LDAP_USER_SEARCH = LDAPSearch("o=loc",
@SEJeff
SEJeff / human_readable_sizes.py
Created February 27, 2012 22:35
Nifty python function for turning machine readable bytes into human readable sizes
def hr_bytes(size):
'''
This just returns the bytes in a human readable format.
'''
hr = lambda s:[(s%1024**i and "%.1f"%(s/1024.0**i) or str(s/1024**i))+x.strip() for i,x in enumerate(' KMGTPEZY') if s<1024**(i+1) or i==8][0]
return hr(size)
@SEJeff
SEJeff / djangomodule.py
Created February 28, 2012 00:37 — forked from fatbox/djangomodule.py
Load Django modules from within a Salt module
"""
This allows you to import Django modules into a Salt module
"""
import logging
import sys
import os
log = logging.getLogger(__name__)
include:
- apt
# our custom sources
/etc/apt/sources.list.d/fatbox.list:
file:
- managed
- source: salt://fatbox/debian/apt/fatbox.list
- owner: root
- group: root