Skip to content

Instantly share code, notes, and snippets.

View peterjaap's full-sized avatar

Peter Jaap Blaakmeer peterjaap

  • elgentos ecommerce solutions / Blaakmeer Webdevelopment
  • Groningen, the Netherlands
View GitHub Profile
@peterjaap
peterjaap / varnish-test.sh
Last active April 18, 2025 10:29
Varnish test script
#!/bin/bash
# ========================
# Varnish Cache Test Script for Magento 2
# ========================
# --- Configurable URLs ---
BASE_URL="https://mydomain.com"
# URLs can be comma-separated for multiple testing
@peterjaap
peterjaap / detect-unused-magento2-extensions.php
Created April 15, 2025 14:31
PHP script to detect potentially unused Magento 2 extensions
<?php
require __DIR__ . '/app/bootstrap.php';
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\Module\Dir\Reader as ModuleDirReader;
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
@peterjaap
peterjaap / find-file-equivalents.sh
Created April 8, 2025 08:20
Efficiently detect content-duplicate files between two directories (app/ and vendor/) regardless of path. This script computes SHA256 hashes and file sizes to identify files in app/ that are binary-equivalent to any file in vendor/. It avoids expensive cmp comparisons by leveraging sorted hash lists and join. Ideal for large codebases with poten…
#!/bin/bash
# Step 1: Hash all files in app/ and vendor/ using sha256 and file size
find app -type f -exec stat --format="%s %n" {} + | while read -r size file; do
hash=$(sha256sum "$file" | cut -d' ' -f1)
echo "$size $hash $file"
done | sort > /tmp/app_files.txt
find vendor -type f -exec stat --format="%s %n" {} + | while read -r size file; do
hash=$(sha256sum "$file" | cut -d' ' -f1)
@peterjaap
peterjaap / remove-coupon-field-when-coupert-is-detected.js
Last active April 3, 2025 20:04
Remove coupon field when Coupert extension is detected. Adjustable to also block Capital One Shopping, Rakuten, CouponCabin Sidekick, Dealfinder, RetailMeNot, Ibotta and Honey
(function() {
var detectExtension = function(url, ifInstalled, ifNotInstalled) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = url;
link.onload = ifInstalled;
link.onerror = ifNotInstalled || function() {};
document.head.appendChild(link);
@peterjaap
peterjaap / varnish6-xkey.vcl
Last active April 23, 2025 08:58
Optimized Varnish VCL for Magento 2. See the non-Xkey version here: https://gist.github.com/peterjaap/006169c5d95eeffde3a1cc062de1b514
# A number of these changes come form the following PR's; , combines changes in https://github.com/magento/magento2/pull/29360, https://github.com/magento/magento2/pull/28944 and https://github.com/magento/magento2/pull/28894, https://github.com/magento/magento2/pull/35228, https://github.com/magento/magento2/pull/36524, https://github.com/magento/magento2/pull/34323
# VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 6
# See the non-Xkey version here: https://gist.github.com/peterjaap/006169c5d95eeffde3a1cc062de1b514
vcl 4.1;
import std;
import xkey;
@peterjaap
peterjaap / 2.4.7-p4-most-relevant-changes-according-to-claude.txt
Last active February 13, 2025 11:40
Magento 2.4.7-p4 patch update most relevant changes according to Claude
SECURITY & VALIDATION CHANGES:
1. app/code/Magento/Customer/Controller/Account/EditPost.php
- Removed file attribute deletion functionality for security
2. app/code/Magento/Config/Plugin/Model/Config/Backend/LocalePlugin.php
- Added new plugin to validate currency code values
3. app/code/Magento/Directory/Model/Config/Backend/WeightUnit.php
- Added new backend model to validate weight unit values
@peterjaap
peterjaap / miyoo-games-backup-and-remove.sh
Created November 2, 2024 13:11
Script to clean Miyoo games list - remove 99% of all games
#!/bin/bash
# Define the backup directory
BACKUP_DIR=~/backup-miyoo-games
SOURCE_DIR="/mnt/sd-card/Roms"
# Create the backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
WELL_KNOWN_GAMES=(
@peterjaap
peterjaap / mage-os-migration.sh
Last active December 10, 2024 14:57
Mage OS migration shell script - you can use this if you want to move from Magento community edition to MageOS. This updates your composer.json file and your local patches.
#!/bin/bash
# Path to the composer.json file
COMPOSER_FILE="composer.json"
TEMP_FILE="composer_temp.json"
# Checkout the composer.json file to avoid unwanted changes
git checkout "$COMPOSER_FILE"
# Create a new file to hold updated content
@peterjaap
peterjaap / cleanup-sequence-tables.sql
Created September 19, 2024 06:58
Query to remove Magento 2 sequence tables for non-existing stores
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.`', TABLE_NAME, '`') INTO @tables FROM (
SELECT *
FROM information_schema.tables AS t
WHERE t.table_schema = 'DB NAME'
AND t.table_name REGEXP "^sequence_(.+)_[0-9]+"
AND SUBSTRING_INDEX(t.table_name, '_', -1) NOT IN (SELECT DISTINCT store_id FROM sales_sequence_meta)
) TT;
SET @tables = CONCAT('DROP TABLE ', @tables);
@peterjaap
peterjaap / ACSD-51892_2.4.6.patch
Created July 11, 2023 07:28
Drop-in ACSD-51892 patch for 2.4.6 / 2.4.6-p1 in vaimo/composer-patches format
@package magento/framework
@level 4
@version >=103.0.6 <103.0.7
diff --git a/vendor/magento/framework/App/DeploymentConfig.php b/vendor/magento/framework/App/DeploymentConfig.php
index 6713baa3a1d..64f32d5516b 100644
--- a/vendor/magento/framework/App/DeploymentConfig.php
+++ b/vendor/magento/framework/App/DeploymentConfig.php
@@ -51,6 +51,16 @@ class DeploymentConfig
*/