Skip to content

Instantly share code, notes, and snippets.


Phil Freo philfreo

View GitHub Profile

Pi-Hole setup with Docker on Raspberry Pi and Ubiquiti USG

In Raspberry Pi, create a docker-compose.yml file grabbed from here: Tweak timezone.

Then I went to http://rpi.local and saw a Pi-Hole message.

Then I saw that I could login to rpi.local/admin with the password found from sudo docker-compose logs pihole

In Pi-Hole Admin:

  • Settings > DNS
philfreo /
Created Feb 3, 2020
Lambda@Edge function for setting HSTS header for Cloudfront+S3 sites

Set this up as an "Origin Response" Cloudfront Trigger.

philfreo /
Last active Feb 3, 2020
Lambda@Edge Dynamic Redirect Example

Server-side Redirects

See redirects.json to define or update redirects.

Redirects format

Example for redirects.json

philfreo / _Homebridge Docker Raspberry Pi
Last active Dec 28, 2019
Homebridge Docker Raspberry Pi Setup
View _Homebridge Docker Raspberry Pi


Setup Homebridge to run via Docker on a Raspberry Pi.

Assume source of truth for files is on laptop, and you want to "deploy" them to Pi upon changes.

One-time setup

  • In this directory, rename config.tpl.json to config.json for Homebridge (bigger sample here) and change the username and pin to something unique).
  • Add any Homebridge plugins to package.json and config.json
philfreo / wealthfront_accounts.js
Last active Dec 18, 2019
Wealthfront Accounts List
View wealthfront_accounts.js
document.querySelectorAll('header,.dashboard-path-container-component,.dashboard-loan-card-component,.dashboard-global-sidebar-component,footer,.dashboard-external-account-external-account-card-component-action-links-container').forEach((x) => {
accountsData = [];
document.querySelectorAll('.dashboard-external-account-external-account-card-component,.dashboard-wealthfront-account-card-component').forEach((acct) => {
const category = acct.parentElement.querySelector('.dashboard-external-account-account-group-component-title').innerText;
let value = parseFloat(acct.querySelector('.dashboard-external-account-external-account-card-component-account-value,.dashboard-wealthfront-account-card-component-account-value').innerText.substr(1).replace(',', ''), 10);
if (category === 'Liabilities') value *= -1;
philfreo /
Created Nov 14, 2019
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 | env IEVMS_VERSIONS="EDGE" bash
  3. Start Windows instance in VirtualBox.
  4. The password for the default Windows IEUser is Passw0rd! (mentioned here)
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" "">
<plist version="1.0">
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 | 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()
philfreo /
Last active Sep 10, 2020
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.
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/*
You can’t perform that action at this time.