Skip to content

Instantly share code, notes, and snippets.

@erik4github
erik4github / drip.wistia-identify-audience.js
Last active April 5, 2018 17:02
Identify Wistia video play audience based on Drip email address
window._wq = window._wq || [];
window._wq.push({
id: "_all",
onReady: function(video) {
video.bind("play", function() {
_dcq.push([
"identify",
{
success: function(response) {
video.email(response.email);
@erik4github
erik4github / vanilla-serialize.js
Created April 13, 2018 19:31
Vanilla JavaScript equivalent of jQuery serialize
Array.from(new FormData(formElement), event =>
event.map(encodeURIComponent).join("=")
).join("&");
@erik4github
erik4github / hubspot-gtm-gdpr-cookie.js
Created May 30, 2018 16:49
HubSpot - Google Tag Manager - GDPR Opt-Out Listener.
@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:

  • ^[^?]+(?.*)
@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 / 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 / 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 / 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 / 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 / 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/

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