Skip to content

Instantly share code, notes, and snippets.

View philfreo's full-sized avatar

Phil Freo philfreo

View GitHub Profile
@philfreo
philfreo / png.js
Created May 30, 2017 23:21
PhantomJS program to generate a PNG based on stdin (e.g. SVG image)
// PhantomJS program to generate a PNG based on stdin (e.g. SVG image)
// Example: curl http://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg | phantomjs png.js > test.png && open test.png
/*
From Flask/Python:
import os
from subprocess import Popen, PIPE, STDOUT
p = Popen(['phantomjs', '%s/png.js' % os.path.dirname(os.path.realpath(__file__))], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
out = p.communicate(input=svg.encode('utf-8'))[0]
strIO = StringIO.StringIO()
strIO.write(out)
@philfreo
philfreo / 1_pdf.py
Last active January 30, 2024 16:20
Three ways to make a PDF from HTML in Python (preferred is weasyprint or phantomjs)
def render_pdf_weasyprint(html):
from weasyprint import HTML
pdf = HTML(string=html.encode('utf-8'))
return pdf.write_pdf()
def render_pdf_xhtml2pdf(html):
"""mimerender helper to render a PDF from HTML using xhtml2pdf.
Usage: http://philfreo.com/blog/render-a-pdf-from-html-using-xhtml2pdf-and-mimerender-in-flask/
"""
@philfreo
philfreo / Dockerfile
Last active September 16, 2022 19:34
test dockerfile syntax highlighting
FROM ubuntu:14.04.5
#Install newer version of Python 2.7
RUN DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:fkrull/deadsnakes-python2.7 && apt-get update \
&& apt-get install -y python2.7=2.7.12-1~trusty1 && rm -rf /var/lib/apt/lists/*
@philfreo
philfreo / _README.md
Last active April 8, 2018 06:42
Make Dash button play iTunes to AirPlay speakers

Uses a (basically free) Amazon Dash Button to play/pause your iTunes music over AirPlay speakers.

Requires OS X and an AirPlay compatible speaker (e.g. Apple TV or any speaker hooked up to AirPort Express).

  1. Install node-dash-button and follow the instructions to get your Dash Button's MAC address.
  2. Install node-applescript
  3. Tweak code as desired, filling in your button's MAC address, name of your AirPlay speakers, etc.
  4. Run via Terminal: node dash_buttons.js
@philfreo
philfreo / bootstrap_instance.sh
Last active March 26, 2020 03:42
AWS User script to bootstrap any instance
#!/bin/bash -x
# User script to bootstrap any instance.
# This will set up, array, and format every instance storage
# drive present in the instance (if any)
#
# The disk format/layout is read from an EC2 tag "DiskLayout"
# (defined in the cloudformation templates) and it defaults to
# "raid0". Possible values are:
# * raidN: grabs all available instance storage drives, creates a
@philfreo
philfreo / filevalidator.js
Created March 5, 2016 02:37
Detect if a File is a certain type based on its file signature in JavaScript
define([
'underscore',
],
function(_) {
'use strict';
// https://en.wikipedia.org/wiki/List_of_file_signatures
var fileSignatures = {
'mp3': [
@philfreo
philfreo / rollbar.py
Last active October 17, 2015 01:14
Python/Flask+Rollbar as logger handler + structlog support
class StructlogRollbarHandler(RollbarHandler):
def __init__(self, prefix, *args, **kwargs):
self.prefix = prefix
super(StructlogRollbarHandler, self).__init__(*args, **kwargs)
def format_title(self, data):
# Keys used to construct the title and for grouping purposes.
KEYS = ['event', 'func', 'exception_name', 'queue']
def format_field(field, value):
@philfreo
philfreo / listening.sh
Created August 31, 2015 04:59
See what local processes are listening on any IP address
netstat -na | grep LISTEN | grep -v 127.0.0.1 | grep -v ::1
@philfreo
philfreo / guide.md
Created August 4, 2015 23:35
Close.io API Getting Started Guide

Getting Started with the Close.io API

The Close.io API allows you to connect your app or service directly to your data in Close.io to search your existing leads, add new leads, and much more. In this guide, we're going to look at a couple of examples of how to accomplish some basic tasks using the API so that you can get started integrating Close.io into your current apps and workflows.

General API Information

Base URL

https://app.close.io/api/v1
@philfreo
philfreo / README.md
Last active August 8, 2016 02:29
SSL CSR & localhost self-signing

Generate a CSR for production use:

openssl req -nodes -newkey rsa:2048 -sha256 -keyout mysite-ssl.private-key.pem -out mysite-ssl.csr -subj '/C=US/ST=California/L=Palo Alto/O=My Company Inc./CN=*.example.com'

Generate a long-lasting self-signed cert & trust it for localhost development usage:

openssl req -nodes -newkey rsa:2048 -sha256 -x509 -days 3650 -keyout selfsigned.key -out selfsigned.crt -subj '/C=US/ST=Anywhere/L=Anywhere/O=Localhost/CN=local.example.com'