Skip to content

Instantly share code, notes, and snippets.

View josephabrahams's full-sized avatar

Joseph Abrahams josephabrahams

View GitHub Profile
josephabrahams /
Created October 25, 2019 17:07
Use λ to Fix CloudFront/S3 CORS Issues

Use Lambda to Fix CloudFront/S3 CORS Issues

If you use S3 to serve static assets, you're going to have to configure S3 to deal with CORS issues. Unfortuantly, S3 doesn't return Vary: Origin unless an Origin request header is present. This causes CORS issues for browsers like Chrome since the original cached response from the GET request will get reused for CORS evaluation due to the lack of Vary: Origin.

The solution is to use a Lambda@Edge function to add the correct response headers from S3.

Steps to set up Lambda/CloudFront/S3:

josephabrahams / composer.json
Last active March 20, 2019 20:35
WP Composer File
"type": "vcs",
"url": ""
josephabrahams / iframe.html
Last active December 18, 2018 17:57
Redirect parent window from an iframe action
<!doctype html>
<meta charset="utf-8">
<a href="" target="_top">Link</a>
josephabrahams /
Last active September 6, 2018 18:28
Setup Ubuntu on VirtualBox for C Development over SSH
# only require sudo password once during this script
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# remove need for typing sudo password in the future
echo -e "\nubuntu ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers
# allow access to vm shared folders
josephabrahams / external.conf
Last active July 19, 2018 22:21
Redirect Pi-hole home page when accessing from hostname
# /etc/lighttpd/external.conf
$HTTP["host"] == "pi.hole" {
# Ensure the Pi-hole Block Page knows that this is not a blocked domain
setenv.add-environment = ("fqdn" => "true")
# Redirect homepage to "/admin/"
$HTTP["url"] == "/" {
url.redirect = ( "" => "/admin/" )
josephabrahams /
Created July 19, 2018 20:35
Safely upgrade system dependencies
sudo apt-get update && \
sudo apt-get -y upgrade --with-new-pkgs && \
sudo apt-get -y autoremove && \
sudo apt-get -y autoclean
if [ -f /var/run/reboot-required ]; then
echo "Reboot required."
josephabrahams /
Created July 19, 2018 20:33
Safely reload nginx
sudo nginx -t && sudo nginx -s reload && echo "nginx: reload successful"
josephabrahams / certbot
Created July 16, 2018 03:11
Let's Encrypt cert update cron
# /etc/cron.d/certbot: crontab entries for the certbot package
# Upstream recommends attempting renewal twice a day
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
josephabrahams / s3-redirect-rule.xml
Created June 2, 2018 23:02
Redirect all requests from S3 bucket to another domain and strip the path.
josephabrahams /
Last active March 4, 2018 07:53
QSTK Mac Installation w/ Python 3

QSTK Mac Installation

Now with Python 3!

Install System Dependencies

brew install python
brew install pipenv
brew install gfortran