Skip to content

Instantly share code, notes, and snippets.

View davidalger's full-sized avatar

David Alger davidalger

View GitHub Profile
@davidalger
davidalger / install-php-sodium-on-el8.md
Created December 2, 2019 17:50
Install php-sodium on EL 8

There is currently no pre-built package available for the php sodium ext currently. And due to the changes made to the EL 8 packaging system, IUS no longer plans to maintain any packages for EL 8 (alternate versions of packages such as PHP should eventually become available via additional module streams published in the AppStream repo) so it's not available via IUS either beyond EL 7.

Magento will fallback on sha256 for password hashes when sodium is unavailable:

public function getLatestHashVersion(): int
{
    if (extension_loaded('sodium') && defined('SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13')) {
        return self::HASH_VERSION_ARGON2ID13;
    }

return self::HASH_VERSION_SHA256;

@davidalger
davidalger / sysadmin-shortcuts.md
Last active February 2, 2024 09:17
sysadmin-shortcuts

list listening ports

sudo lsof -nP -iTCP -sTCP:LISTEN
sudo netstat -plunt

flush DNS on Mojave

sudo killall -HUP mDNSResponder

immediately sleep displays

Enable macOS Server Performance Mode

Performance mode changes the system parameters of your Mac. These changes take better advantage of your hardware for demanding server applications.

A Mac with macOS Server that needs to run high-performance services can turn on performance mode to dedicate additional system resources for server applications. Note, however, that performance mode can be enabled even without macOS Server being installed to achieve similar benifits for other high-performance services.

sudo nvram boot-args="serverperfmode=1 $(nvram boot-args 2>/dev/null | cut -f 2-)"
sudo reboot

Reference: https://support.apple.com/en-us/HT202528.

@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 / magento
Last active March 20, 2023 19:20
Magento 2 Shell Wrapper
#!/usr/bin/env bash
# usage: put at /usr/local/bin/magento then call from anywhere within a magento 2 webroot
#
dir="$(pwd)"
while [[ "$dir" != "/" ]]; do
if [[ -x "$dir/bin/magento" ]]; then
"$dir/bin/magento" "$@"
exit $?
fi
@davidalger
davidalger / magento2-order-counts.sql
Last active March 8, 2023 10:57
magento2-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_order o
@davidalger
davidalger / socat-pty-shell-over-tcp.md
Last active February 20, 2023 20:55
Remote Linux Console Access

Where SSH is available, this is probably the more simple and definitely more secure option

  • Create admin user on the server-side (root is typically dissallowed by default)

    useradd -G wheel davidalger
    passwd davidalger
    
  • Connect from the client-side via SSH

@davidalger
davidalger / memory-usage-log.md
Created May 4, 2017 16:12
PHP Memory Usage Log

Setup memory log on php-fpm pool

  1. Added the following to /usr/local/lib/strangecode_php_memory_log.php

     <?php
     function strangecode_php_memory_log()
     {
         $current = memory_get_usage() / 1024 / 1024;
         $peak = memory_get_peak_usage() / 1024 / 1024;
    

$uri = $_SERVER['REQUEST_URI'] ?? 'n/a';

@davidalger
davidalger / kubectl-cheats.md
Last active November 24, 2021 20:15
kubectl cheats

List evicted pods

kubectl get pods --all-namespaces -o json \
  | jq -r '.items[] | select(.status.reason == "Evicted") | "pod/\(.metadata.name) -n \(.metadata.namespace)"'

Delete evicted pods