Skip to content

Instantly share code, notes, and snippets.

@dstufft
dstufft / mysql_bin_purge.py
Created February 18, 2011 02:42
Purges binary unneeded binary logs from a MySQL master.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""MySQL Binary Log Purger
This script handles purging unneeded binary logs from a MySQL master. It
will run on python 2.5+ and requires the oursql library.
In order to configure this script, you need to have a user with the same
username and password on the master and all slaves. The port is assumed
to be the same amongst the master and all slaves, and it is assumed
@dstufft
dstufft / fabfile.py
Created March 10, 2011 02:01
A fabfile for deploying a Django app with VirtualEnvWrapper, PIP and Supervisor
# Run this like fab -R www deploy
from fabric.api import *
REPO_URL = '[email protected]:username/repo.git'
PROJECT_DIR = '$HOME/projects/projectname'
PROJECT_NAME = 'projectname'
SERVER_NAME = 'projectname.servername' # I use gunicorn, so i have projectname.gunicorn
env.roledefs['www'] = ['www1.example.com']
@dstufft
dstufft / linode-dns.py
Created April 1, 2011 01:48
Dynamic DNS w/ Linode DNS
#!/usr/bin/env python
import urllib
import json
import sys
LINODE_API_URL = 'https://api.linode.com/'
LINODE_API_KEY = '' # Add in your Linode API Key
TARGET_DOMAIN = 'example.com' # Replace with domain name
TARGET_RECORD = 'home' # Replace with sub domain
@dstufft
dstufft / gist:997475
Created May 29, 2011 04:48
Configuration Files for Nginx + Gunicorn + Supervisord
We couldn’t find that file to show.
@dstufft
dstufft / hits.py
Created June 3, 2011 12:24
Reads a tab delimited log file in reverse and generates some stats based on it.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Finds the Address with the most Hit's yesterday"""
from datetime import date, datetime
from optparse import OptionParser
import mmap
import csv
import sys
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
@dstufft
dstufft / profile.ps1
Created June 24, 2011 13:08
Windows PowerShell 2.0 Profile that adds a descriptive prompt suitable for working with git (or hg) and virtualenvs
# Written by Donald Stufft
#
# My Windows PowerShell Profile. It gives a prompt that looks like
# UserName at MachineName in ~/path on master^1?!
# (virtualenvname) ±
#
# Explanation:
# If you are in a git repo the prompt character will be ±, ¥ for mercurial and » otherwise.
# If you are in a git repo it will include the "on ...." bit.
# It will replace master with the name of the current branch
from tastypie.authentication import BasicAuthentication as TastypieBasicAuthentcation
from django.contrib.auth.models import AnonymousUser
class BasicAuthentication(TastypieBasicAuthentcation):
"""
Subclass Basic Authentcation to allow Anonymous users.
"""
def is_authenticated(self, request, **kwargs):
@dstufft
dstufft / mixins.py
Created September 15, 2011 19:18
Login Required Decorator
from django.conf import settings
from django.http import HttpResponseRedirect
class LoginRequired(object):
def dispatch(self, request, *args, **kwargs):
if self.check_logged_in(request.user):
return super(LoginRequired, self).dispatch(request, *args, **kwargs)
else:
return self.not_logged_in(self):
@dstufft
dstufft / decorators.py
Created September 15, 2011 21:22
Mixins vs Decorators for Django
from functools import wraps
class ViewDecorator(object):
def __init__(self, decorator_class):
self.decorator_class = decorator_class
def __call__(self, *args, **kwargs):
# Pretend that there is a generic decorator wrapper here
pass
@dstufft
dstufft / kaa.py
Created October 31, 2011 23:23 — forked from maxcountryman/kaa.py
A very simple non-blocking IRC bot using gevent
import gevent
from gevent import socket, queue
from gevent.ssl import wrap_socket
import logging
logger = logging.getLogger('irc')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()