Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Caceres rchrd2

View GitHub Profile
@rchrd2
rchrd2 / gist:6179550
Created Aug 7, 2013
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!
View gist:6179550
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 Nov 4, 2013
Helper script to convert wav files to mp3 with ffmpeg.
View convert.sh
#!/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 Nov 19, 2013
Watch a directory then automatically render and open profile graphs.
View profile_render.sh
#!/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 Dec 29, 2015
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`.
View johnd1
#!/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 Nov 28, 2013
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.
View Restart_Celery
# 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
View time_range_regex.py
"""
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 Aug 29, 2015
Procfile for gulp + python server in ./public
View Procfile
# Run with "foreman start"
gulp: gulp
server: sh -c 'cd public && python -m SimpleHTTPServer 9876'
@rchrd2
rchrd2 / bootstrap_puppet.sh
Last active Aug 29, 2015
First steps to setup a new puppet agent
View bootstrap_puppet.sh
# 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 Jun 19, 2014
/etc/nagios3/conf.d/localhost_nagios2.cfg
View gist:e5810e7fa15b7beb713d
# 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 Jun 21, 2014
Nagios check_redis_llen.sh
View 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