Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@erikhansen
erikhansen / rsync_examples.sh
Last active March 1, 2019 19:00 — forked from mttjohnson/rsync_examples.sh
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/ user_name@example.com:/var/www/
# rsync media between two remotes that can not talk to each other
# this creates a port (50000) on the origin server that establishes a tunnel between the origin and destination through
# your computer, as long as your computer can access both servers you can rsync the files between the two
@erikhansen
erikhansen / load_all_sitemap_urls.sh
Last active March 1, 2019 20:10
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' {}
@erikhansen
erikhansen / brew_vagrant_version.sh
Created February 8, 2019 18:22 — forked from mttjohnson/brew_vagrant_version.sh
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:
@erikhansen
erikhansen / robots.txt
Last active April 2, 2020 09:11
Recommended Magento 2 robots.txt
# TODO: Update this with appropriate url
Sitemap: https://www.example.com/sitemap.xml
User-agent: *
# Paths (clean URLs)
Disallow: /index.php/
Disallow: /catalog/product_compare/
# Need to allow these urls paths to be indexed, since M2 commonly includes these links in sitemap.xml
# Disallow: /catalog/category/view/
@erikhansen
erikhansen / daily_errors_report.sh
Last active August 2, 2021 11:41
Magento 2 - Send nightly error email, grouped and sorted by count
#!/bin/bash
# stop on errors
set -e
# turn on debugging if running into issues
#set -x
# This script sends a nightly email, showing errors, grouped and sorted by count.
# Getting these errors emailed can be especially useful for the first few weeks after launching a new Magento site.
# Assumptions:
@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 / commands
Last active April 2, 2020 09:14
Magento 2 Local Site Configurations
# Set admin login to 6 days
bin/magento -q config:set admin/security/session_lifetime 518400
# Allow admin logins to be bookmarked
bin/magento -q config:set admin/security/use_form_key 0
# Set customer login to 4 hours
bin/magento -q config:set web/cookie/cookie_lifetime 14400
# Misc dev settings
bin/magento -q config:set dev/css/merge_css_files 0
bin/magento -q config:set dev/js/merge_files 0
bin/magento -q config:set dev/js/enable_js_bundling 0
SET @utc_offset = 6;
-- Orders Per Year --
SELECT period_date, CONCAT("UTC-", @utc_offset) AS utc_offset, order_count, gross_revenue, ROUND(gross_revenue / order_count, 2) AS gross_aov
FROM (
SELECT
COUNT(*) AS order_count,
ROUND(SUM(base_grand_total), 2) AS gross_revenue,
date_format(date_sub(o.created_at, INTERVAL @utc_offset HOUR), "%Y") AS period_date
FROM sales_order o
@erikhansen
erikhansen / README.md
Last active April 4, 2019 21:27
Example README.md file for Magento 2 project

Title of Site

Developer Setup

Run through the following steps to setup this project on your local environment. These instructions assume you're using the standard Classy Llama devenv.

Server Access

Use the following to connect to stage.

@erikhansen
erikhansen / composer_private_repos.sh
Created November 7, 2018 17:47 — forked from mttjohnson/composer_private_repos.sh
Composer Notes and Private Repositories
# List the composer home directory
# Typically /Users/<user>/.composer or /home/<user>/.composer or C:\Users\<user>\AppData\Roaming\Composer
echo $COMPOSER_HOME
# List files in the composer home
ls -la $COMPOSER_HOME
# View auth.json in composer home used when no local ./auth.json exists in the directory executed from
cat $COMPOSER_HOME/auth.json