Skip to content

Instantly share code, notes, and snippets.

View SchumacherFM's full-sized avatar

Cyrill Schumacher SchumacherFM

View GitHub Profile
@SchumacherFM
SchumacherFM / .bash_profile
Last active December 4, 2023 13:07
Remove all empty values from a JSON file with CLI program jq
# removes all null, false, "", 0, [], {} and "0001-01-01T00:00:00Z values from a json
# files and writes the data back to the original file via program sponge (brew install moreutils jq)
# date time string because of GoLang empty time encoding 🙈
jsonRemoveEmpty() {
for file in *.json; do
cat "$file" | jq 'walk( if type == "object" then with_entries(select(.value != null and .value != false and .value != "" and .value != 0 and .value != [] and .value != {} and .value != "0001-01-01T00:00:00Z") ) else . end)' | sponge "$file"
done
}
@SchumacherFM
SchumacherFM / db.go
Created February 15, 2015 00:13
GoLang Database SQL: Selecting an unknown amount of columns from a query. Benchmark results in db_test.go
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"log"
)
const (
@SchumacherFM
SchumacherFM / aExplanation.md
Last active April 20, 2023 10:58
Magento Backend Reindex and fastcgi_finish_request()

Backend Section: Index Management

  • Nginx 1.4
  • PHP 5.5 FPM

Doc: fastcgi_finish_request

Clicking on one of the Reindex Data links executes the reindex process and immediately shows the URL from action preReindexProcess() but clicking on that link to initiate a new request takes as long as it takes to wait for the reindexing.

So something is still using the same connection and waits to finish the previous request. How to initiate a new request without waiting for the previous one?

@SchumacherFM
SchumacherFM / pt-duplicate-key-checker.sql
Last active February 5, 2023 15:10
pt-duplicate-key-checker for Magento 1.8 MySQL database. Less indexes the faster the update/insert statement
# ########################################################################
# api2_acl_attribute
# ########################################################################
# IDX_API2_ACL_ATTRIBUTE_USER_TYPE is a left-prefix of UNQ_API2_ACL_ATTRIBUTE_USER_TYPE_RESOURCE_ID_OPERATION
# Key definitions:
# KEY `IDX_API2_ACL_ATTRIBUTE_USER_TYPE` (`user_type`)
# UNIQUE KEY `UNQ_API2_ACL_ATTRIBUTE_USER_TYPE_RESOURCE_ID_OPERATION` (`user_type`,`resource_id`,`operation`),
# Column types:
# `user_type` varchar(20) not null comment 'type of user'
@SchumacherFM
SchumacherFM / CatalogDeleteNull.sql
Last active January 15, 2023 15:41
Magento: Remove all NULL values from catalog_*_entity_* tables
DELETE FROM catalog_category_entity_datetime WHERE `value` IS NULL;
DELETE FROM catalog_category_entity_decimal WHERE `value` IS NULL;
DELETE FROM catalog_category_entity_int WHERE `value` IS NULL;
DELETE FROM catalog_category_entity_text WHERE `value` IS NULL;
DELETE FROM catalog_category_entity_varchar WHERE `value` IS NULL;
DELETE FROM catalog_product_entity_datetime WHERE `value` IS NULL;
DELETE FROM catalog_product_entity_decimal WHERE `value` IS NULL;
DELETE FROM catalog_product_entity_gallery WHERE `value` IS NULL;
DELETE FROM catalog_product_entity_group_price WHERE `value` IS NULL;
@SchumacherFM
SchumacherFM / arrayToInt.php
Created October 18, 2013 01:49
array_map('intval',...) vs arrayToInt()
<?php
$integers = range(100, 1000);
foreach ($integers as &$int) {
$int = (string)$int;
}
function arrayToInt(array $arr)
{
@SchumacherFM
SchumacherFM / bench_test.go
Last active May 18, 2022 08:50
GoLang Benchmark: Map, StringSlice, Array, StructSlice
package main
// run with: $ go test --bench=. -test.benchmem .
// @see https://twitter.com/karlseguin/status/524452778093977600
import (
"math/rand"
"strconv"
"testing"
)
@SchumacherFM
SchumacherFM / createTestCustomers.sql
Last active April 3, 2020 20:45
Magento: Different SQL Queries to truncate tables, create anonymous, test customers out of your existing and round all prices to get rid of the decimals.
UPDATE `customer_entity`
SET `email` = concat('test+', entity_id, '@aGmailDomain.com');
UPDATE `customer_entity_varchar`
SET `value` = CONCAT(MD5(concat('qXpassword', entity_id)), ':qX')
WHERE `attribute_id` = 12;
UPDATE `sales_flat_order`
SET customer_email = concat('test+', IFNULL(customer_id, entity_id), '@aGmailDomain.com');
@SchumacherFM
SchumacherFM / Explanation.md
Last active December 9, 2019 18:19
Magento: Optimize URL rewrite frontend select for categories

After I have seen that some 3rd party modules duplicate the core_url_rewrite table to store there additional category rewrite information in it (1), I came to the conclusion that it should be save to remove the joinLeft() in the flat table classes.

Instead of the joinLeft() you simply refer to the column main_table.url_path as request_path in the tables catalog_category_flat_store_[StoreId]. Please see the new methods.

Downside: To get the correct rewrites in the frontend you need to run the reindex for catalog_category_flat. During this reindex the correct rewrites will be inserted into the column catalog_category_flat_store_X.url_path.

Footnotes:

(1) the join with the core_url_rewrite takes for large product collection really long when you only need the correct rewrite for the categories. This can save per request around ~0.Xsec.

@SchumacherFM
SchumacherFM / gist:5371312
Created April 12, 2013 11:12
Magento Truncate Quote and Orders
SET foreign_key_checks = 0;
TRUNCATE `log_quote`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;