Skip to content

Instantly share code, notes, and snippets.

@comame
Last active October 16, 2021 19:15
Show Gist options
  • Save comame/db013cc689954ef77c546872aa1f6fd1 to your computer and use it in GitHub Desktop.
Save comame/db013cc689954ef77c546872aa1f6fd1 to your computer and use it in GitHub Desktop.
stdin-reader
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};
const DEBUG = process.env.DEBUG
function test(...msg) {
if (DEBUG) console.log(...msg)
}
// const [ a, b, c ] = readMany(3)
(() => {
// code
})()
// cat $1 | DEBUG=1 node $1.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment