Skip to content

Instantly share code, notes, and snippets.

View JosephLeedy's full-sized avatar

Joseph Leedy JosephLeedy

View GitHub Profile
@tored
tored / getOptions.php
Last active September 30, 2021 17:33
getOptions: experimental command line parser for PHP by using attributes
<?php
declare(strict_types=1);
#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class Option
{
public function __construct(
public string|null $short = null,
public string|null $long = null,
public bool $required = false,
@WinstonN
WinstonN / flatten_additional_attributes.py
Last active March 16, 2021 19:58
Flatten additional_attributes from Magento 2 export csv
"""
This script formats a magento product export file, and sets each
additional_attribute as a new column in a target file
"""
import csv
# real files
source_file = './catalog_product_20210316_044037.csv'
target_file = './catalog_product_20210316_044037_formatted.csv'
@hostep
hostep / composer-v2-support-older-magento2-versions.md
Last active January 27, 2024 10:37
Add composer v2 support to older Magento2 versions

Add composer v2 support to older Magento2 versions

Magento 2.3.7 and 2.4.2 ship with composer v2 support out of the box but as far as I can see the only thing that needs to happen is to use some more modern versions of certain composer plugins which are used by certain dependencies of Magento.

This means we should be able to add composer v2 support to older Magento2 versions as well if we get a bit creative.

See below for diffs of the composer.json files you can apply to your projects, be sure to keep a mental note of these things, they will need to maintained by yourself in case newer versions of these modules are released. And if one day you update to Magento 2.3.7 or 2.4.2 or higher, you can remove these changes again.

⚠️ Disclaimer: use these tricks at your own risk!

@Vinai
Vinai / example.clj
Last active July 22, 2019 13:48
Example of property based tests for a simple algorithm in Clojure and in PHP.
(ns example.core
(:require [clojure.test :refer :all]
[clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]))
;; -----------------------------------------------------------------------
;; Application code to test
(defn includes? [needle haystack]
@erikhansen
erikhansen / sync_prod_to_stage.sh
Last active November 11, 2022 23:31
Magento 2 script to push DB and `pub/media` changes from prod>stage
#!/bin/bash
# stop on errors
set -e
# turn on debugging if you're running into issues
#set -x
# Static variables
ENVIRONMENT=$1
RED='\033[0;31m'
NC='\033[0m' # No Color
@erikhansen
erikhansen / generate_sanitize_queries.sql
Last active October 24, 2019 19:22
Sanitize customer emails from Magento database. UPDATE: Use this instead: https://github.com/elgentos/masquerade
/*
Run the following query to get a set of queries that will purge all tables of email addresses. The queries that are output from
this should be manually reviewed to remove queries for any unnecessary tables and can then be run manually or via a Magerun "db:query"
to include it as a part of a scripted cloning process.
IMPORTANT: Make sure to update the @db_name variable
What the resulting query will do:
-- Replace the emails in Magento with dummy emails (unless email is one of the whitelisted domains) in order to prevent emails erroneously being sent to customers.
-- Make all emails with @example.com and use and MD5 of the original domain of the email as the tag for the email. This is important in case we have two emails with the
-- same "local part" but different "domain part". For example, bob.smith@yahoo.com would become bob.smith+c9d12f@example.com
@ProcessEight
ProcessEight / Testing in Magento 2.md
Last active February 7, 2024 14:42
M2: Notes on setting up PHPUnit and writing/troubleshooting tests in Magento 2
@avafloww
avafloww / PhpJava.java
Last active October 16, 2022 18:50
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
@samtay
samtay / magento2.plugin.zsh
Last active August 13, 2018 16:40
Auto completion & portability for bin/magento
# ------------------------------------------------------------------------------
# FILE: m2.plugin.zsh
# DESCRIPTION: oh-my-zsh m2 autocomplete file. Adapted from composer plugin
# AUTHOR: Sam Tay (sam.chong.tay@gmail.com)
# VERSION: 1.0.0
# ------------------------------------------------------------------------------
# Keep this up to date by checking bin-magento list --raw --no-ansi
_bin_magento_get_command_list () {
bin-magento --raw --no-ansi list | sed "s/[[:space:]].*//g"