Skip to content

Instantly share code, notes, and snippets.

View quinncomendant's full-sized avatar

Quinn Comendant quinncomendant

View GitHub Profile
@quinncomendant
quinncomendant / post-receive
Last active May 13, 2023 05:14
Use this script as `deploy.git/hooks/post-receive` in a bare git repo (`git init --bare`) on a server to deploy application files with, e.g., `git push deploy-production main`.
#!/usr/bin/env bash
#
# git post-receive hook to deploy releases via git push.
#
# @see https://gist.github.com/quinncomendant/6605356f8e5db92e657902303f10aaf3
# @author Quinn Comendant <quinn@strangecode.com>
# @version 2023-05-12
# Config
sitedir="/path/to/deploy/location";
@quinncomendant
quinncomendant / install-dnscrypt-proxy.md
Last active March 3, 2023 01:42
Instructions to install dnscrypt-proxy via Homebrew on macOS

Prevent DNS leaks on macOS by using dnscrypt-proxy. dnscrypt-proxy is available for installation via Homebrew, and comes configured to use OpenDNS servers. After installing, dnscrypt-proxy will always run in the background and encrypt all your DNS queries:

  1. Open Terminal.app (press Command+Space and type terminal and hit return).
  2. If you don't already have Homebrew installed, install it by copy–pasting the following line in Terminal app and press enter/return key. Wait for the command to finish.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install dnscrypt-proxy by running:
brew install dnscrypt-proxy
@quinncomendant
quinncomendant / cpu-threshold-alert-microsoft-edge
Last active September 18, 2022 14:40
Detect if Microsoft Edge has been using more than 90% CPU continuously.
#!/usr/bin/env bash
# Microsoft Edge on macOS sometimes will get stuck using 100% CPU endlessly, requiring a relaunch to stop.
# See issue at https://techcommunity.microsoft.com/t5/discussions/edge-browser-100-cpu-requires-force-quit-macos-mojave-and-v91-0/m-p/2441462/highlight/true#M48074
#
# This script will display a macOS notification if Microsoft Edge has been using more
# than 90% CPU continuously for more than 10 minutes. It only checks the main
# Microsoft Edge process, not the Microsoft Edge Helper processes.
#
# Save it to ~/bin/cpu-threshold-alert-microsoft-edge
@quinncomendant
quinncomendant / .htaccess for WP subdirectory installation
Last active September 12, 2022 03:22
This .htaccess file works with Wordpress installed under a subdirectory wp/ inside the document root.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Make the admin still accessible from /wp-admin
RewriteCond %{REQUEST_URI} ^/wp-admin/?(.*)
RewriteRule .* wp/wp-admin/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^/wp/?$
RewriteRule .* wp/wp-admin/ [L,R=301]
# Base is the URL path of the home directory
RewriteBase /
@quinncomendant
quinncomendant / umbrella
Last active May 13, 2022 06:52
[WARNING: this script no longer works with newer versions of the roaming client software, which now has a *Disable* control in its menu so use that instead.] Cisco Umbrella Roaming Client management script for Mac OS X. This makes it easy to manage the background processes of umbrella to start, stop, restart, sleep and get status.
#!/bin/bash
# Quinn Comendant <quinn@strangecode.com>
# https://gist.github.com/quinncomendant/3be731567e529415d5ee
# Since 25 Jan 2015
# Version 1.2.2
# q 13942 0.0 0.3 4408332 22096 ?? SN 7:32PM 0:00.27 /Applications/OpenDNS Roaming Client/RoamingClientMenubar.app/Contents/MacOS/RoamingClientMenubar
# nobody 13937 0.0 0.1 4296740 5164 ?? Ss 7:31PM 0:00.06 /usr/local/sbin/dnscrypt-proxy --user nobody --local-address=127.0.0.1:53 --plugin=libdcplugin_erc.so -d
# root 13903 0.0 0.2 4366308 13752 ?? SNs 7:31PM 0:00.25 /Library/Application Support/OpenDNS Roaming Client/dns-updater
@quinncomendant
quinncomendant / dns.sh
Last active February 21, 2022 22:22
Manage cloud DNS services on the command line. A wrapper for DNS provider API tools (denominator, lexicon).
#!/usr/bin/env bash
#
# Quinn Comendant <quinn@strangecode.com>
# 06 Aug 2015 17:51:37
#
# Config
#
set -euo pipefail;
<?php
/*
* Set timezone used internally by PHP. See full list at https://www.php.net/manual/en/timezones.php
*
* @access public
* @param string $tz Timezone, e.g., America/Mexico_City
* @return
* @author Quinn Comendant <quinn@strangecode.com>
* @since 28 Jan 2019 16:38:38
@quinncomendant
quinncomendant / convert-hms-to-s.php
Created November 2, 2021 19:02
Convert Period of Time values (e.g., 1h15m30s) to seconds. Converts all values in stdin and sends to stdout.
#!/usr/bin/php
<?php
$content = trim(file_get_contents('php://stdin', 'r'));
preg_match_all('/\b((?:[\d]+h)?(?:[\d]+m)?(?:[\d]+s))\b/i', $content, $matches, PREG_PATTERN_ORDER);
foreach ($matches[1] as $PTtime) {
$start = new DateTime();
$end = clone $start;
$end->add(new DateInterval(sprintf('PT%s', strtoupper($PTtime))));
$elapsed = $end->getTimestamp() - $start->getTimestamp();
$content = preg_replace(sprintf('/\b%s\b/', $PTtime), $elapsed, $content);
@quinncomendant
quinncomendant / chrome-webstore-dl.sh
Created February 13, 2021 00:16
Downloads a chrome extension matching ExtensionID to ~/src/chrome-webstore-{ExtensionID}
#!/usr/bin/env bash
#
# Quinn Comendant <quinn@strangecode.com>
# 29 Sep 2017 16:09:21
#
# Functions
#
@quinncomendant
quinncomendant / Autosave.js
Created September 3, 2019 07:55
Autosave module makes it easy to save and load form values in localStorage.
//
// Maintain state of form values across page loads with localStorage.
//
// eslint-disable-next-line no-unused-vars
var Autosave = (function ($) {
'use strict';
//
// Options
//