Skip to content

Instantly share code, notes, and snippets.

View davidalger's full-sized avatar

David Alger davidalger

View GitHub Profile
@davidalger
davidalger / mail-sort.sh
Last active March 2, 2017 15:35
This script will handily sort millions of mail files out of a mail inbox into a series of directories organized by month
#!/usr/bin/env bash
maildir="$1"
if [[ "$maildir" == "" ]]; then
echo "Usage: mail-sort.sh <maildir> <dest>"
exit -1
fi
if [[ ! -d "$maildir" ]]; then
echo "Please make sure '$maildir' is a directory!"
exit -1
@davidalger
davidalger / m2-module-install-2.sh
Last active May 24, 2017 15:16
Install module directly or via composer
composer config repositories.alger/phpworld-talk2 vcs git@github.com:davidalger/phpworld-talk2.git
composer require alger/module-skeleton:dev-master
bin/magento setup:upgrade -q && bin/magento cache:flush -q
# OR
git clone git@github.com:davidalger/phpworld-talk2.git app/code/Alger/Skeleton
bin/magento module:enable Alger_Skeleton
bin/magento setup:upgrade -q && bin/magento cache:flush -q
@davidalger
davidalger / convert-tags.sh
Last active June 8, 2017 18:36
Converts long-form echo tags to short-echo tags
#!/usr/bin/env bash
#
# note: using *html vs *.phtml because one .html file has a use of <?php echo in it
#
function replace_tags {
find "$1" -type f -name "$2" -print0 | xargs -0 perl -pi -w -e "$3"
}
echo "==> Convert single-line long-tags to uniform short-echo tag format"
@davidalger
davidalger / check-urls.sh
Created May 26, 2017 17:36
Check list of URLs for HTTP status codes
#!/usr/bin/env bash
set -e
if [[ ! -f "$1" ]]; then
echo "Usage: $(basename $0) <filepath>"
echo ""
echo " <filepath> path to file with list of URLs to check (one per line)"
echo ""
exit -1
@davidalger
davidalger / magento1-order-counts.sql
Last active November 27, 2017 19:01
magento1-order-counts.sql
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_flat_order o
@davidalger
davidalger / pfsense-setup-packet.md
Last active August 10, 2018 15:25
Install pfSense via Rescue OS on Packet Host

Install pfSense via Rescue OS on Packet Host

  1. Create t1.small.x86 server using the FreeBSD 11.1 operating system

  2. Wait for server to build and then reboot into Rescue OS and connect via SSH

  3. Write install media to disk and reboot

     curl -sO https://nyifiles.pfsense.org/mirror/downloads/pfSense-CE-memstick-serial-2.4.3-RELEASE-amd64.img.gz
    

gunzip -c pfSense-CE-memstick-serial-2.4.3-RELEASE-amd64.img.gz | dd of=/dev/sda && reboot

@davidalger
davidalger / cloud-sql-proxy.service
Created August 24, 2018 01:38 — forked from goodwill/cloud-sql-proxy.service
Example Systemd file for starting cloud sql proxy at system start
[Install]
WantedBy=multi-user.target
[Unit]
Description=Google Cloud Compute Engine SQL Proxy
Requires=networking.service
After=networking.service
[Service]
Type=simple
#file proxysql.cfg
# This config file is parsed using libconfig , and its grammar is described in:
# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-File-Grammar
# Grammar is also copied at the end of this file
datadir="/var/lib/proxysql"
FROM debian:jessie
ENV BUILD_PKG "automake bzip2 cmake make g++ gcc git-core libssl-dev patch binutils"
RUN apt-get update && apt-get install -y \
libssl1.0.0 openssl ssl-cert $BUILD_PKG \
vim mysql-client && \
cd /usr/local/src && \
git clone -b 2018-04-01 --depth 1 --single-branch https://github.com/google/re2.git && \
git clone -b v2.0.0 --depth 1 --single-branch https://github.com/sysown/proxysql.git && \
#file proxysql.cfg
# This config file is parsed using libconfig , and its grammar is described in:
# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-File-Grammar
# Grammar is also copied at the end of this file
datadir="/var/lib/proxysql"
admin_variables=
{