Skip to content

Instantly share code, notes, and snippets.

View philfreo's full-sized avatar

Phil Freo philfreo

View GitHub Profile
@philfreo
philfreo / documents.py
Created January 8, 2013 22:57
RandomPKDocument and DocumentBase
import os
import datetime
from zbase62 import zbase62
from mongoengine import *
from mongoengine.base import ValidationError
from mongoengine.queryset import OperationError
class RandomPKDocument(Document):
id = StringField(unique=True, primary_key=True)
@philfreo
philfreo / simple_allow_all.xml
Last active October 23, 2019 02:39
AWS S3 CORS policy examples
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
<AllowedHeader>Content-*</AllowedHeader>
<AllowedHeader>Host</AllowedHeader>
</CORSRule>
sqlite3 ~Library/Messages/chat.db "DELETE FROM message WHERE text LIKE '%File:///%';"
@philfreo
philfreo / gist:5217582
Created March 21, 2013 22:57
wrap MimeRender decorator so you have access to the original wrapped function
class MimeRender(mimerender.FlaskMimeRender):
def __call__(self, *args, **kwargs):
ret = super(MimeRender, self).__call__(*args, **kwargs)
def wrap(target):
target._orig_func = target
return ret(target)
return wrap
mimerender = MimeRender()
@philfreo
philfreo / closeio_rest_api.php
Last active March 18, 2019 14:34
POST HTTP request with JSON in PHP
$lead = array('name' => 'test');
$headers = array('Content-Type' => 'application/json');
$options = array('auth' => array('YOUR_API_KEY', ''));
$request = Requests::post('https://api.close.com/api/v1/lead/', $headers, json_encode($lead), $options);
<?php
/**
* Custom configuration bootsrtap file for ExpressionEngine
*
* Place config.php in your site root
* Add require(realpath(dirname(__FILE__) . '/../../config_bootstrap.php')); to the bottom of system/expressionengine/config/config.php
* Add require(realpath(dirname(__FILE__) . '/../../config_bootstrap.php')); to the bottom of system/expressionengine/config/database.php
* If you have moved your site root you'll need to update the require_once path
*
@philfreo
philfreo / stripe_rev.py
Last active December 17, 2015 03:28
Calculate how much active/current subscription revenue you have for all your Stripe customers, considering discounts, trials, etc.
from __future__ import division
import collections
from texttable import Texttable
by_status = collections.defaultdict(list)
per_page = 100
offset = 0
while True:
@philfreo
philfreo / gist:5752798
Created June 10, 2013 22:02
Notify you when the Apple Dev Center is back online
while true; do
curl --silent --head https://developer.apple.com/membercenter/ | grep --silent maintenance
if [ $? -eq 0 ]; then; break; fi
sleep 3
done
say "Apple Developer Center is Now Online";
@philfreo
philfreo / html2pdf.py
Created June 21, 2013 22:50
A Flask view that returns HTML or generates a PDF
import mimerender
mimerender.register_mime('pdf', ('application/pdf',))
mimerender = mimerender.FlaskMimeRender(global_charset='UTF-8')
def render_pdf(html):
from xhtml2pdf import pisa
from cStringIO import StringIO
pdf = StringIO()
pisa.CreatePDF(StringIO(html.encode('utf-8')), pdf)
@philfreo
philfreo / makepdf.js
Created June 24, 2013 23:21
PhantomJS: generate PDF to stdout from HTML in stdin. Example: echo "<b>test</b>" | phantomjs makepdf.js > test.pdf && open test.pdf
var page = require('webpage').create(),
fs = require('fs');
page.viewportSize = { width: 600, height: 600 };
page.paperSize = { format: 'Letter', orientation: 'portrait', margin: '1cm' };
page.content = fs.read('/dev/stdin');
window.setTimeout(function() {
page.render('/dev/stdout', { format: 'pdf' });