Skip to content

Instantly share code, notes, and snippets.

@ericflo
ericflo / pycamo.py
Created November 22, 2010 01:00
Just makin' sure I know how to create a hex digest for Camo from Python
>>> import hashlib
>>> import hmac
>>> digest_maker = hmac.new('0x24FEEDFACEDEADBEEFCAFE', '', hashlib.sha1)
>>> digest_maker.update('http://farm5.static.flickr.com/4116/4857328881_fefb8e2134_z.jpg')
>>> digest_maker.hexdigest()
'2731d77b436b8a78f4cbe3624d8088fd5262f996'
@ericflo
ericflo / twisted_proxy.py
Created November 22, 2010 01:11
Proxies local stuff, depending on whether it's /live/ or not.
#!/usr/bin/env python
from twisted.internet import reactor
from twisted.web import proxy, server
from twisted.web.resource import Resource
class ProxyResource(Resource):
def getChild(self, path, request):
request.received_headers['x-forwarded-host'] = request.received_headers['host']
@ericflo
ericflo / backup_db.py
Created January 5, 2011 18:25
A management command to put on a cron to keep daily backups of a postgres database (with a 1-week window)
import datetime
import subprocess
from django.conf import settings
from django.core.management.base import BaseCommand
from boto.s3.connection import S3Connection
from boto.s3.key import Key
class Command(BaseCommand):
@ericflo
ericflo / twitter_to_convore.py
Created February 20, 2011 10:02
A small script which takes keywords to track on Twitter and streams them live into a Convore topic.
import base64
import httplib
import threading
import urllib
import tweepy
CONVORE_BOT_USERNAME = ''
CONVORE_BOT_PASSWORD = ''
CONVORE_TOPIC_ID = '7612'
//
// NSURLConnection+Blocks.h
// SteveHolt
//
// Created by Eric Florenzano on 10/19/11.
// Copyright (c) 2011 Boilerplate Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@ericflo
ericflo / get_and_update_or_create.py
Created January 2, 2012 20:21
Utility function for querying for and updating a model at the same time.
def get_and_update_or_create(model, unique, update):
"""
Given a model, a dictionary of lookup arguments, and a dictionary of update
arguments, this convenience function gets an object and updates it in the
database if necessary.
Returns a tuple (object, int) where int is 0 if the object was not updated,
1 if the object was created, and 2 if the object was updated in the
database.
@ericflo
ericflo / stripe.py
Created March 21, 2012 00:15
Replaced my use of Stripe's Python API with this
import httplib
import base64
import contextlib
import simplejson
import urllib
from django.conf import settings
def stripe_fetch(resource, method='GET', params=None, secret=settings.STRIPE_SECRET, prefix='/v1'):
@ericflo
ericflo / send_template_mail.py
Created March 23, 2012 21:12
Send a templated mail
from django.conf import settings
from django.template import Context, loader
from django.core.mail import send_mail
def send_template_mail(slug, context, recipient_list, from_email=settings.DEFAULT_FROM_EMAIL):
if isinstance(recipient_list, basestring):
recipient_list = [recipient_list]
if not isinstance(context, Context):
context = Context(context)
subject_tmpl = loader.get_template('mail/%s/subject.txt' % (slug,))
@ericflo
ericflo / logscoop.py
Last active December 28, 2015 02:39
Low tech Flask logging with UDP, JSON, and Twisted.
import os
import subprocess
from sqlalchemy import Column, String, Integer, Float, MetaData, Table
from sqlalchemy import create_engine
from alchimia import TWISTED_STRATEGY
from flask import json
@ericflo
ericflo / reactdropzone.js
Last active September 15, 2016 09:00
ReactDropzone, a react component for interfacing with http://www.dropzonejs.com/
/** @jsx React.DOM */
var ReactDropzone = React.createClass({
componentDidMount: function() {
var options = {};
for (var opt in Dropzone.prototype.defaultOptions) {
var prop = this.props[opt];
if (prop) {
options[opt] = prop;
continue;