Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / info.php
Last active May 20, 2019 21:14 — forked from davidalger/phpinfo.php
PHP Info (phpinfo) - With header to bypass varnish caching
<?php
header('Cache-Control: private');
phpinfo();
@mttjohnson
mttjohnson / m2_rest_api_snippets.sh
Last active August 26, 2021 19:37
Examples of Magento 2 REST API calls with curl
# Install jq on Mac
brew install jq
brew install oath-toolkit
# Install Perl module from CPAN
perl -MCPAN -e 'install URI::Escape'
@mttjohnson
mttjohnson / n.sh
Last active February 25, 2020 10:05 — forked from dagelf/n.sh
Linux network interface throughput speed
#!/bin/sh
# Forked from https://gist.github.com/dagelf/ab2bad26ce96fa8d79b0834cd8cab549
# With modifications for including timestamp and reporting in Megabits/s instead of Kilobytes/s
#
# To run: ./n.sh em1
SLP=60 # display / sleep interval
DEVICE=$1
IS_GOOD=0
for GOOD_DEVICE in `grep \: /proc/net/dev | awk -F: '{print $1}'`; do
@mttjohnson
mttjohnson / redis_activity_monitoring.sh
Last active February 25, 2020 10:05
Redis Activity Monitoring
# Poll for various system stats for monitoring system
# Just copy and paste the commands into a bash prompt
# Use Ctrl-C to exit the polling
# Defaults that can be overriden
[[ -z "$REDIS_CONN" ]] && REDIS_CONN="-h 127.0.0.1 -p 6379"
[[ -z "$SLEEP_SECONDS" ]] && SLEEP_SECONDS=60
# Header info
CUR_TIME='timestamp'
@mttjohnson
mttjohnson / code_pipe_to_php.sh
Created September 13, 2018 15:54
Setting code in bash variable and piping to php
# This fails the variable assignment because of the single quotes and spaces
# and with this method single quotes have to be escaped
PHP_CODE="initialized"
PHP_CODE='<?php
print 'hello ';
print "world!";
print "\n";
'
echo "${PHP_CODE}" | php
@mttjohnson
mttjohnson / elasticsearch_explore.sh
Last active September 21, 2021 19:07
ElasticSearch Exploration
# ElasticSearch Documentation
# https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html
# Initialize some variables
ES_HOST="localhost"
ES_PORT="9200"
ES_USER="elastic"
ES_PASS="changeme"
# System Info
@mttjohnson
mttjohnson / nginx_phpfpm_status_override_with_location.php
Created August 2, 2018 21:12
Overriding HTTP Status Code when Location Header Exists with Nginx and PHP-FPM
<?php
$status_code = "200";
$reason_phrase = "OK";
# Status of responses including a Location header: 201, 301, 302, 303, 307, 308.
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location
# https://tools.ietf.org/html/rfc2616#section-14.30
# Nginx interprets CGI response headers differently than Apache and if a location
# header is found in a response not containing a standard status code it will override
@mttjohnson
mttjohnson / mysql_over_ssh_tunnel.php
Created July 25, 2018 04:02
Establishing an SSH Tunnel and Connecting to MySQL with PHP
<?php
$ssh_host = "1.2.3.4";
$ssh_user = "my_ssh_username";
$ssh_tunnel_local_port = "3307";
$ssh_tunnel_remote_host = "127.0.0.1"; # DB Server IP on the remote network if not local to the remote system
$ssh_tunnel_remote_port = "3306";
$local_mysql_host = "127.0.0.1";
$mysql_user = "my_mysql_username";
$mysql_pass = "my_secret_password";
$mysql_db_name = "my_database_name";
@mttjohnson
mttjohnson / waitforssh
Created July 3, 2018 18:41
David's waitforssh shell script
#!/bin/sh
ssh $1
while test $? -gt 0
do
sleep 5 # highly recommended - if it's in your local network, it can try an awful lot pretty quick...
echo "Trying again..."
ssh $1
done
@mttjohnson
mttjohnson / bash_array_sort.sh
Created July 2, 2018 20:10
Bash Array Sort - Percentage distribution of total quantity among array elements
declare THREADS_TOTAL=4 # 600
declare TEST_SCENARIO_PER_BROWSE="25" # 90
declare TEST_SCENARIO_PER_ABANDONED_CART="25" # 5
declare TEST_SCENARIO_PER_CHECKOUT_GUEST="25" # 3
declare TEST_SCENARIO_PER_CHECKOUT_CUSTOMER="25" # 2
############################################################
# Thread distribution calculation and validity checks
############################################################