Skip to content

Instantly share code, notes, and snippets.

@powellc
powellc / fabfile.py
Created February 1, 2010 00:22 — forked from heckj/fabfile.py
Forked for my own vps info.
#!/usr/bin/env python
from __future__ import with_statement # needed for python 2.5
from fabric.api import *
from fabric.contrib.console import confirm
# ================================================================
# NOTE:
# using this fabfile expects that you have the python utility
# fabric installed locally, ssh access to reamea.com, and your
# ssh public key associated with the account 'mboza@reamea.com'
#!/bin/bash
# The purpose of this file is to, as quickly as possible, set up a home directory
# with all the creature comforts I expect.
#
# For this to work:
# 1. Add ssh keys to github and personal git repo
# 2. sudo aptitude install zsh git-core
mkdir $HOME/.virtualenvs
# terminfo and termcap for nice 256 color terminal
# allow bold colors - necessary for some reason
attrcolor b ".I"
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
# erase background with current bg color
defbce "on"
@powellc
powellc / .zshrc
Created September 15, 2010 16:33
export TERM=xterm-256color
# Default the box color to red, but change to differentiate boxes or VPSs
export BOXCOLOR="%{$fg[red]%}"
# Path to your oh-my-zsh configuration.
export ZSH=$HOME/.oh-my-zsh
# Set to the name theme to load.
# Look in ~/.oh-my-zsh/themes/
#!/bin/bash
###
### This script simply parses ifconfig and loads a box's main IP into a shell variable
###
OS=`uname`
IP="" # store IP
case $OS in
Linux) IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' | grep 24 `;;
diff --git a/src/adzone/managers.py b/src/adzone/managers.py
index 347e85e..271e36d 100644
--- a/src/adzone/managers.py
+++ b/src/adzone/managers.py
@@ -8,8 +8,15 @@ class AdManager(models.Manager):
Returns a random advert that belongs to the specified category and zone
"""
- try:
- ad = self.get_query_set().filter(category__slug=ad_category, zone__slug=ad_zone).order_by('?')[0]
@powellc
powellc / run.py
Created March 7, 2011 20:21
A development script to run django with gevent instead of flup
#!/usr/bin/python
import sys
sys.path.append('<path_to_virtualenv>')
from gevent import monkey; monkey.patch_all()
from gevent.wsgi import WSGIServer
import os
import traceback
from django.core.handlers.wsgi import WSGIHandler
from django.core.management import call_command
@powellc
powellc / pg_backup_all.sh
Last active October 1, 2023 19:14
Bash script to backup all postgresql databases on a server, run with cron once a day or 5 times a day, whatever. Just updated it so it ignores your postgres db, and also bzips the backups and adds a symlink to a latest directory. Sweet.
#!/bin/bash
# Location to place backups.
backup_dir="/var/backups/databases/"
nightly_dir="/var/backups/databases/latest/"
#String to append to the name of the backup files
backup_date=`date +%d-%m-%Y`
#Numbers of days you want to keep copie of your databases
number_of_days=15
databases=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'`
for i in $databases; do if [ "$i" != "postgres" ] && [ "$i" != "template0" ] && [ "$i" != "template1" ] && [ "$i" != "template_postgis" ]; then
@powellc
powellc / msql_backup_all.sh
Last active December 11, 2015 17:08
MySQL backup script for nightly dumps that clean up after a certain number of days and keep a symlink to the latest one so you can easily setup a webserver to provide dumps for development purposes
#!/bin/bash
DB_BACKUP="/var/backups/databases/"
LATEST_DIR="/var/backups/databases/latest/"
DB_USER="root"
DB_PASSWD="secretttt"
HN=`hostname | awk -F. '{print $1}'`
# Remove backups older than 10 days
@powellc
powellc / pg_chg_table_owner.sh
Last active December 11, 2015 17:48
Change owner of all tables in a PG database, great for those times when your dev user doesn't match production or whatever.
echo "Your database name [Enter]: "
read YOUR_DB
echo "New owner name [Enter]: "
read NEW_OWNER
# First alter tables
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $YOUR_DB` ; do
psql -c "alter table $tbl owner to $NEW_OWNER" $YOUR_DB ;
done