Skip to content

Instantly share code, notes, and snippets.

View davidalger's full-sized avatar

David Alger davidalger

View GitHub Profile
@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()
@davidalger
davidalger / 00-postfix-sendgrid-teammate.md
Last active May 19, 2020 20:33
Example usage of the Postfix role for Ansible as can be found here: https://github.com/linuxhq/ansible-role-postfix

Create SendGrid Account

  1. Create a SendGrid account if you do not already have one. An Essentials plan would suffice if email volume is within the limit, but the essentials plan uses a shared IP with other people that send emails, and that could possibly affect your sending reputation. The essentials plan also limits the additional teammates to a single additional teammate user. For taking advantage of multiple teammate accounts that can login to the same SendGrid account, more email volume, for better control of the sending reputation, or some other more advanced feature use a Pro account.

  2. If you choose an Essentials plan, you can either provide us with the main account credentials, or add a teammate with admin access.

    If you provide us with the main account, we can take care of creating the appropriate teammate account for you.

If you want to create the additional teammate account, you can give it a username like companyname_website or something. Please use