Skip to content

Instantly share code, notes, and snippets.


Phil Freo philfreo

View GitHub Profile
philfreo /
Last active May 25, 2021
Segment Integration JS

If you're interested in a Close Segment Destination, please email We're actively working on a Segment integration and are looking for testers in the near future. If you need something immediately you can try writing code in Functions using the code below as a starting point.

philfreo / 1. Segment Google Analytics
Last active Sep 29, 2021
Segment workaround due to their incorrect Google Analytics server-side integration
View 1. Segment Google Analytics



If you use Segment's Google Analytics server-side integrations, even if you follow all of their documentation / recommendation, it is impossible to properly track your visitors/sessions in GA from anonymous through identified.

This means that if you use Segment like this, you cannot do very basic things in GA like understanding attribution of your product's sign ups. In GA, a brand new session is created for the identified users, which is not correct.

This problem applies to using Segment on the web with analytics.js when the Google Analytics Destination is set to Cloud Mode, or when using a true server-side Source such as Python/Ruby/Node.

philfreo / readme.sql
Last active Nov 20, 2020
Stripe Sigma: Year revenue by country
View readme.sql
-- breakdown revenue per country
-- we store billing address only in the Charge object
-- NOTE this is rough and there are 2 different country columns to consider here
-- transactions table is what we want since we can sum it all up and that will subtract out refunds
-- however we have to join to each Source separately so we can pull out the charge_id for all types of transactions
-- because the charge is what we need for the address, since it doesn't exist on the Customer, nor on the e.g. refund

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 Aug 23, 2021
Wealthfront Accounts List
View wealthfront_accounts.js
document.querySelectorAll('.dashboard-path-global-graph-component,header,.dashboard-path-container-component,.dashboard-loan-card-component,.dashboard-global-sidebar-component,footer,.dashboard-external-account-external-account-card-component-action-links-container,[data-testid=autopilot-learn-more],[aria-label="Link an account"],[data-testid="add-an-account-btn"]').forEach((x) => {
accountsData = [];
document.querySelectorAll('.dashboard-external-account-external-account-card-component,.dashboard-wealthfront-account-card-component').forEach((acct) => {
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">