Skip to content

Instantly share code, notes, and snippets.

View dfelton's full-sized avatar

Darren Felton dfelton

View GitHub Profile
@dfelton
dfelton / Magento 1.x Orphaned Records Cleanup.md
Last active May 24, 2021 19:23
Deletes orphaned records from a Magento 1.x database.

Purpose

The purpose of this SQL script is to clean up a Magento 1.x database by deleting orphaned records from database tables which cause foreign key contraint failures. This happens when at some point in time records where deleted from the database while FOREIGN_KEY_CHECKS = 0 and the person performing the delete operations failed to delete all related records pertaining to related tables of the primary table.

This script can be helpful when encountering foreign key constraint failures using the Data Migration Tool to migrate your

@dfelton
dfelton / Magento Unused catalog_product EAV attributews.md
Created January 11, 2017 21:07
Finds unused catalog_product eav attributes

Unused catalog_product EAV attributes

SELECT queries for finding unused catalog_product EAV attributes.

@dfelton
dfelton / 000_magento_ee_2.1.3_cli.md
Last active January 20, 2017 04:57
CLI options for Magento 2 CLI

Magento CLI version 2.1.3

Usage:

command [options] [arguments]

Options:

--help (-h)           Display this help message
--quiet (-q)          Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

--version (-V) Display this application version

@dfelton
dfelton / 000 - Max scale param value necessary for PHP bcmul function.md
Last active February 24, 2019 18:51
PHP - Prove max $scale param necessary for bcmul() operations

Can be used to assert the max scale necessary for bcmul() operations between two string representations of floating point values.

Theory is that the max scale necessary is a simple calculation of maxScale = numDigitsAfterDecimalOfLeftOperand + numDigitsAfterDecimalOfRightOperand

Logic could probably be simplified by converting left and right operand values to whole numbers, performing calculation, and converting back to floating point number. Alongside this, perform bcmul() operation with

@dfelton
dfelton / .bashrc
Last active November 2, 2020 00:17
~/.bashrc preferences
# Git
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\u@\[\033[32m\]\w\[\033[33m\]\$(git_branch)\[\033[00m\]\$ "
# Aliases
alias la='ls -la'
@dfelton
dfelton / php_memory_limit.sh
Created August 20, 2019 17:06
Just a quick and dirty memory limit check.
# PHP Memory Limit Check (converts memory limit to bytes and verifies it is 1 gigabyte or greater)
php -r '(int)preg_replace_callback("/(\-?\d+)(.?)/", function ($m) { return $m[1] * pow(1024, strpos("BKMG", $m[2])); }, strtoupper(ini_get("memory_limit"))) >= 1073741824 ? exit(0) : exit(1);'
if [ $? -eq 0 ]; then
echo -e "\t\e[32mPASS:\e[0m PHP CLI memory limit is configured to 1 Gigabyte or greater"
else
INSTALL_CHECK=0
echo -e "\t\e[91mFAILED:\e[0m PHP CLI memory limit is not configured to 1 Gigabyte or greater"
fi
@dfelton
dfelton / 000 - Magento 2 Cheat Sheet.md
Last active January 10, 2020 01:59
Magento 2 Cheat Sheet

Just a cheat Sheet

@dfelton
dfelton / .zshrc
Last active March 30, 2023 15:58
Z Shell profile for maxOS
# Terminal Styling
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' stagedstr 'M'
zstyle ':vcs_info:*' unstagedstr 'M'
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' actionformats '%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats \
@dfelton
dfelton / pushToDev.sh
Last active July 10, 2020 18:42
Bash function that pushes current branch to upstream development branch
pushToDev() {
php -nr '
function getCurrentBranchName(): ?string {
$branches = shell_exec("git branch 2>/dev/null");
$branchName = null;
if (is_string($branches)) {
$branches = explode(PHP_EOL, trim($branches));
foreach ($branches as $branch) {
if (strpos($branch, "*") === 0) {
$branchName = trim(substr($branch, 1));
@dfelton
dfelton / createSampleData.php
Created June 25, 2020 22:00
Generates sample data in Magento by via cURL requests to the Magento admin. Useful if CLI access and access to System -> Import/Export is restricted.
<?php
class Config
{
public static $adminUsername = '';
public static $adminPassword = '';
public static $expectedLoginLandingRoute = '/index/index/';
public static $authCookieName = 'adminhtml';