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 retry<T>(promise: () => Promise<T>, maxTries = 3): Promise<T> { | |
| return promise().catch(() => | |
| maxTries > 1 ? retry(promise, maxTries - 1) : promise() | |
| ); | |
| } |
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
| const countSelectedIssuePoints = () => $('.js-issue.ghx-selected .aui-badge.ghx-statistic-badge') | |
| .map((_, b) => +$(b).text()) | |
| .get() | |
| .reduce( | |
| (a,b) => a + (b || 0), | |
| 0, | |
| ); | |
| countSelectedIssuePoints(); // 3 |
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
| const preFetchImageSize = (url, checkInterval = 10) => new Promise((resolve, reject) => { | |
| const image = new Image(); | |
| image.src = url; | |
| image.onerror = reject; | |
| const interval = setInterval(() => { | |
| if (image.width + image.naturalWidth) { | |
| clearInterval(interval); | |
| resolve({ |
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
| const formatToDuration = milliseconds => { | |
| const seconds = Math.round(milliseconds / 1000); | |
| const s = Math.round(seconds % 60); | |
| const m = (Math.floor(seconds / 60) % 60); | |
| const h = (Math.floor(seconds / 60 / 60) % 24); | |
| const d = (Math.floor(seconds / 60 / 60 / 24)); | |
| return [ | |
| (d ? `${d}d` : ''), | |
| (h ? `${h}h` : ''), |
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
| const parseHex = hexString => hexString | |
| .match(/.{1,2}/g) | |
| .map(hex => String.fromCharCode(parseInt(hex, 16))) | |
| .join(''); |
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
| /** | |
| * Example: | |
| * observe('myProp').on(myObject); | |
| */ | |
| global.observe = (varName) => ({ | |
| on: (object) => { | |
| let value = object[varName]; | |
| Object.defineProperty( | |
| object, |
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
| const smoothScrollToTop = (element = document.body, interpolationFactor = 1.2) => | |
| Math.round(element.scrollTop /= interpolationFactor) ? | |
| setTimeout(smoothScrollToTop, 16.666, element) && true : false; |
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
| Array.prototype.shuffle = function() { | |
| return this | |
| .reduce( | |
| ([result, rest]) => { | |
| const random = (Math.random() * rest.length) >> 0; | |
| return [ | |
| result | |
| .concat(rest[random]), | |
| rest | |
| .slice(0, random) |
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
| 'use strict'; | |
| Promise.series = promises => | |
| ((results = []) => | |
| promises | |
| .reduce( | |
| (promise, current) => promise | |
| .then(current) | |
| .then(function () { | |
| results.push(arguments); |
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
| var todo = {a: [1, 2, 3]}; | |
| console.log((todo === { ...todo, a: [...todo.a] })); // false | |
| console.log((todo.a === { ...todo, a: [...todo.a] }.a)); // false | |
| console.log(todo, { ...todo, a: [...todo.a] }) // {"a":[1,2,3]} {"a":[1,2,3]} | |
| console.log([1,2,3,4].includes(1)) // true | |
| console.log([1,2,3,4].includes(5)) // false | |
| console.log(2 ** 8) // 256 |
NewerOlder