Skip to content

Instantly share code, notes, and snippets.

View kraken-chris's full-sized avatar

Chris Huffman kraken-chris

  • Kraken Commerce
  • Springfield, MO
View GitHub Profile
@kraken-chris
kraken-chris / category_paths.sql
Created October 27, 2023 17:49
Fetch all category ids and full category paths
SELECT
cce.entity_id AS category_id,
GROUP_CONCAT(eav.value ORDER BY parent.path ASC SEPARATOR '/') AS category_path
FROM
catalog_category_entity AS cce
JOIN
catalog_category_entity AS parent ON cce.path LIKE CONCAT(parent.path, '%')
JOIN
catalog_category_entity_varchar AS eav ON parent.row_id = eav.row_id
WHERE
@kraken-chris
kraken-chris / DB Table Size.sql
Created June 22, 2023 14:38
Get the size of a specific DB table.
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "<db_name>"
AND table_name = "<table_name>";
@kraken-chris
kraken-chris / setup.sh
Last active June 8, 2023 20:54
Setup Magento PHP_Codesniffer
## Use the latest PHP_Codesniffer version
composer require squizlabs/php_codesniffer:^3.5 --dev
## Use the latest versino of Magento Coding Standard
composer require magento/magento-coding-standard:^28 --dev -W
## Make sure phpcs works
vendor/bin/phpcs -i
## Add Magento 2 Coding Standard to PHP_Codesniffer
@kraken-chris
kraken-chris / output_var.php
Created June 8, 2023 15:38
Debugging one-liner: Output some data to a file
file_put_contents(BP.'/var/log/logfilename.log', "\nLog info: $variable\n", FILE_APPEND);
@kraken-chris
kraken-chris / translate-into-inches
Created May 9, 2023 16:04
Spreadsheet formula to translate various lengths into inches. Supports: ", ft, mm, m
=IF(ISNUMBER(SEARCH("""",B2)), LEFT(B2,LEN(B2)-1), IF(ISNUMBER(SEARCH("mm", B2)),LEFT(B2, LEN(B2)-2) / 25.4,IF(ISNUMBER(SEARCH("M", B2)),LEFT(B2, LEN(B2)-1) * 39.37,IF(ISNUMBER(SEARCH("ft", B2)),LEFT(B2,LEN(B2)-2) * 12,B2))))
@kraken-chris
kraken-chris / Create Zip Archive.php
Created March 30, 2023 19:28
Create zip archive from files uploaded in a form
$zip = new Zip();
$zip->setArchive($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'media/ziptest.zip');
$location = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'media/zip_test/';
move_uploaded_file($_FILES['file0']['tmp_name'], $location . 'tmp_file0.pdf');
move_uploaded_file($_FILES['file1']['tmp_name'], $location . 'tmp_file1.pdf');
$fileArchive = $zip->compress($_FILES['file0']['tmp_name']);
@kraken-chris
kraken-chris / Flatten-Directory.sh
Created March 29, 2023 15:21
Given a directory containing multiple directories each with files within, move the images to a single directory with no nested directories.
find TargetDirectory/ -mindepth 2 -type f -exec mv -i '{}' TargetDirectory/ ';'
@kraken-chris
kraken-chris / select_all_checkboxes.js
Created March 1, 2023 19:33
Select all checkboxes on a page
javascript:(function(){function checkFrames(w) {try {var inputs = w.document.getElementsByTagName('input');for (var i=0; i < inputs.length; i++) {if (inputs[i].type && inputs[i].type == 'checkbox'){inputs[i].checked = !inputs[i].checked;}}} catch (e){}if(w.frames && w.frames.length>0){for(var i=0;i<w .frames.length;i++){var fr=w.frames[i];checkFrames(fr);}}}checkFrames(window);})()
@kraken-chris
kraken-chris / update_base_urls.sql
Last active December 9, 2022 19:53
Update base urls
# Update "local_url" with the value of WARDEN_ENV_NAME
SET @localUrl = "{{local_url}}";
SET @scope = 0; #update scope if needed for each website/store
UPDATE
core_config_data
SET
`value` = concat("https://app.", @localUrl, ".test/")
WHERE
path LIKE "web/%/base_url"