Skip to content

Instantly share code, notes, and snippets.

View davidalger's full-sized avatar

David Alger davidalger

View GitHub Profile
@davidalger
davidalger / db-dump.sh
Last active September 29, 2020 03:10
Uses n98-magerun over SSH to dump a database and pull to local environment for import
#!/usr/bin/env bash
set -euo pipefail
trap 'error "$(printf "Command \`%s\` on line $LINENO failed with exit code $?" "$BASH_COMMAND")"' ERR
## setup functions for use throughout the script
function error {
>&2 printf "\033[31mERROR\033[0m: $@\n"
}
function :: {
@davidalger
davidalger / run-ansible
Last active July 10, 2020 19:41
Shell script to wrap ansible runtime in a docker context using these images: https://github.com/davidalger/docker-images-ansible
#!/usr/bin/env bash
set -euo pipefail
trap 'error "$(printf "Command \`%s\` on line $LINENO failed with exit code $?" "$BASH_COMMAND")"' ERR
function error {
>&2 printf "\033[31mERROR\033[0m: $@\n"
}
function fatal {
error "$@"
@davidalger
davidalger / patches--ConsoleLogger-Prefix.patch
Created June 2, 2020 22:43
Prefixes logging output of Magento 2 database upgrade CLI commands with timestamp in HH:MM:SS format
--- webroot/vendor/magento/framework/Setup/ConsoleLogger.php 2020-06-02 17:09:24.000000000 -0500
+++ webroot/vendor/magento/framework/Setup/ConsoleLogger.php 2020-06-02 17:23:51.000000000 -0500
@@ -67,7 +67,7 @@
public function log($message)
{
$this->terminateLine();
- $this->console->writeln('<detail>' . $message . '</detail>');
+ $this->console->writeln('<detail>' . $this->logPrefix() . $message . '</detail>');
}
@davidalger
davidalger / php74-build.md
Last active May 18, 2020 16:08
PHP 7.4 build script to create RPM repository based on IUS/Fedora spec files

How to Use This

  1. Spin up a CentOS 7 server on Digital Ocean with 2G memory using Test Ocean stack. It may also be run from within a centos:7 Docker container.

    terraform apply -var droplet_image=centos-7-x64 -var droplet_size=2gb -var droplet_count=1
    
  2. SSH into the server (dropping into root via sudo -i) then run the following to execute the script.

    curl -s https://raw.githubusercontent.com/davidalger/docker-images-php/master/scripts/php74-build.sh?t=$(date +%s) | bash
    
@davidalger
davidalger / cloud-config.yaml
Created April 15, 2020 20:34
Automatically format and mount both EBS Volume devices and Amazon EC2 NVMe Instance Storage devices (ephemeral local storage) via cloud-init on Nitro instances running CentOS 7
#cloud-config
packages:
- epel-release # required for jq installation to succeed
write_files:
- path: /usr/local/bin/mount-scratch-disks
owner: root:root
permissions: '0700'
content: |
#!/bin/bash
@davidalger
davidalger / 00-iframe-communication.md
Created April 4, 2020 02:25 — forked from pbojinov/README.md
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

@davidalger
davidalger / 00-magento-om-debug.md
Created April 3, 2020 13:56
Magento 2 OM Debugging

Sometimes console commands use DI in a way that instantiates objects which have side-effects or do a lot of work to initialize themselves in the __construct method. This generally will surface in one of two ways:

a) Errors when running bin/magento due to application scope not being set

b) Inability to run setup:install from-scratch due to a module instantiating an object which relies on tables which do not exist yet creating errors such as the following:

Table 'magento_integration_tests.flag' doesn't exist

Appling this patch will cause Magento to output a list of all shared instances instantiated by the ObjectManager during the DI process. This can be useful in debugging the above issues. Inspect the output for Command classes, and then trace down what is instantiated following the last Command class, and you may find the class that is at fault. Once you have this information, a bit of trial and error may be used such as disabling modules or appending \Proxy to injected classes (remember to fl

@davidalger
davidalger / rabbitmqctl-cheats.md
Last active August 11, 2020 13:49
RabbitMQ Cheats for Operators

Cleanup default user and vhost

rabbitmqctl delete_user guest
rabbitmqctl delete_vhost /

Create administrative user

Note: Make sure pwgen is installed before running the following.

AMQP_USER=rabbitadmin AMQP_PASS="$(pwgen -A1 32 1 | tee /dev/stderr)"

@davidalger
davidalger / vertest.sh
Last active February 29, 2020 16:57
Unit Testing Version Comparison in Bash Script
#!/bin/bash
function version {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}
# version operator version true/false (1/0)
UNITS=(
"(2.5.7 -le 2.5.6.9 0)"
"(2.4.10 -lt 2.4.9 0)"
@davidalger
davidalger / cleanupDuplicateCoupons.sql
Created February 20, 2020 17:15
Cleans up duplicate codes from salesrule_coupons table provided times_used is 0
-- Dissalow non-deterministic use of columns not named in GROUP BY
-- See: https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html
SET SESSION sql_mode = CONCAT_WS(",", (SELECT @@session.sql_mode), 'ONLY_FULL_GROUP_BY');
DROP PROCEDURE IF EXISTS deleteDuplicateCoupons;
DELIMITER $$
CREATE PROCEDURE deleteDuplicateCoupons()