This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ios10 stop pinch and zoom | |
function prevent(e) { e.preventDefault() } | |
document.body.addEventListener('gesturechange', prevent); | |
document.body.addEventListener('gesturestart', prevent); | |
document.body.addEventListener('gestureend', prevent); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function waitUntil(options) { | |
options = options || {}; | |
options.timeout = options.timeout || 1000; | |
var elapsed = 0; | |
var handle = setInterval(function() { | |
if (options.rule()) { | |
if (typeof options.success === "function") options.success(); | |
if (typeof options.complete === "function") options.complete(); | |
return clearInterval(handle); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debounce(cb, time) { | |
var handle = null; | |
var func = function() { | |
func.cancel(); | |
handle = setTimeout(cb, time); | |
}; | |
func.cancel = function() { | |
if (!handle) return; | |
clearTimeout(handle); | |
handle = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DeferredPromise extends Promise { | |
constructor(def = (res, rej)=>{}) { | |
let res, rej; | |
super((resolve, reject)=>{ | |
def(resolve, reject); | |
res = resolve; | |
rej = reject; | |
}); | |
this.resolve = res; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function csvToJSON(data) { | |
var rows = [['']]; | |
for (var i = 0, l = data.length, char = data[i], wasInSpeechMarks = false, isInSpeechMarks = false; i < l; char = data[++i]) { | |
if (wasInSpeechMarks && char !== "," && char !== "\n" && char !== "\r") { // skip after speech mark waiting for new column or row | |
} else if (isInSpeechMarks && char === '"' && data[i+1] !== '"') { // at end of speechmark block | |
isInSpeechMarks = false; | |
wasInSpeechMarks = true; | |
} else if (isInSpeechMarks || char !== '"' && char !== "," && char !== "\n" && char !== "\r") { // is in speechmarks or not a new colum or row | |
if (isInSpeechMarks && char === '"' && data[i+1] === '"') i++; // is in speechmarks at a double quote | |
rows[rows.length-1][rows[rows.length-1].length-1] += char; // add character to current cell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function multiplyOut (matrix) { | |
const partLengths = matrix.map(part => part.length) // how large each part is [3, 3, 2] | |
const subPartIndices = '0'.repeat(matrix.length).split('').map(Number) // how far we've gone in each part [0, 0, 0] | |
let isEnded = false | |
const sumsToPerform = [] | |
while (isEnded === false) { | |
sumsToPerform.push(subPartIndices.reduce((sum, subPartIndex, partIndex) => { | |
sum.push(matrix[partIndex][subPartIndex]) | |
return sum | |
}, [])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
// function for adding bionic style to a node | |
function process (n) { | |
if (n._isBionic) return; | |
const ns = [...n.childNodes] | |
.filter(n => n.nodeType === n.TEXT_NODE) | |
.filter(n => n.nodeValue.trim()); | |
if (!ns.length) return; | |
ns.forEach(function apply(n) { | |
const pn = n.parentNode; |