# lsof -t -i tcp:<PORT_TO_KILL> -s tcp:listen | sudo xargs kill
$ lsof -t -i tcp:80 -s tcp:listen | sudo xargs kill
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
| /** | |
| * See {@link http://99-bottles-of-beer.net|99 Bottles of Beer} | |
| */ | |
| function bottles(i) { | |
| return i === 0 ? 'no more bottles' : `${i} bottle${i > 1 ? 's' : ''}`; | |
| } | |
| function beer(i) { | |
| const str = bottles(i); |
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 splitFetch(data, chunk = 50) { | |
| return Promise.all(Array.from(Array(Math.ceil(data.length / chunk)), (_, i) => { | |
| return Promise.all(data.slice(i * chunk, (chunk * (i + 1))).map(() => fetch('https://example.com'))); | |
| })); | |
| } | |
| (async () => { | |
| console.time('split'); | |
| await splitFetch(Array.from(Array(1e3))).then(console.log).catch(console.error); | |
| console.timeEnd('split'); |
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 main() { | |
| console.log('a'); | |
| const a = new Promise((resolve) => { | |
| resolve('b'); | |
| console.log('c'); | |
| }).then(console.log); | |
| setTimeout(async () => { | |
| b(); |
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
| /** | |
| * | |
| * Given an array of integers, | |
| * return indices of the two numbers such that they add up to a specific target. | |
| * | |
| * You may assume that each input would have exactly one solution, | |
| * and you may not use the same element twice. | |
| * | |
| * Example: | |
| * |
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
| // From https://developers.google.com/public-data/docs/canonical/countries_csv |
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 rdc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
| const rdi = '1234567890'; | |
| const rdl = 'abcdefghijklmnopqrstuvwxyz'; | |
| const ipt = '6'; | |
| const rd = [ | |
| ...rdi | |
| ]; | |
| Array.from(Array(ipt.length)).reduce((p, n) => p + rd[Math.floor(Math.random() * rd.length)], ''); |
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 isANumber(n) { | |
| // return !Number.isNaN(+n) | |
| // && /^\-?\d*(\.\d*)?(e(\+|\-)?\d+)?$/i.test( | |
| // Array.isArray(n) || (typeof n === 'string' && !n.length) | |
| // ? NaN | |
| // : n | |
| // ); | |
| // } | |
| /** NOTE: A better version to detect Symbol */ |