This file contains 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 depromise = <T>(promise: Promise<T>): T => { | |
let result: T | undefined; | |
let error: Error | undefined; | |
let isPromisePending = true; | |
promise | |
.then((res) => { | |
result = res; | |
isPromisePending = false; | |
}) |
This file contains 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
// Helper methods | |
const hex_decode = (s) => | |
Uint8Array.from(s.match(/.{1,2}/g).map((b) => parseInt(b, 16))); | |
const hex_encode = (u) => | |
Array.from(u).map((b) => b.toString(16).padStart(2, '0')).join('') | |
const ascii_decode = (s) => | |
Uint8Array.from(Array.from(s).map((l) => l.charCodeAt(0))) |
This file contains 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
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
const getList = () => | |
fetch( | |
'https://raw.githubusercontent.com/VGraupera/1on1-questions/master/questions.json' | |
) | |
.then(r => r.json()) |
This file contains 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
// Issue is it polutes user's history | |
const loader = (prefix='', frames = ['🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘'], index = 0, interval = 100) => | |
setInterval(() => { | |
history.pushState(null, '', `${prefix}${frames[index]}`) | |
index = (index+1) % frames.length | |
}, interval) | |
// To add `loader` as a searchParams | |
let url = new URL(location.href) | |
url.searchParams.append('loader', '') |