Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / read_lines.sh
Created December 19, 2018 20:47
Reading partial segments/lines of a file using sed
# extract lines 13100-13200 of file and write to a separate file
sed -n 13100,13200p database.sql > small_segment.sql
@mttjohnson
mttjohnson / mysql_insert_update_options.sql
Created December 14, 2018 21:23
MySQL Insert/Update or both
-- In the below example there is a unique key for scope, scope_id, and path
-- We can choose to only insert a record if it doesn't exist, only update
-- a record that doesn't exist, or accomodate both to ensure that a record
-- exists afterwards, either inserted, or updated for the matching key.
-- Only insert a record if it does not already exist
INSERT INTO core_config_data (scope, scope_id, path, value)
SELECT * FROM (SELECT 'default', '0', 'catalog/search/engine', 'enterprise_search/engine') AS to_insert
WHERE NOT EXISTS (
@mttjohnson
mttjohnson / perl_regex_examples.sh
Last active December 12, 2018 02:24
Perl Bash/Shell RegEx Examples
# example perl one line replacing contents in a file in place
perl -pi -e 's/something_to_match/replaced_with/' ./my_path/to_file.txt
# Additional regex modifiers got global multi-line and case insensitive
perl -pi -e 's/something_to_match/replaced_with/gmi' ./my_path/to_file.txt
# Using different delimiters for the regex, in this case using a # instead of the tranditional /
perl -pi -e 's#something_to_match#replaced_with#' ./my_path/to_file.txt
# If you don't want to modify a file in place you can split things up a bit
@mttjohnson
mttjohnson / mysql_deadlocks.sql
Last active February 25, 2020 10:05
MySQL Deadlocks
-- enabled the logging for deadlocks on the mysql server via a global config set:
SET GLOBAL innodb_print_all_deadlocks = 1;
-- You can query the server to check the current status of the config value:
select @@innodb_print_all_deadlocks;
-- The log file it writes to is typically /var/log/mysqld.log
-- view most recent deadlock
SHOW ENGINE INNODB STATUS;
@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 / date_epoch.sh
Created November 28, 2018 00:15
Date Commands
# current date in epoch (seconds Unix time 0 (midnight 1/1/1970))
date -v +1y +%s
# year from now date in epoch
date +%s

Keybase proof

I hereby claim:

  • I am mttjohnson on github.
  • I am mttjohnson (https://keybase.io/mttjohnson) on keybase.
  • I have a public key ASDFt-9_sbEjb_M_IAT3oz0uB9NujGKlOmm11KxVww5SgAo

To claim this, I am signing this object:

@mttjohnson
mttjohnson / update_magerun.sh
Last active July 9, 2020 16:02
Update n98-magerun on servers
/usr/local/bin/n98-magerun2 --version
wget https://files.magerun.net/n98-magerun2-latest.phar
mv -f n98-magerun2-latest.phar /usr/local/bin/n98-magerun2
chmod 755 /usr/local/bin/n98-magerun2
/usr/local/bin/n98-magerun2 --version
# Install older version of MageRun2 for PHP 7.1
wget https://files.magerun.net/n98-magerun2-3.2.0.phar
mv n98-magerun2-3.2.0.phar /usr/local/bin/n98-magerun2
chmod +x /usr/local/bin/n98-magerun2
@mttjohnson
mttjohnson / sophos_antivirus_references.sh
Created November 23, 2018 15:50
Sophos Anti-Virus sav References
# To disable on access scanner use savdctl
/opt/sophos-av/bin/savdctl
# savdctl: Control the Sophos Anti-Virus daemon
# Usage: savdctl [--daemon | --no-daemon] [COMMAND] [ARGUMENT]
# COMMAND:
# help Display this help information
# version Display the version and copyright information
# enable Enable on-access scanning
# disable Disable on-access scanning
@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();