Skip to content

Instantly share code, notes, and snippets.

View alfg's full-sized avatar

Alfred Gutierrez alfg

  • NBCUniversal / PeacockTV
  • ☀️ Los Angeles, CA
  • 05:00 (UTC -07:00)
View GitHub Profile
@alfg
alfg / main.js
Created December 31, 2014 18:48
Basic constructor pattern with jQuery support
;(function($) {
// Plugin constructor with options and methods
var MainPlugin = function() {
var _self = this;
var _options = {
foo: "bar"
};
@alfg
alfg / cache.js
Last active August 29, 2015 14:25
node-cache getOrSet caching pattern.
var NodeCache = require('node-cache');
var myCache = new NodeCache();
var cache = {
/** Gets key from cache if exists, else sets the cache and returns data.
* @param {string} cacheKey - Key to get or set.
* @param {integer} timeout - Timeout (in seconds) for cache to release.
* @param {Function} fn - Function to get data if key does not exist.
* @param {Function} callback - Callback function to send back data or value.
@alfg
alfg / .jshintrc.js
Last active August 29, 2015 14:27 — forked from connor/.jshintrc.js
jshintrc example
// NOTE: I added the .js extension to this gist so it would have syntax highlighting. This file should have NO file extension
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
@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 / 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