Skip to content

Instantly share code, notes, and snippets.

View josephabrahams's full-sized avatar

Joseph Abrahams josephabrahams

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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: