Skip to content

Instantly share code, notes, and snippets.

View josephabrahams's full-sized avatar

Joseph Abrahams josephabrahams

View GitHub Profile
@josephabrahams
josephabrahams / cloudfront_s3_cors.md
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
josephabrahams / composer.json
Last active March 20, 2019 20:35
WP Composer File
{
"repositories":[
{
"type":"composer",
"url":"https://wpackagist.org"
},
{
"type": "vcs",
"url": "https://github.com/__your_github_org__/acf-pro.git"
}
@josephabrahams
josephabrahams / iframe.html
Last active December 18, 2018 17:57
Redirect parent window from an iframe action
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Child</title>
</head>
<body>
<h1>Child</h1>
<a href="https://example.com/" target="_top">Link</a>
</body>
@josephabrahams
josephabrahams / c_init.sh
Last active September 6, 2018 18:28
Setup Ubuntu on VirtualBox for C Development over SSH
!/bin/sh
# 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
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
josephabrahams / aptupgrade.sh
Created July 19, 2018 20:35
Safely upgrade system dependencies
#!/bin/bash
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."
fi
@josephabrahams
josephabrahams / reloadnginx.sh
Created July 19, 2018 20:33
Safely reload nginx
#!/bin/bash
sudo nginx -t && sudo nginx -s reload && echo "nginx: reload successful"
@josephabrahams
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.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
AWS_CONFIG_FILE="/root/.aws/config"
@josephabrahams
josephabrahams / s3-redirect-rule.xml
Created June 2, 2018 23:02
Redirect all requests from S3 bucket to another domain and strip the path.
<RoutingRules>
<RoutingRule>
<Redirect>
<HostName>example.com</HostName>
<HttpRedirectCode>301</HttpRedirectCode>
<Protocol>https</Protocol>
<ReplaceKeyWith/>
</Redirect>
</RoutingRule>
</RoutingRules>
@josephabrahams
josephabrahams / QSTK-Mac-Installation.md
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