I hereby claim:
- I am frankiehayward on github.
- I am frankiehayward (https://keybase.io/frankiehayward) on keybase.
- I have a public key ASB2vkbDQp7lKwlSOgD4qh3ABtg2RH0aooVlCu2kG03YvQo
To claim this, I am signing this object:
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
<!-- Superscript Replace --> | |
<script> | |
(function($){ | |
$('p,h1,h2,h3,h4,h5,h6').each(function(i){ | |
var $this = $(this); | |
if (($this.text().indexOf("®") !== -1) || ($this.text().indexOf("®") !== -1)) { | |
$this.html($this.html().replace(/(<sup>)?(®|®)(<\/sup>)?/gi, '<sup>®</sup>')); | |
} | |
if (($this.text().indexOf("™") !== -1) || ($this.text().indexOf("™") !== -1)) { | |
$this.html($this.html().replace(/(<sup>)?(™|™)(<\/sup>)?/gi, '<sup>™</sup>')); |
I hereby claim:
To claim this, I am signing this object:
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon; | |
approximatelyEqual(Math.PI / 2.0, 1.5708); // true |
const arrayToCSV = (arr, delimiter = ',') => | |
arr.map(v => v.map(x => `"${x}"`).join(delimiter)).join('\n'); | |
arrayToCSV([['a', 'b'], ['c', 'd']]); // '"a","b"\n"c","d"' | |
arrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '"a";"b"\n"c";"d"' |
const arrayToHtmlList = (arr, listID) => | |
(el => ( | |
(el = document.querySelector('#' + listID)), | |
(el.innerHTML += arr.map(item => `<li>${item}</li>`).join('')) | |
))(); | |
arrayToHtmlList(['item 1', 'item 2'], 'myListID'); |
const attempt = (fn, ...args) => { | |
try { | |
return fn(...args); | |
} catch (e) { | |
return e instanceof Error ? e : new Error(e); | |
} | |
}; | |
var elements = attempt(function(selector) { | |
return document.querySelectorAll(selector); | |
}, '>_>'); |
const averageBy = (arr, fn) => | |
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) / | |
arr.length; | |
averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 5 | |
averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 5 |
const bifurcateBy = (arr, fn) => | |
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]); | |
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); | |
// [ ['beep', 'boop', 'bar'], ['foo'] ] |
const bottomVisible = () => | |
document.documentElement.clientHeight + window.scrollY >= | |
(document.documentElement.scrollHeight || document.documentElement.clientHeight); | |
bottomVisible(); // true |