Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / rsync_examples.sh
Last active April 13, 2021 15:33
rsync examples (two remotes)
# rsync with sudo
rsync -av \
--rsync-path="sudo -u www-data rsync" \
-e 'ssh -o StrictHostKeyChecking=no' \
path_to_local_data/ [email protected]:/var/www/
# If you wanted to build an exclusion list from a list of files in a directory
# This was useful when trying to sync a list of files but exclude a list of default installed
# so that the destination only contained the differences of what was added that wasn't a part
@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,
@mttjohnson
mttjohnson / wp_create_user.sql
Created May 19, 2016 04:01
create wordpress user from sql
SET @user_login := 'mjohnson';
SET @user_pass := 'securePassword';
SET @user_email := '[email protected]';
INSERT INTO `wp_users`
(`user_login`, `user_pass`, `user_email`, `user_registered`)
VALUES
(@user_login, MD5(@user_pass), @user_email, now());
SELECT @user_id := LAST_INSERT_ID();
INSERT INTO `wp_usermeta`
(`user_id`, `meta_key`, `meta_value`)
@mttjohnson
mttjohnson / remove-php-memory-limit.sh
Last active February 25, 2020 12:09
Composer Memory Limit Issue
# Temporarily remove php memory limit when running composer from the commmand line
php -dmemory_limit=-1 /usr/local/bin/composer ...
# Run with explicitly defined list of extensions to avoid xdebug
php -n \
-dextension=bcmath.so \
-dextension=bz2.so \
-dextension=calendar.so \
-dextension=ctype.so \
@mttjohnson
mttjohnson / xdebug_notes.txt
Last active July 17, 2019 21:43
xdebug command line enable
# to turn on the remote debugger pass in a config flag to automatically start it
php -d xdebug.remote_autostart=On ...
# just make sure your debugger is referencing the same path as the path of the file you are executing
# for remote debugging, these options should exist in your xdebug.ini file
xdebug.remote_enable = on
xdebug.remote_host = 127.0.0.1
@mttjohnson
mttjohnson / ssl_certificate_validation.sh
Last active October 17, 2023 16:01
SSL Certificate Validation
# Verify SSL
ssl_domain=mydomainnametotest.com
openssl rsa -noout -modulus -in $ssl_domain.key | openssl md5
openssl req -noout -modulus -in $ssl_domain.csr | openssl md5
openssl x509 -noout -modulus -in $ssl_domain.crt | openssl md5
# Output text of certificate
openssl x509 -text -in /etc/nginx/ssl/$ssl_domain.crt
# Get details of all certs in .crt bundle file to verify certificate chain
@mttjohnson
mttjohnson / awk examples
Created September 16, 2016 16:11
awk examples
# recursively search for files that have pattern in them, then list the filename and line number where found
find . -type f -exec awk '/\$store_code/ {printf "%d:", FNR; print FILENAME}' {} +
@mttjohnson
mttjohnson / cap_deploy_commit.sh
Created October 10, 2016 16:21
Capistrano deploy specific commit
stage.rb
set :branch, ENV['BRANCH'] || 'develop'
BRANCH=074e9eb--entire-commit-has-in-this-branch-variable--cab54fcc2fde8b bundle exec cap stage deploy
@mttjohnson
mttjohnson / gist_search.md
Last active June 6, 2017 21:06
Gist User Search
@mttjohnson
mttjohnson / change file and directory permissions
Created October 26, 2016 04:20
change file and directory permissions
change file permissions
find /path/to/base/dir -type d -exec chmod 0755 {} +
find /path/to/base/dir -type f -exec chmod 0644 {} +
find . -type d -exec chmod 0777 {} +
find . -type f -exec chmod 0666 {} +