Skip to content

Instantly share code, notes, and snippets.

powellc /
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.
# Location to place backups.
#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
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 /
Created August 3, 2016 15:59 — forked from six519/
Install node/npm/nvm Bash Script In FreeBSD 10.2
#!/usr/bin/env bash
#just want to post something!!!!!! :D
sudo pkg install node www/npm git gmake wget
wget -qO- | bash
powellc /
Last active May 12, 2016 18:14
Build a changelog from git commits
import re
import os
import git
semver_pattern = '(?:(\d+)\.)(?:(\d+)\.)(?:(\d+))'
BASE_DIR = os.getcwd()
g = git.cmd.Git(BASE_DIR)
commits = list(filter(None, g.log("--format=%B").splitlines()))
powellc /
Created February 11, 2016 19:12
Fixes overscanning on Heron, my TV computer
xrandr --output HDMI-0 --rate 60 --mode 1360x768 --fb 1360x768 --panning 1360x768* --output HDMI-0 --mode 1360x768 --same-as VGA-0
xrandr --output HDMI-0 --set underscan on
xrandr --output HDMI-0 --set "underscan hborder" 40 --set "underscan vborder" 25
powellc /
Last active February 10, 2016 21:28

Keybase proof

I hereby claim:

  • I am powellc on github.
  • I am secstate ( on keybase.
  • I have a public key ASBxgRKwG3tnw7tfdz9pf0b2oIvtQrkboSA3EbFL7aDObQo

To claim this, I am signing this object:

powellc / zshrc
Last active February 10, 2016 17:22
My zshrc file
# Path to your oh-my-zsh installation.
export ZSH=~/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# Uncomment the following line to use case-sensitive completion.
powellc / bashrc
Last active February 10, 2016 17:21
A bash configuration file
#!/usr/bin/env bash
# Path to the bash it configuration
export BASH_IT="/home/powellc/.bash_it"
# Lock and Load a custom theme file
# location /.bash_it/themes/
export BASH_IT_THEME='powerline'
# Your place for hosting Git repos. I use this for private repos.
powellc / save_as-with-unique-slugs
Created January 5, 2014 06:01
ModelAdmin code to make save_as work for models with unique slugs
def add_view(self, request, form_url='', extra_context=None):
save_as_new = request.POST.get("_saveasnew", '')
if extra_context is None:
extra_context = {}
# keep the save as new in case of validation errors
extra_context['save_as_new'] = save_as_new
# but if it is a real new addition, remove _saveasnew from POST
if not save_as_new and '_saveasnew' in request.POST:
del request.POST['_saveasnew']
powellc /
Created May 28, 2013 12:31
Shell script to use duplicity and AWS S3 to backup files on a server, hooray. Not the most secure way to handle your password and AWS key, but couldn't get easier, giving you no reason to have some kind of backup of your server.
export PASSPHRASE=your_gpg_passphrase
export AWS_ACCESS_KEY_ID=your_s3_access_key
export AWS_SECRET_ACCESS_KEY=your_s3_secret
export MYSQL_PASSWORD=your_mysql_password
for DB in app_1 app_2 app_3; do
mysqldump -h localhost -u backup_user -p${MYSQL_PASSWORD} ${DB} | gzip > /var/dbdumps/${DB}.sql
powellc /
Created May 7, 2013 21:31
A nice big caveat for using Johnny Cache to speed up django ORM queries when you also have to use management tasks.

Johnny Cache & Management Commands

Discovered a pretty huge caveat to using Johnny Cache to speed up Django ORM queries.

Johnny Cache is a really great library that can speed up Django sites that are slowing down with large joins and complex data models. Django has a built in ORM caching mechanism, but Johnny Cache takes it one step further.

That said, there are some monsters in the undiscovered ocean. One of the big ones is,