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
#!/bin/sh | |
# Init prettier config | |
cat <<EOF > ./.prettierrc.js | |
module.exports = { | |
arrowParens: "always", | |
printWidth: 100, | |
semi: true, | |
singleQuote: false, | |
tabWidth: 2, |
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
// Uses baseline mode of h264 encoding, and ensures that dimensions are divisible by 2 | |
ffmpeg -r 30 -f image2 -i "%04d.png" -c:v libx264 -profile:v baseline -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -an -crf 17 output.mp4 | |
// with 2x speed | |
ffmpeg -r 30 -f image2 -i "%04d.png" -c:v libx264 -profile:v baseline -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -an -crf 17 -filter:v "setpts=0.5*PTS" ./mp4/output-2.mp4 |
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
for(var i = 0; i < 3; i++) { | |
setTimeout(function() { | |
console.log(i) | |
}, 200) | |
} | |
// output: 3 | |
// output: 3 | |
// output: 3 |
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 fromArray = require('from2-array'); | |
const through = require('through2'); | |
const fs = require('fs'); | |
const concatFiles = (destination, files, callback) => { | |
const destStream = fs.createWriteStream(destination); | |
fromArray.obj(files) // [1] | |
.pipe(through.obj((file, encoding, done) => { // [2] | |
const src = fs.createReadStream(file); // [3] | |
src.pipe(destStream, { end: false }); // [4] |
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 stream = require('stream'); | |
class ReplaceStream extends stream.Transform { | |
constructor(searchString, replaceString) { | |
super(); | |
this.searchString = searchString; | |
this.replaceString = replaceString; | |
this.tailPiece = ''; | |
} |
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 stream = require('stream'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const mkdirp = require('mkdirp'); | |
class ToFileStream extends stream.Writable { | |
constructor() { | |
super({ objectMode: true }); // [1] | |
} |
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 Chance = require('chance'); | |
const http = require('http'); | |
const chance = new Chance(); | |
http.createServer((req, res) => { | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
const generateMore = () => { | |
while(chance.bool({ likelihood: 95 })) { | |
let shouldContinue = res.write( |
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 Chance = require('chance'); | |
const http = require('http'); | |
const chance = new Chance(); | |
http.createServer((req, res) => { | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
while(chance.bool({ likelihood: 95 })) { | |
res.write(chance.string() + '\n'); | |
} | |
res.end('\n The end... \n') |
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 stream = require('stream'); | |
const Chance = require('chance'); | |
const chance = new Chance(); | |
class RandomStream extends stream.Readable { | |
constructor(options) { | |
super(options); | |
} | |
_read(size) { |
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
process.stdin | |
.on('data', (chunk) => { | |
console.log(`Chunk read: (${chunk.length}) "${chunk.toString()}"`); | |
}) | |
.on('end', () => process.stdout.write('End of stream')); |
NewerOlder