Skip to content

Instantly share code, notes, and snippets.

View rchrd2's full-sized avatar

Richard Caceres rchrd2

View GitHub Profile
"""
A pretty nice time parsing regex.
@author Richard Caceres, @rchrd2
"""
import re
# The history for this regex is stored in my gist
# https://gist.github.com/rchrd2/9773922
time_range_regex = re.compile(r'''
@rchrd2
rchrd2 / Restart_Celery
Created November 28, 2013 20:00
This sends a SIGHUP to the children of a master celery process. The benefit of this is that the master celery process keeps it's same PID.
# Send a SIGHUP to only the children (--ppid is the magic param here).
cat /var/run/celery.pid | xargs ps --no-headers --ppid | awk '{print $1}' | xargs kill -HUP
@rchrd2
rchrd2 / johnd1
Last active December 29, 2015 11:39
These are templates for creating an init.d script for a Procfile that needs to be run with virtualenv. The first uses `daemon`. The second uses `start-stop-daemon`.
#!/bin/bash
### BEGIN INIT INFO
# Provides: johnd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
@rchrd2
rchrd2 / profile_render.sh
Created November 19, 2013 21:57
Watch a directory then automatically render and open profile graphs.
#!/bin/sh
watchmedo shell-command \
--pattern="*prof" \
--ignore-pattern="*png" \
--wait \
--command='find profile_data -name "*\.prof" -exec sh -c "test -f {}.png || (gprof2dot -f pstats {} | dot -Tpng -o {}.png && open {}.png)" \;' \
profile_data
@rchrd2
rchrd2 / convert.sh
Created November 4, 2013 20:17
Helper script to convert wav files to mp3 with ffmpeg.
#!/bin/bash
BITRATE=320
defvalue='.'
SOURCE_DIR=${1:-$defvalue}
# Validate arguments
if [[ "$#" == 0 ]]; then
echo >&2 "Usage: ./convert.sh ./exports/*.wav"
exit 1;
@rchrd2
rchrd2 / gist:6179550
Created August 7, 2013 22:39
How to link django-social-auth with google-api-python-client I am creating a gist, because this took me way to long to figure out. Maybe it can save you some time!
import httplib2
from apiclient.discovery import build
from oauth2client.client import AccessTokenCredentials
def connect_helper(user):
c = user.social_auth.get(provider='google-oauth2')
access_token = c.tokens['access_token']
credentials = AccessTokenCredentials(access_token, 'my-user-agent/1.0')
http = httplib2.Http()