Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@rchrd2
rchrd2 / test-php-basic-auth.php
Last active February 1, 2024 21:18 — forked from westonruter/test-php-basic-auth.php
PHP basic auth example
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
@mttjohnson
mttjohnson / test_http_redirects.sh
Last active January 31, 2024 22:31
Testing HTTP Redirects
# The check_url recursive function
check_url() {
THIS_URL="${1}"
HTTP_RESP_CODE=$(curl -ksI "${THIS_URL}" | grep -i 'HTTP/' | cut -d' ' -f 2)
echo "${THIS_URL} -> ${HTTP_RESP_CODE}"
if [ "${HTTP_RESP_CODE}" == "301" ] || [ "${HTTP_RESP_CODE}" == "302" ]
then
HTTP_LOC=$(curl -ksI ${1} | grep -i 'Location: ' | cut -d'_' -f 2)
HTTP_REDIRECT=$(echo "${HTTP_LOC}" | tail -c +11 | tr -d '\r' | tr -d '\n')
@twksos
twksos / CiscoVPNConnection.scpt
Last active July 31, 2023 20:50
Cisco VPN connection auto connect AppleScript
-- Please set your vpn connection name and password here
set VPNName to "VPN name"
set VPNpassword to "VPN password"
tell application "System Events"
tell current location of network preferences
set VPNService to service VPNName
end tell
set isConnected to connected of current configuration of VPNService
@adgedenkers
adgedenkers / vpn_connection.scpt
Created October 11, 2012 18:16
Toggle Connection to VPN on a Mac via AppleScript
tell application "System Events"
-- get current clipboard contents as a string
set CurrentClipboard to the clipboard as string
-- set the clipboad to your password
set the clipboard to "Y0urVPNPa$$w0rd"
-- start playing with the VPN
tell current location of network preferences
@nvahalik
nvahalik / custom google apps scripts for tech sales
Last active June 16, 2022 06:17
Some Google Apps Script functions for Spreadsheets which might be useful for those in Technical Sales or software development. They can be used to add up and manipulate hour ranges (e.g. SUMRANGE(["1-2",2,"2-5"]) would yield "5-9"). Those functions are SUMRANGE, SUMRANGEHIGH, SUMRANGELOW, RANGEMULT, and RANGEADD. There are also some functions wh…
/* Grab the values and make them globally available. */
var hoursPerDay = 8;
var hoursPerWeek = hoursPerDay * 5;
/**
* We calculate the number of hours in a given range.
*/
function SUMTIME(allData) {
var numHours = 0;
var numCells = allData.length;
@mttjohnson
mttjohnson / arduino_student_kit_class.md
Last active April 10, 2022 20:52
Intro to Programming and Electronics - Sycamore Club Class

Intro to Programming and Electronics - Sycamore Club Class

Arduino Student Kit February-April 2022 lead by Matt Johnson

Intro Description

Arduino Student Kit

@davidalger
davidalger / warmer-cron.sh
Last active April 29, 2021 08:31
Script to crawl and warm the cache two levels deep on Magento demo Pods via CronJob spec
#!/bin/bash
set -euo pipefail
FRONT_URL="${FRONT_URL:-https://app.exampleproject.test/}"
echo "==> [$(date +%H:%M:%S)] waiting on readiness"
ELAPSED_SECONDS=0
while : ; do
ELAPSED_SECONDS=$(echo ${ELAPSED_SECONDS}+2 | bc)
RESPONSE_CODE=$(curl -sI "${FRONT_URL}" 2>/dev/null | head -n1 | awk '{print $2}')
@mttjohnson
mttjohnson / mysql_size_info.sql
Last active April 29, 2021 08:30
MySQL data usage queries
/*
# Get size of a specific database into a bash variable for use in estimating mysqldump size for pv status bar
DATABASE_NAME="example_db_name"
DATABASE_SIZE=$(mysql --batch -sN -e "SELECT CONCAT(ROUND(sum( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 0), 'g') as size FROM information_schema.TABLES WHERE table_schema = '${DATABASE_NAME}' GROUP BY table_schema;")
echo "${DATABASE_SIZE}"
*/
/* find the largest tables on the server */
SELECT CONCAT(table_schema, '.', table_name) 'db.table',
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
# clear the entire cache
varnishadm "ban req.url ~ /"
# monitor varnish stats
varnishstat -n prod
# monitor varnish log with multiple patterns
varnishlog | grep 'eqURL\|Age:\|VCL_call\|TTL\|Expires:\|Cache-Control:'
# Use a query with varnishlog to watch requests from a specific IP
@ericthehacker
ericthehacker / install-source-guardian-php70.sh
Last active October 16, 2019 19:34
Install source guardian on web70 VM
#!/bin/bash
# This quick and dirty script installs the Source Guardian loader on the web70 VM.
# Similar commands should work on other version of PHP -- simply replace the .lin file copied and the .ini file with the correct version.
cd /tmp
wget https://www.sourceguardian.com/loaders/download/loaders.linux-x86_64.tar.gz -O ./source-guardian.tgz
mkdir source-guardian