Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@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}')

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@mttjohnson
mttjohnson / brew_vagrant_version.sh
Last active February 8, 2019 18:22
Installing older version of vagrant/ansible with brew
# You can find the current list of casks on github, and the one for vagrant here:
# https://github.com/Homebrew/homebrew-cask/blob/master/Casks/vagrant.rb
# From there you may be able to load the history of that file and lookup previous versions of
# the cask which would be related to previous versions of vagrant as indicated in the cask definition file.
# If the github history of the file fails you can search through recent commit history and find a commit prior
# to the version change you are trying to avoid and get the commit hash before the change and use it to locate
# a previous version of the cask file.
# current (master branch) casks:
@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
@LordZardeck
LordZardeck / Result.md
Last active February 13, 2018 19:27
Crazy feature I discovered in PHP. You can access protected properties of a instance if the method that's accessing those protected propteries exist on the same type of that instance, even if it's not the instance you are accessing from. Seems similar to C# nested types: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-an…

HasProtectedProperty

string(6) "foobar"

HasPrivateProperty

string(6) "barfoo"
@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')
@mttjohnson
mttjohnson / mock-varnish-backend-request.sh
Last active April 5, 2019 15:43
Mock Varnish Backend Request
# Consider filtering the varnishlog output
# https://feryn.eu/blog/varnishlog-measure-varnish-cache-performance/
varnishlog -i "RespHeader,Req*" -X "RespHeader:(x|X)-" -I "timestamp:Resp" -x reqprotocol,reqacct -g request
# Capture the log output from varnishlog and look for BereqHeader
# -n name is how you can specify a specific named instance of varnish
# remove -n if you just want to access the default instance
varnishlog -n stage
@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 / braintree_settlement.sh
Created November 29, 2016 23:22
Braintree manual transaction settlement
# Setup local directory with braintree example and libraries
git clone git@github.com:braintree/braintree_php_example.git
cd braintree_php_example
composer install
# Create and define configuration options
echo '
BT_ENVIRONMENT=sandbox
BT_MERCHANT_ID=xxxxxxxxxxxx
BT_PUBLIC_KEY=xxxxxxxxxxxx