Skip to content

Instantly share code, notes, and snippets.

@erik4github
erik4github / README.md
Created August 24, 2022 03:57
Normalize Git line endings

often I get annoying CRLF to LF issues when using an editor that doesn't let you specify default line endings like Obsidian, which is super annoying when syncing notes across devices

so here's a script to use. if you want to filter (e.g. only markdown files) you can pass it as an arg like normalize *[.md]

@erik4github
erik4github / schema.json
Last active October 15, 2021 19:24
HubSpot CMS Modules JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"title": "HubSpot Module",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The variable name you will use to refer to this field's values, and is what the value of the field is stored against. Cannot contain spaces or special characters.",
@erik4github
erik4github / OrgIsSandBoxClass.cls
Last active March 18, 2021 21:35
Determine if Salesforce org is sandbox in case there's something you need to enable on sandboxes but not prod
@TestVisible
private static Boolean orgIsSandbox {
get {
if (orgIsSandbox == null) {
orgIsSandbox = [SELECT IsSandbox FROM Organization LIMIT 1].IsSandbox;
}
return orgIsSandbox;
}
set;
}
@erik4github
erik4github / apex.json
Created March 11, 2021 22:57
Apex User Snippets for VSCode
{
"InvocableMethod": {
"prefix": "InvocableMethod",
"body": [
"@InvocableMethod(label='$1' description='$2' callout=${3|true,false|} category='$4' configurationEditor='$5')"
],
"description": "Apex InvocableMethod Annotation, @see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm"
},
"InvocableVariable": {
"prefix": "InvocableVar",
@erik4github
erik4github / Dotenv Outside Current Dir.md
Created February 18, 2021 04:19
Load dotenv .env file outside of current directory
  • /.env
    • /server/package.json

node -r dotenv/config index.ts dotenv_config_path=../.env

@erik4github
erik4github / sfdx_export
Created December 1, 2020 22:45
Export records via SFDX into CSV or JSON
#!/bin/bash
# CSV with SOQL example
sfdx force:data:soql:query -q "SELECT Name, Username, Email FROM User WHERE IsActive = True" --resultformat csv | paste -sd '\n' >| sf_users.csv
# JSON with SOQL Example
sfdx force:data:soql:query -q "SELECT Name, Username, Email FROM User WHERE IsActive = True" --resultformat json >> sf_users.json
@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/

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