Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil Freo philfreo

View GitHub Profile
View README.md

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

In Raspberry Pi, create a docker-compose.yml file grabbed from here: https://github.com/pi-hole/docker-pi-hole/#quick-start. 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
philfreo / README.md
Created Feb 3, 2020
Lambda@Edge function for setting HSTS header for Cloudfront+S3 sites
View README.md

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

@philfreo
philfreo / README.md
Last active Feb 3, 2020
Lambda@Edge Dynamic Redirect Example
View README.md

Server-side Redirects

See redirects.json to define or update redirects.

Redirects format

Example for redirects.json

{
@philfreo
philfreo / _Homebridge Docker Raspberry Pi Setup.md
Last active Dec 28, 2019
Homebridge Docker Raspberry Pi Setup
View _Homebridge Docker Raspberry Pi Setup.md

Overview

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
philfreo / wealthfront_accounts.js
Last active Dec 18, 2019
Wealthfront Accounts List
View wealthfront_accounts.js
javascript:
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) => {
x.remove()
});
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;
accountsData.push([
@philfreo
philfreo / windows_on_macos.md
Created Nov 14, 2019
Testing on Windows from macOS
View windows_on_macos.md
  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)
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 Sep 10, 2020
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/*
You can’t perform that action at this time.