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 searchParams = Array.from(new URLSearchParams(location.search).entries()).reduce((result, [key, value]) => ({ ...result, [key]: value }), {}); |
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
function useLayoutEffectDebug(fn, deps) { | |
const [lastDeps, setLastDeps] = useState([]); | |
useLayoutEffect(() => { | |
console.log({ lastDeps, deps }); | |
lastDeps && console.log(deps.findIndex((value, index) => value !== lastDeps[index])); | |
setLastDeps(deps); |
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
<!DOCTYPE html> | |
<!-- Very unpolished, just for the very short purpose --> | |
<html lang="en-US"> | |
<head> | |
<title>Render logo</title> | |
<script type="text/javascript"> | |
(async function () { | |
'use strict'; | |
const SIZE = 192; |
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
// executeAsyncScript is not running a Promise function and is not able to deal with errors. | |
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html#executeAsyncScript | |
// This function will use executeAsyncScript to run a Promise function in an async fashion. | |
export default async function executePromiseScript(driver, fn, ...args) { | |
const { error, result } = await driver.executeAsyncScript((fn, args, callback) => { | |
eval(`(${fn})`).apply(null, args).then(result => callback({ result }), error => callback({ error })); | |
}, fn + '', args); | |
if (error) { |
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 http2 = require('http2'); | |
function main() { | |
const server = http2.createSecureServer({ | |
cert: CERTIFICATE, | |
key: PRIVATE_KEY | |
}); | |
server.on('error', err => console.error(err)); |
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
function asyncToDone(task: () => Promise<any>) { | |
return function (done: (err?: Error) => void) { | |
task().then(() => done(), done); | |
} | |
} |
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
interface IDeferred<T> { | |
promise: () => Promise<T>, | |
resolve: (result: T) => void, | |
reject: (error: Error) => void | |
} | |
function createDeferred<T>(): Promise<IDeferred<T>> { | |
return new Promise<IDeferred<T>>(resolveCreate => { | |
const promise = new Promise<T>(function (resolve, reject) { | |
resolveCreate({ promise: () => promise, resolve, reject }); |
NewerOlder