Skip to content

Instantly share code, notes, and snippets.

View philfreo's full-sized avatar

Phil Freo philfreo

View GitHub Profile
@philfreo
philfreo / closeio_emails.py
Created July 11, 2013 16:45
Close.io: send a templated email to everyone in a search query
#!/usr/bin/env python
import argparse
from pybars import Compiler
from closeio_api_client.api import CloseIO_API as CloseIO
# We ensure the same templateid doesn't get sent again (see the search query construction)
emails = {
@philfreo
philfreo / gist:6518326
Created September 11, 2013 01:37
Stripe invoice.created webhook handling for subscription billing
def stripe_invoice_created_webhook(stripe_event):
"""Called by Stripe when an invoice is created so we can log it and tell Stripe about any charges to add."""
stripe_event_invoice = stripe_event['data']['object']
stripe_invoice = stripe.Invoice.retrieve(stripe_event_invoice['id'])
orgs = Organization.objects.filter(status=OrganizationStatus.Paying, stripe_customer_id=stripe_invoice.customer)
for org in orgs:
if org.manual_billing:
continue
@philfreo
philfreo / swap.pp
Last active December 23, 2015 03:49 — forked from Yggdrasil/swap.pp
# Manages swapspace on a node.
#
# Based on https://gist.github.com/Yggdrasil/3918632
#
# Parameters:
# - $ensure Allows creation or removal of swapspace and the corresponding file.
# - $swapfile Defaults to /mnt which is a fast ephemeral filesystem on EC2 instances.
# This keeps performance reasonable while avoiding I/O charges on EBS.
# - $swapsize Size of the swapfile in MB. Defaults to memory size.
#
@philfreo
philfreo / etc_default_supervisor.sh
Created September 17, 2013 06:02
Supervisor Init.d
# Defaults for supervisor initscript
# sourced by /etc/init.d/supervisor
# installed at /etc/default/supervisor by the maintainer scripts
#
# This is a POSIX shell fragment
#
# Additional options that are passed to the Daemon.
DAEMON_OPTS="-c /etc/supervisor/supervisord.conf"
@philfreo
philfreo / fabfile_puppet.py
Created September 19, 2013 07:14
Fabric fabfile to bootstrap new servers and install/configure Puppet 3.3 Tested with 64bit Ubuntu 12.04 LTS on AWS EC2
import os
from fabric.api import *
PUPPETMASTER_HOST = 'ecxxxxxxxxxxxx.us-west-2.compute.amazonaws.com'
DOMAIN = 'example.com'
def set_hostname(hostname, domain):
"""Sets the hostname and FQDN for an instance. Should persist after reboot.
We want to get 'hostname' to return our hostname (e.g. "foo").
@philfreo
philfreo / elb.py
Created September 26, 2013 18:19
Python script to remove/add an EC2 instance into an AWS ELB. Helpful during deployments. (Using Flask / Flask-Script but easily modifiable)
#!/usr/bin/env python
import time
import boto
import boto.ec2.elb
import boto.utils
from flask.ext.script import Manager
from closeio.main import setup_app
@philfreo
philfreo / gist:7257723
Created October 31, 2013 21:44
Facebook Perl source code from 2005. When browsing around thefacebook.com in 2005 the server spit out some server-side source code rather than running it. I believe this was for their old graph feature that let you visualize the graph between all your friends. The filename is `mygraph.svgz` and contains some gems such as a commented out "zuck" d…
#!/usr/bin/perl
use Mysql;
use strict;
use vars qw($school_name);
use vars qw($pass);
require "./cgi-lib.pl";
@philfreo
philfreo / hijack-links.js
Created February 26, 2014 22:41
Hijack in-site links for Backbone.js
@philfreo
philfreo / gist:9241308
Created February 26, 2014 23:49
Einstein's favorite limerick
There was an old lady called Wright
who could travel much faster than light.
She departed one day
in a relative way
and returned on the previous night.
@philfreo
philfreo / close-api.rb
Last active September 15, 2022 00:52
Close API Ruby RestClient Example
require 'rest_client'
require 'json'
API_KEY = 'your api key here'
api_base = 'https://' + API_KEY + ':@api.close.com/api/v1/'
# get info about yourself
RestClient.get api_base+'me/'
# post a lead