Skip to content

Instantly share code, notes, and snippets.

View un33k's full-sized avatar
🎯
Focusing

Val N. un33k

🎯
Focusing
View GitHub Profile
@un33k
un33k / nt.sh
Created September 26, 2010 00:45 — forked from epall/nt.sh
OSX: Start a new terminal with PWD=current directory
#!/usr/bin/env sh
# A simple script to open a new tab in Terminal in the current directory
# Author: Eric Allen
osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' > /dev/null 2>&1
osascript -e "tell application \"Terminal\" to do script \"cd $PWD && clear\" in window 1" > /dev/null 2>&1
### Basic daemon config
ServerRoot "/etc/apache2"
PidFile ${APACHE_PID_FILE}
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
ServerTokens ProductOnly
ServerAdmin webmaster@djangoproject.com
### Listen on localhost:8000 (behind the proxy)
@un33k
un33k / replication_fabfile.py
Created June 4, 2011 02:22 — forked from jacobian/replication_fabfile.py
A fab task to start pg9 hot standby.
def start_replication():
"""
Begin Postgresql standby
"""
# Stop pg on the slave machine.
with settings(host_string=env.db_slave):
run('service postgresql-9.0 stop')
# Create the backup on the master machine
with settings(host_string=env.db_master):
@un33k
un33k / check_postgres_replication.py
Created June 4, 2011 02:25 — forked from jacobian/check_postgres_replication.py
Nagios plugin to check PostgreSQL 9 streaming replication lag.
#!/usr/bin/env python
"""
Nagios plugin to check PostgreSQL 9 streaming replication lag.
Requires psycopg2 and nagiosplugin (both installable with pip/easy_install).
MIT licensed:
Copyright (c) 2010 Jacob Kaplan-Moss. All rights reserved.
import datetime
import mechanize
from xml.etree import cElementTree
USERNAME = '...'
PASSWORD = '...'
NUMBER = '2025551212'
br = mechanize.Browser()
br.open('https://ebillpay.verizonwireless.com/vzw/accountholder/overview/AccountOverview.action')
@un33k
un33k / gist:1007493
Created June 4, 2011 02:31 — forked from jacobian/gist:336445
Installing GeoDjango deps on Ubuntu 9.10
### Install some packages. Ignore the errors.
aptitude install binutils libgdal1-1.5.0 postgresql-8.3-postgis postgresql-server-dev-8.3 python-psycopg2 python-setuptools
### Make connecting to postgres easier
echo "local all all trust" > /etc/postgresql/8.3/main/pg_hba.conf
invoke-rc.d postgresql-8.3 reload
### Become the Postgres user to create a spatial template database:
@un33k
un33k / add_user_info_to_request_middleware.py
Created June 5, 2011 03:51 — forked from sidmitra/add_user_info_to_request_middleware.py
Middleware to add user info to the current django request
class ExceptionUserInfoMiddleware(object):
"""
Adds user details to request context on receiving an exception, so that they show up in the error emails.
Add to settings.MIDDLEWARE_CLASSES and keep it outermost(i.e. on top if possible). This allows
it to catch exceptions in other middlewares as well.
"""
def process_exception(self, request, exception):
"""
@un33k
un33k / middleware.py
Created June 5, 2011 03:54 — forked from pmclanahan/middleware.py
Django 1.2+ middleware that allows you to set cookies from a request object.
from types import MethodType
from django.http import CompatCookie, HttpRequest
def _set_cookie(self, key, value='', max_age=None, expires=None, path='/',
domain=None, secure=False):
self._resp_cookies[key] = value
self.COOKIES[key] = value
if max_age is not None:
import re
import inspect
import pygraphviz as pgv
from django.conf import settings; settings.configure()
from django.views import generic
class GenericViewGraph(pgv.AGraph):
_ignore_types = (None, object)
def __init__(self, *args, **kwargs):
@un33k
un33k / deleting_file_field.py
Created September 23, 2011 04:28 — forked from jacobian/deleting_file_field.py
DeletingFileField
from django.db import models
from django.db.models import signals
class DeletingFileField(models.FileField):
"""
FileField subclass that deletes the refernced file when the model object
itself is deleted.
WARNING: Be careful using this class - it can cause data loss! This class
makes at attempt to see if the file's referenced elsewhere, but it can get