Skip to content

Instantly share code, notes, and snippets.

View rchrd2's full-sized avatar

Richard Caceres rchrd2

View GitHub Profile
@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()
@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 / 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 / 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 / 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
"""
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 / Procfile
Last active August 29, 2015 13:58
Procfile for gulp + python server in ./public
# Run with "foreman start"
gulp: gulp
server: sh -c 'cd public && python -m SimpleHTTPServer 9876'
@rchrd2
rchrd2 / bootstrap_puppet.sh
Last active August 29, 2015 14:02
First steps to setup a new puppet agent
# Install NTP for clock syncing
apt-get install -y ntp
/etc/init.d/ntp start
# Install Puppet from official packages
cd
mkdir source
cd source
sudo wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb
sudo dpkg -i puppetlabs-release-precise.deb
@rchrd2
rchrd2 / gist:e5810e7fa15b7beb713d
Created June 19, 2014 04:20
/etc/nagios3/conf.d/localhost_nagios2.cfg
# A simple configuration file for monitoring the local host
# This can serve as an example for configuring other servers;
# Custom services specific to this host are added here, but services
# defined in nagios2-common_services.cfg may also apply.
#
define host{
use generic-host ; Name of host template to use
host_name localhost
alias localhost
@rchrd2
rchrd2 / check_redis_llen.sh
Created June 21, 2014 19:57
Nagios check_redis_llen.sh
#!/bin/bash
# A simple nagios check for Redis set length
#
# It doesn't require any redis libraries and uses the raw api
#
# @author Richard Caceres (me@rchrd.net)
# @license MIT
# @example check_redis_llen -c 50 -w 10 -k celery -h localhost -p 6379
# Parse -c -w args