Skip to content

Instantly share code, notes, and snippets.

Jeff Schroeder SEJeff

Block or report user

Report or block SEJeff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@SEJeff
SEJeff / debugdjango_function.sh
Created Nov 4, 2010
This is the shell function I use to catch snowy tracebacks when a tomboy sync fails
View debugdjango_function.sh
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 Apr 8, 2011
Django debug middleware for displaying extra information when the request includes the "debug" query string.
View debug_middleware.py
# 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 Apr 9, 2011
Shell function for automatically cd-ing into the source directory of any python module much like how you cd in the shell
View cdpy.sh
# 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 Apr 14, 2011
Atom feed generator
View atom_feed_gen.py
# 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 Jul 7, 2011
API fix for apt.list_pkgs
View apt.patch
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 Jul 8, 2011
How to enable debug logging for django_auth_ldap
View settings_logging.py
############################## 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 Jul 8, 2011
Example django_auth_ldap configuration
View settings_ldap.py
############################## 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 Feb 27, 2012
Nifty python function for turning machine readable bytes into human readable sizes
View human_readable_sizes.py
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 Feb 28, 2012 — forked from fatbox/djangomodule.py
Load Django modules from within a Salt module
View djangomodule.py
"""
This allows you to import Django modules into a Salt module
"""
import logging
import sys
import os
log = logging.getLogger(__name__)
View gist:2045075
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
You can’t perform that action at this time.