Skip to content

Instantly share code, notes, and snippets.

View epicserve's full-sized avatar

Brent O'Connor epicserve

View GitHub Profile
@epicserve
epicserve / checkpid_test.py
Created February 23, 2012 09:00
Pidcheck is a python decorator to check and see if a process with the same PID is still running.
#!/usr/bin/env python
from checkpid import pidcheck
from time import sleep
import logging
log = logging.getLogger("checkpid")
log.setLevel(logging.INFO)
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
@epicserve
epicserve / redis_key_sizes.sh
Last active November 18, 2025 16:07
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@epicserve
epicserve / svn_to_git.rst
Created September 15, 2011 17:17
Convert SVN Repositories to Git Repositories

Convert SVN Repositories to Git Repositories

This guide on how to convert an SVN repository to a git repository was mostly taken from John Albin Wilkins post on Converting a Subversion repository to Git.

1. Retrieve a list of all Subversion committers

@epicserve
epicserve / timeit.py
Created November 5, 2025 14:02
Example of using the rich library for a timing context manager
import time
from contextlib import contextmanager
from datetime import timedelta
from rich.align import Align
from rich.columns import Columns
from rich.console import Console
from rich.padding import Padding
from rich.style import Style
from rich.text import Text
@epicserve
epicserve / share_link_on_facebook_fan_page_test.py
Created March 17, 2012 22:21
Share a link on your Facebook fan page.
@epicserve
epicserve / example.com.import.txt
Last active March 11, 2023 14:04
Example Terraform file for importing DNS Records from DigitalOcean
digitalocean_domain.example example.com
digitalocean_record.example example.com,<DO ID>
digitalocean_record.fd-gmail-txt example.com,<DO ID>
digitalocean_record.fd-mx["alt1.aspmx.l.google.com."] example.com,<DO ID>
digitalocean_record.fd-mx["alt2.aspmx.l.google.com."] example.com,<DO ID>
digitalocean_record.fd-mx["aspmx.l.google.com."] example.com,<DO ID>
digitalocean_record.fd-mx["aspmx2.googlemail.com."] example.com,<DO ID>
digitalocean_record.fd-mx["aspmx3.googlemail.com."] example.com,<DO ID>
digitalocean_record.fd-ns["1"] example.com,<DO ID>
digitalocean_record.fd-ns["2"] example.com,<DO ID>
@epicserve
epicserve / example_command.py
Created October 30, 2013 17:05
Example of how to setup logging for a Django management command.
from django.core.management.base import BaseCommand
from mymodule import main
import logging
class Command(BaseCommand):
help = 'Do foo'
def handle(self, *args, **options):
@epicserve
epicserve / mem_report.sh
Created April 26, 2012 22:55
A quick script for printing out memory usage of various services
CELERY=`ps -A -o pid,rss,command | grep celeryd | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'`
GUNICORN=`ps -A -o pid,rss,command | grep gunicorn | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'`
REDIS=`ps -A -o pid,rss,command | grep redis | grep -v grep | awk '{total+=$2}END{printf("%d", total)}'`
NGINX=`ps -A -o pid,rss,command | grep nginx | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'`
OTHER=`ps -A -o pid,rss,command | grep -v nginx | grep -v celeryd | grep -v gunicorn | grep -v redis | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'`
websites=`ps -A -o user,pid,rss,command | grep gunicorn | egrep -o "[a-z_]+\.py$" | sort | uniq | perl -wpe 's|\.py$||;' | xargs`
printf "%-10s %3s MB\n" "Celery:" $CELERY
printf "%-10s %3s MB\n" "Gunicorn:" $GUNICORN
printf "%-10s %3s MB\n" "Nginx:" $NGINX
printf "%-10s %3s KB\n" "Redis:" $REDIS
@epicserve
epicserve / weather_codes.py
Created January 28, 2013 21:32
Yahoo and NOAA Weather Icons
# source: http://w1.weather.gov/xml/current_obs/weather.php
# icon_url: http://w1.weather.gov/images/fcicons/<weather_code>.jpg
noaa_weather_codes = {
'bkn': 'Mostly Cloudy | Mostly Cloudy with Haze | Mostly Cloudy and Breezy',
'nbkn': 'Mostly Cloudy | Mostly Cloudy with Haze | Mostly Cloudy and Breezy',
'skc': 'Fair | Clear | Fair with Haze | Clear with Haze | Fair and Breezy | Clear and Breezy',
'nskc': 'Fair | Clear | Fair with Haze | Clear with Haze | Fair and Breezy | Clear and Breezy',
'few': 'A Few Clouds | A Few Clouds with Haze | A Few Clouds and Breezy',
'nfew': 'A Few Clouds | A Few Clouds with Haze | A Few Clouds and Breezy',
'sct': 'Partly Cloudy | Partly Cloudy with Haze | Partly Cloudy and Breezy',
@epicserve
epicserve / django_aliases.sh
Created November 20, 2012 16:39
Django Aliases
# Django Aliases
alias d=django-admin.py
alias dt='django-admin.py test'
alias dsa='django-admin.py startapp --template=https://github.com/epicserve/django-app-template/archive/master.zip'
alias dsp='django-admin.py startproject --template=https://github.com/epicserve/django-base-site/archive/master.zip'
alias dsma='django-admin.py schemamigration --auto'
alias dsmi='django-admin.py schemamigration --initial'
alias dm='django-admin.py migrate'
# shortcut for starting django's runserver on a different port