Skip to content

Instantly share code, notes, and snippets.

View frankiehayward's full-sized avatar

Frankie Hayward frankiehayward

View GitHub Profile
@frankiehayward
frankiehayward / facebook_pixel.js
Created December 5, 2019 23:25
This is a template prototype for the Facebook Pixel.
// Create Permissions
const copy = require('copyFromWindow');
const set = require('setInWindow');
const alias = require('aliasInWindow');
const queue = require('createQueue');
const call = require('callInWindow');
const map = require('makeTableMap');
const log = require('logToConsole');
const script = require('injectScript');
@frankiehayward
frankiehayward / adara_pixel.js
Last active December 5, 2019 23:25
This is a template prototype for the Adara tracking script.
// Add Permissions
const map = require('makeTableMap');
const log = require('logToConsole');
const send = require('injectScript');
// Get Properties
const props = data.propertyList ? map(data.propertyList, 'name', 'value') : {};
// Build Url
let url = '//tag.yieldoptimizer.com/ps/ps?t=s';
@frankiehayward
frankiehayward / sojern_pixel.js
Last active December 5, 2019 23:25
This is a template prototype for the Sojern tracking script.
// Add Permissions
const map = require('makeTableMap');
const log = require('logToConsole');
const send = require('injectScript');
// Get Properties
const props = data.propertyList ? map(data.propertyList, 'name', 'value') : {};
// Build Url
let url = '//beacon.sojern.com/pixel/p/' + data.pixelId + '?f_v=v6_js&p_v=3';
@frankiehayward
frankiehayward / is_boolean.js
Created December 5, 2019 23:17
This snippet can be used to check whether an argument is a boolean.
const isBoolean = val => typeof val === 'boolean';
isBoolean(null); // false
isBoolean(false); // true
@frankiehayward
frankiehayward / is_before_date.js
Created December 5, 2019 23:16
This snippet can be used to check whether a date is before another date.
const isBeforeDate = (dateA, dateB) => dateA < dateB;
isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true
@frankiehayward
frankiehayward / is_array_like.js
Created December 5, 2019 23:15
This snippet can be used to check if a provided argument is iterable like an array.
const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function';
isArrayLike(document.querySelectorAll('.className')); // true
isArrayLike('abc'); // true
isArrayLike(null); // false
@frankiehayward
frankiehayward / is_anagram.js
Created December 5, 2019 23:15
This snippet can be used to check whether a particular string is an anagram with another string.
const isAnagram = (str1, str2) => {
const normalize = str =>
str
.toLowerCase()
.replace(/[^a-z0-9]/gi, '')
.split('')
.sort()
.join('');
return normalize(str1) === normalize(str2);
};
@frankiehayward
frankiehayward / is_after_date.js
Created December 5, 2019 23:13
This snippet can be used to check whether a date is after another date.
const isAfterDate = (dateA, dateB) => dateA > dateB;
isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true
@frankiehayward
frankiehayward / is.js
Created December 5, 2019 23:12
This snippet can be used to check if a value is of a particular type.
const is = (type, val) => ![, null].includes(val) && val.constructor === type;
is(Array, [1]); // true
is(ArrayBuffer, new ArrayBuffer()); // true
is(Map, new Map()); // true
is(RegExp, /./g); // true
is(Set, new Set()); // true
is(WeakMap, new WeakMap()); // true
is(WeakSet, new WeakSet()); // true
is(String, ''); // true
@frankiehayward
frankiehayward / intersection_with.js
Created December 5, 2019 23:11
This snippet can be used to return a list of elements that exist in both arrays by using a comparator function.
const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, y)) !== -1);
intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0]