Skip to content

Instantly share code, notes, and snippets.

View philfreo's full-sized avatar

Phil Freo philfreo

View GitHub Profile
@philfreo
philfreo / windows_on_macos.md
Created November 14, 2019 21:38
Testing on Windows from macOS
  1. Download & install VirtualBox for OS X
  2. Acquire a Windows 10 environment. Easiest way:
    • Use a maintained fork of ievms, like this:
    • curl -s https://raw.githubusercontent.com/amichaelparker/ievms/master/ievms-node.sh | env IEVMS_VERSIONS="EDGE" bash
  3. Start Windows instance in VirtualBox.
  4. The password for the default Windows IEUser is Passw0rd! (mentioned here)
#!/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 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