Skip to content

Instantly share code, notes, and snippets.

View mttjohnson's full-sized avatar

Matt Johnson mttjohnson

View GitHub Profile
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active July 18, 2024 07:57
Opening and closing an SSH tunnel in a shell script the smart way

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 / gist_search.md
Last active June 6, 2017 21:06
Gist User Search
@davidalger
davidalger / memory-usage-log.md
Created May 4, 2017 16:12
PHP Memory Usage Log

Setup memory log on php-fpm pool

  1. Added the following to /usr/local/lib/strangecode_php_memory_log.php

     <?php
     function strangecode_php_memory_log()
     {
         $current = memory_get_usage() / 1024 / 1024;
         $peak = memory_get_peak_usage() / 1024 / 1024;
    

$uri = $_SERVER['REQUEST_URI'] ?? 'n/a';

@davidalger
davidalger / phpinfo.php
Last active July 28, 2020 19:51
PHP Info with cache-control: private for busting varnish cache
<?php
header('Cache-Control: private');
phpinfo();
@gboudreau
gboudreau / AuthyToOtherAuthenticator.md
Last active July 22, 2024 17:46 — forked from Ingramz/AuthyToOtherAuthenticator.md
Export TOTP tokens from Authy
@CNanninga
CNanninga / magento2-clone-prod-to-stage.sh
Last active August 27, 2019 07:00
Magento 2 Production to Stage Clone
#!/bin/bash
SOURCE_DB_NAME="example_prod"
SOURCE_ROOT_DIR="/var/www/prod"
SOURCE_DUMP_FILENAME=example_prod_$(date +%F).sql.gz
TARGET_DB_NAME="example_stage"
TARGET_ROOT_DIR="/var/www/stage"
TARGET_SSH_USER="www-stage"
TARGET_SSH_HOST="stage.example.com"
@erikhansen
erikhansen / sync_prod_to_stage.sh
Last active November 11, 2022 23:31
Magento 2 script to push DB and `pub/media` changes from prod>stage
#!/bin/bash
# stop on errors
set -e
# turn on debugging if you're running into issues
#set -x
# Static variables
ENVIRONMENT=$1
RED='\033[0;31m'
NC='\033[0m' # No Color
@erikhansen
erikhansen / load_all_sitemap_urls.sh
Last active May 20, 2024 03:21
Load all urls from a sitemap.xml file
#!/bin/bash
# This script crawls all urls in a /sitemap.xml file and loads them, effectively priming the cache
# Usage: ./warm_cache.sh www.example.com
time wget --quiet https://$1/sitemap.xml --output-document - | \
egrep -o "https?://[^<]+" | \
grep $1 | \
grep -v "jpg" | \
xargs -i -d '\n' curl --output /dev/null --silent --write-out '%{http_code} %{time_total}ms %{url_effective} \n' {}
@perryholden
perryholden / dangerous_functions.php
Last active March 8, 2023 16:50
Test File or Folder for Dangerous PHP Functions
<?php
/**
* dangerous_functions.php
* Perry Holden <perry.holden@gmail.com>
*
* Usage: php dangerous_functions.php [type: folder|file] [folder_or_filename]
* Example: php dangerous_functions.php folder vendor/businessname/module-name
*/
if (!isset($argv[1])) {