Skip to content

Instantly share code, notes, and snippets.

View alfg's full-sized avatar

Alfred Gutierrez alfg

  • NBCUniversal / PeacockTV
  • ☀️ Los Angeles, CA
  • 02:15 (UTC -07:00)
View GitHub Profile
@alfg
alfg / runinenv.sh
Created April 20, 2012 19:25 — forked from parente/runinenv.sh
run a command in virtualenv, useful for supervisord
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"
@alfg
alfg / getFileHash.py
Created April 20, 2012 22:36
Simple script to get both MD5 and SHA1 hash of any file.
#!/usr/bin/env python
# Simple script to get both MD5 and SHA1 hash of any file.
import sys
import hashlib
if len(sys.argv) < 2:
sys.exit('Usage: %s filename' % sys.argv[0])
@alfg
alfg / ranking.py
Created April 24, 2012 23:13
Reddit ranking algorithm
#Rewritten code from /r2/r2/lib/db/_sorts.pyx
from datetime import datetime, timedelta
from math import log
epoch = datetime(1970, 1, 1)
def epoch_seconds(date):
"""Returns the number of seconds from the epoch to date."""
td = date - epoch
@alfg
alfg / transmission-blocklist-update.py
Created April 30, 2012 21:56
Updates Transmission daemon blocklist file.
#!/usr/bin/env python
import urllib2
import gzip
import os
from subprocess import call
'''
Updates Transmission Blocklist with specified blocklist file. Must be run as root
if using default blocklist_path directory.
@alfg
alfg / gist:2572863
Created May 2, 2012 01:22
Displays git branch in prompt
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"
PS1="$GREEN\u@battlestation$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\$ "
@alfg
alfg / .gitconfig
Created August 14, 2012 20:40
Add this to your .gitconfig to make git diff, branch and status much more readable. :)
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
@alfg
alfg / clean_old_s3_files.py
Created December 6, 2012 07:32
Purges old objects stored in S3 based on last_modified date.
#!/usr/bin/env python
""" clean_old_s3_files.py - Purges old files based on date given
Author: Alfred Gutierrez (alfg.co)
Requires: boto
Usage: Configure Date, AWS and Bucket variables below. Then run as 'python clean_old_s3_files.py'
@alfg
alfg / datawatch.py
Created December 7, 2012 06:40
Polls a MongoDB collection for new data inserted and sends an email notice
#! /usr/bin/env python
import time
import threading
import pymongo
from pymongo import Connection
import redis
import boto
import pystache
@alfg
alfg / widget-bootstrap.html
Last active November 20, 2019 01:20
Bootstrap files for creating embedded widgets for your site
<html>
<head>
<title>Sample Widget Page</title>
</head>
<body>
<h1>Sample Widget Page</h1>
<script type="text/javascript" src="http://localhost:81/widget-bootstrap.js"></script>
<div id="widget-container"></div>
@alfg
alfg / demo.html
Last active July 22, 2017 00:41
Ping.js example
<!DOCTYPE html>
<html>
<head>
<title>Ping.JS Demo</title>
<style>
ul span {
color: green;
}
</style>