TLDR: Use for...of instead of forEach() in asynchronous code.
For legacy browsers, use for(...;...;...) or [].reduce()
To execute the promises in parallel, use Promise.all([].map(...))
| document.body.innerHTML = 'Paste or drop items onto this page. View results in console.'; | |
| function getPayload(item) { | |
| const kind = item.kind; | |
| switch (kind) { | |
| case 'string': return new Promise(res => item.getAsString(res)); | |
| case 'file': return Promise.resolve(item.getAsFile()); | |
| default: throw new Error('unknown item kind! ' + kind); | |
| } |
| const { createLogger, format, transports } = require("winston"); | |
| // https://github.com/winstonjs/winston#logging | |
| // { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 } | |
| const level = process.env.LOG_LEVEL || "debug"; | |
| function formatParams(info) { | |
| const { timestamp, level, message, ...args } = info; | |
| const ts = timestamp.slice(0, 19).replace("T", " "); |
Enter this in the search box along with your search terms:
Get all gists from the user santisbon.
user:santisbon
Find all gists with a .yml extension.
extension:yml
Find all gists with HTML files.
language:html
| // https://hg.mozilla.org/mozilla-central/rev/2f9043292e63 | |
| // Used to detect minification for automatic pretty printing | |
| const SAMPLE_SIZE = 30; // no of lines | |
| const INDENT_COUNT_THRESHOLD = 20; // percentage | |
| function isMinified (str) { | |
| let isMinified; | |
| let lineEndIndex = 0; | |
| let lineStartIndex = 0; | |
| let lines = 0; |
Some quick thoughts on https://twitter.com/dan_abramov/status/884892244817346560. It's not ignorant at all to ask how browser vendors approach performance. On the V8 side we've discussed bytecode precompilation challenges a few times this year. Here's my recollection of where we stand on the idea:
JavaScript engines like V8 have to work on multiple architectures. Every version of V8 is different. The architectures we target are different. A precompiled bytecode solution would require a system (e.g the server or a CDN) to generate bytecode builds for every target architecture, every version of V8 supported and every version of the JavaScript libraries or bundles bytecode is being generated for. This is because we would need to make sure every user accessing a page using that bytecode can still get the final JS successfully executed.
Consider that if a cross-browser solution to this problem was desired, the above would need to be applied to JavaScriptCore, SpiderMonkey and Chakra as well. It would need to ca