Skip to content

Instantly share code, notes, and snippets.

View adamzero1's full-sized avatar

Adam adamzero1

View GitHub Profile
@adamzero1
adamzero1 / cron_report.php
Created July 29, 2026 09:59
Magento 2 Cron Report
<?php
declare(strict_types=1);
// Prevent varnish or browsers from caching this dynamic report.
header('Content-Type: text/html; charset=UTF-8');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Expires: Thu, 01 Jan 1970 00:00:00 GMT');
header('Surrogate-Control: no-store');
@adamzero1
adamzero1 / add_composer_patches.php
Last active July 16, 2026 08:57
Add composer patches
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
* Merge patch declarations into composer.json extra.patches.
*
* Usage:
* php add_composer_patches.php payload.json [composer.json]
* cat payload.json | php add_composer_patches.php [composer.json]
@adamzero1
adamzero1 / strip.bash
Created June 26, 2026 09:24
Strip Figma data- stuff
#!/bin/bash
sed -E -i 's/data-([a-z\0-9-]*)="([0-9\.:\/a-zA-Z]*)"//g' /path/to/file
@adamzero1
adamzero1 / query_param_report.php
Created June 25, 2026 10:10
Get Query Strings Report From Nginx Log File
#!/usr/bin/env php
<?php
if ($argc < 2) {
echo "Usage: php query_param_report.php <log-file-path>\n";
exit(1);
}
$filePath = $argv[1];
@adamzero1
adamzero1 / DisallowPrintRSniff.php
Created August 2, 2023 07:57
Custom code sniff to check second argument passed to print_r
<?php
namespace PHP_CodeSniffer\Standards\Mdoq\Sniffs\Functions;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
class DisallowPrintRSniff implements Sniff
{
public const METHOD_NAME = 'print_r';
@adamzero1
adamzero1 / README.md
Last active June 29, 2024 11:41
Get more descriptive error when DOM validation fails in Magento

Get a more debugable error message when DOM validation fails in Magento.

Original Error Message

1 exception(s):
Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'arguments': This element is not expected.
Line: 1471
@adamzero1
adamzero1 / magento_cron_job_run_times.sql
Created August 9, 2022 12:25
Report on average,min and max run time (in seconds) of all completed jobs in Magento 2
select job_code,
avg(timestampdiff(second, executed_at, finished_at)) as average_run_time,
min(timestampdiff(second, executed_at, finished_at)) as min_run_time,
max(timestampdiff(second, executed_at, finished_at)) as max_run_time
from cron_schedule where executed_at is not null and finished_at is not null group by job_code order by max(timestampdiff(second, executed_at, finished_at)) desc;
@adamzero1
adamzero1 / analyse_magento_var_directory.php
Created May 12, 2022 11:00
Analyse Magento var directory
<?php
use Magento\Setup\Module\I18n\Parser\Parser;
if(!is_file('bin/magento')){
echo 'Unable to find "bin/magento", this needs to be ran from the root of the project.'.PHP_EOL;
return 1;
}
define('REPORT_WIDTH', 200);
@adamzero1
adamzero1 / README.md
Last active March 9, 2022 20:27
Magento MySQL Santized Backup

Run sanitized backup

curl https://gist.githubusercontent.com/adamzero1/90e577229cbfb5907822b50daa7baf37/raw/85aa792ea563418fb9da2dee1fba1fa7669e7bd1/backup.sh | bash
@adamzero1
adamzero1 / README.md
Last active February 23, 2022 10:26
Fix broken Magento2 install

Description

Sometimes when running composer install for Magento 2 depending on your current directory structure the Magento composer plugin does not extract/copy the files out of vendor. Which leaves you with a broken installation.

How to run

curl -s https://gist.githubusercontent.com/adamzero1/0eb6d3e14078676a3ba589d77ba67b3d/raw/6ed67290b6eca7211942d1363ab6115eefd590a6/fix | bash