Skip to content

Instantly share code, notes, and snippets.

Phil Freo philfreo

Block or report user

Report or block philfreo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ocr-shot.sh
#!/bin/bash
set -e
CONTENTS=$(tesseract -c language_model_penalty_non_dict_word=0.8 --tessdata-dir /usr/local/share/ "$1" stdout -l eng | xml esc)
hex=$((cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@philfreo
philfreo / png.js
Created May 30, 2017
PhantomJS program to generate a PNG based on stdin (e.g. SVG image)
View png.js
// 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 Jun 30, 2019
Three ways to make a PDF from HTML in Python (preferred is weasyprint or phantomjs)
View 1_pdf.py
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 Sep 18, 2018
test dockerfile syntax highlighting
View Dockerfile
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 Apr 8, 2018
Make Dash button play iTunes to AirPlay speakers
View _README.md

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 Jul 31, 2018
AWS User script to bootstrap any instance
View bootstrap_instance.sh
#!/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 Mar 5, 2016
Detect if a File is a certain type based on its file signature in JavaScript
View filevalidator.js
define([
'underscore',
],
function(_) {
'use strict';
// https://en.wikipedia.org/wiki/List_of_file_signatures
var fileSignatures = {
'mp3': [
@philfreo
philfreo / rollbar.py
Last active Oct 17, 2015
Python/Flask+Rollbar as logger handler + structlog support
View rollbar.py
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 Aug 31, 2015
See what local processes are listening on any IP address
View listening.sh
netstat -na | grep LISTEN | grep -v 127.0.0.1 | grep -v ::1
@philfreo
philfreo / guide.md
Created Aug 4, 2015
Close.io API Getting Started Guide
View guide.md

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
You can’t perform that action at this time.