Skip to content

Instantly share code, notes, and snippets.

@erik4github
erik4github / csv-parser.js
Last active October 16, 2020 05:47
A basic CSV reader in node. Doesn't account for things like commas in row or header values.
const fs = require('fs');
const { once } = require('events');
const readline = require('readline');
const zip = (keys, vals) =>
keys.reduce((currentObj, prop, idx) => {
currentObj[prop] = vals[idx];
return currentObj;
}, {});
@erik4github
erik4github / README.md
Last active June 11, 2020 23:42
Magento 2 save and getResource Deprecation

If you're reading the Magento 2 devdocs for custom attributes, you'll probably notice they give an example of creating a new custom attribute like so:

<?php

namespace Magento\Customer\Setup\Patch\Data;

use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;
@erik4github
erik4github / Magento 2 Windows Specific Config.md
Created June 11, 2020 22:41
In case you can't use Docker

Fix symlinks (2.3)

In vendor\magento\framework\View\Element\Template\File\Validator.php

    protected function isPathInDirectories($path, $directories)
    {
        if (!is_array($directories)) {
            $directories = (array)$directories;
 }
@erik4github
erik4github / regex.md
Last active May 7, 2020 21:27
Exclude query parameters from Google Analytics report regex

Works for landing pages & pages like /this-is-how-a-url-shows-up-in-the-report/

^\/?(\[?.+\=.*)

@erik4github
erik4github / VLOOKUP, XLOOKUP, and INDEX-MATCH.md
Created April 29, 2020 04:12
Reference for how Excel functions VLOOKUP, XLOOKUP, and INDEX(MATCH) work.

VLOOKUP, XLOOKUP, and INDEX/MATCH

Example: Looking up a SKU to return a price.

Note that C is the the column where the SKU is located in, and H is the end of the column. The price is located in column G, so 5 columns away from C.

' Where A2 is the SKU you're looking up in the current sheet and SKU_Price_Table is a Table in another sheet '
=VLOOKUP(A2, SKU_Prices_Table!C:H, 5, FALSE)

Note that if you have numbers and text mixed together, VLOOKUP will only return the matching text columns (e.g. a SKU that is just 123 and a SKU that is F-123, VLOOKUP will return N/A for 123 even if there is a match).

@erik4github
erik4github / selectedToLowerCase.js
Created February 6, 2020 18:56
Bookmarklet - Convert Selected Text To Lowercase
javascript:(function(window){
var selection = window.getSelection();
selection.baseNode.parentElement.innerText = selection.baseNode.textContent.toLowerCase();
})(window);
@erik4github
erik4github / searching-for-nested-keys.py
Last active July 24, 2019 14:27
find where a nested key is located in the dictionary
example_dict = {
'hello': {
'world': {
'nest': 'end'
}
}
}
def find_key(d, value):
for k,v in d.items():
@erik4github
erik4github / swap.js
Created May 9, 2019 02:49
JavaScript - Swap Array Elements
// if needed
const flat = arr => [].concat(...arr);
const swapArrow = arr => arr.map(v => ([v[0], v[1]] = [v[1], v[0]]));
const swapWithReverse = arr => arr.map(v => v.reverse());
function swap(arr) {
let swapped = [];
for (let i = 0; i < arr.length; i++) {
@erik4github
erik4github / collection.js
Created February 15, 2019 01:09
Animating URL bars
// use history.replaceState() instead of history.pushState() in order to not spam browser history
var f = ['๐ŸŒ‘', '๐ŸŒ’', '๐ŸŒ“', '๐ŸŒ”', '๐ŸŒ', '๐ŸŒ–', '๐ŸŒ—', '๐ŸŒ˜'];
function loop() {
location.hash = f[Math.floor((Date.now()/100)%f.length)];
setTimeout(loop, 50);
}
@erik4github
erik4github / regex-reference.md
Last active January 4, 2019 17:48
Regex Reference

Does Not Contain Question Marks (?) - Useful for Excluding Query Parameters in Reports

  • ^[^\?]*$

Filter By Excluding Matching Regex:

  • ^[^?]+(?.*)