Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@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
@mttjohnson
mttjohnson / magento1_enterprise_index_diagnostics.sql
Last active November 9, 2017 19:53
Magento 1.x Enterprise Partial Indexing Diagnostics Toolset
-- When products are added/removed from a category this table stores all the relation data
select * from catalog_category_product where product_id = '24526';
-- The index that is used for presenting products in a category on the frontend
select * from catalog_category_product_index where product_id = '24526';
-- The change log table used for Magento EE partial index functionality
select * from catalog_category_product_index_cl where product_id = '24526' and version_id > (select version_id from enterprise_mview_metadata where changelog_name = 'catalog_category_product_index_cl');
@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 / 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:
@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

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

@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
# 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
@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,
@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}')