Skip to content

Instantly share code, notes, and snippets.

View anthumchris's full-sized avatar
🎶
learning Ableton Live

anthumchris

🎶
learning Ableton Live
  • Colorado, United States
View GitHub Profile
@anthumchris
anthumchris / validate-permissions.js
Created June 9, 2022 20:55
Validate AWS Policy Action Permissions for IAM User or Role
/* This NodeJS script tests IAM Policy Actions for yourself or a specific PolicySourceArn user/role.
*
* https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/configuring-the-jssdk.html
*/
import AWS from 'aws-sdk' // $ npm i -D aws-sdk@2
const iam = new AWS.IAM()
const sts = new AWS.STS()
@anthumchris
anthumchris / Greeting.js
Last active May 3, 2023 11:16
Use Webpack 5 and Babel 7 to create JavaScript bundle for Internet Explorer 11 (IE11, IE 11)
export default 'Hello!'
@anthumchris
anthumchris / gist:ee5355fcdecb9fd93e3d07227a2880a0
Created November 14, 2020 16:43
toggle oscillator playback
<html>
<head>
<style>body { padding: 4rem; text-align: center; }</style>
<script>
/* Parentheses may be needed to instantiate: `audioCtx = new (OBJECT)()`<br />
* Oscillator waveform may need explicit definition: `osc.type = 'sine'`
*/
var audioCtx = null
var isPlaying = false
@anthumchris
anthumchris / app.jsx
Created August 6, 2020 19:37
i18n Pattern
// Devs can easily use English strings that will be translated if necessary
function DeleteButton() {
function prompt() {
alert(intl('Are you sure you want to delete gateway?'))
}
return(
<button onclick={prompt}>
{intl('Delete Gateway')}
</button>
@anthumchris
anthumchris / README.md
Last active September 25, 2022 19:04
Clear Nginx Cache

Clearing Nginx's HTTP Cache

I recently implemented Nginx HTTP content caching on our WordPress web servers to improve page load speeds and eliminate redundant, unneeded server-side page rendering. Caching the pages was relatively straightforward, but clearing the cache required a custom workaround.

Nginx comes in two versions: free and “Nginx Plus” at $2,500/year. The free version of Nginx does not offer the needed cache-clearing features of Nginx Plus, and I wasn’t comfortable paying $20,000 for 8 instances without trying to build my own solution.

Our Nginx servers run as an HTTP proxy for multiple PHP/MySQL-backed WordPress sites. The goal was to cache the dynamic PHP HTML responses in Nginx and serve the HTML pages from Nginx to avoid redundant, CPU-intensive PHP renders.

Site Cache Configuration

The example below shows how PHP response caching is configured for a site (other nginx configuration details are excluded for brevity). A cache named cachedemo-prod is defined to store cached HTML f

@anthumchris
anthumchris / build.sh
Last active July 3, 2021 02:56
Emscripten WebAssembly Module.ready Promise initialization similar to Module.onRuntimeInitialized
#!/bin/bash
emcc \
-O0 `# leave uncompressed for example` \
-s WASM=1 \
-s EXPORTED_FUNCTIONS="['_hello']" \
-s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap']" \
-o emscripten-module.js \
--post-js module-post.js \
hello.c
/* To test, initiate the fetch() and interrupt your network conneciton
* (e.g. turn off wireless). The originating ReadableStreamDefaultReader.read()
* error is lost and unavailable to application's outermost Promise.reject catch()
*/
fetch('https://fetch-progress.anthum.com/10kbps/images/sunrise-baseline.jpg')
.then(response => {
const reader = response.body.getReader();
return new Response(
new ReadableStream({
@anthumchris
anthumchris / custom-fetch-response-reader.js
Last active March 13, 2018 13:45
Custom Fetch Response Stream Reader
fetch('the-best-song-ever.mp3')
.then(response => {
if (!response.body) {
throw Error("ReadableStream is not yet supported in this browser. See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream")
return response;
}
const reader = response.body.getReader();
read()
@anthumchris
anthumchris / post-receive
Last active March 29, 2017 18:25
Git Push to Deploy — Instantly deploy your local Git repository to your remote web server
#/bin/bash
# This script will push your local repository's latest commit to a remote repository on your server.
# It's useful for quickly pushing your local changes to deployment servers (Dev, Stage, Prod/Live, etc.)
#
# This file should be placed in your remote server's project's git hooks folder and named .git/hooks/post-receive.
# Security reminder: Your web server should not allow access to the /.git folder URL
#
# Ensure that this script is executable:
# $ chmod +x .git/hooks/post-receive
@anthumchris
anthumchris / nginx-dynamic-subdomains.conf
Last active February 27, 2018 13:37
Dynamically route subdomains to respective subdomain folders
server {
listen 80;
listen [::]:80;
server_name ~^(?<subdomain>\w+).dynamic.domain.com;
root /var/www/vhost/_dynamic/$subdomain;
access_log /var/log/nginx/dynamic-access.log;
error_log /var/log/nginx/dynamic-error.log;