Skip to content

Instantly share code, notes, and snippets.

Hugh Caluscusin MelodicCrypter

Block or report user

Report or block MelodicCrypter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@MelodicCrypter
MelodicCrypter / create-append-node.js
Created Aug 19, 2019
Two utilities that will create node and append node to that parent node you just created. I've seen these somewhere else so I just shared to you as well.
View create-append-node.js
// Utility for creating Nodes
export const createNode = element => {
return document.createElement(element);
};
// Utility for appending node to parent Node
export const appendNode = (parent, el) => {
return parent.appendChild(el);
};
@MelodicCrypter
MelodicCrypter / upload-stream-video.js
Created Aug 19, 2019
A NodeJS sample for uploading videos and then streaming the video with range feature. Multiparty is a NPM module for uploading file in Node.
View upload-stream-video.js
const { createServer } = require('http');
const { promisify } = require('util');
const multiparty = require('multiparty');
const {
stat,
createReadStream,
createWriteStream
} = require('fs');
const file = __dirname+'/powder-day.mp4';
@MelodicCrypter
MelodicCrypter / promisify-filesystem.js
Created Aug 19, 2019
A NodeJS sample of using Util's promisify to write a file.
View promisify-filesystem.js
const fs = require('fs');
const { promisify } = require('util');
const writeFile = promisify(fs.writeFile);
writeFile('sample.txt', 'this is a sample phrase')
.then(() => console.log('done!'))
.catch(e => console.log(e));
@MelodicCrypter
MelodicCrypter / piping-text.js
Created Aug 19, 2019
A NodeJS sample using Pipe that automatically logs whatever the user types in the console.
View piping-text.js
const { createWriteStream } = require('fs');
const writeStream = createWriteStream('./file-test.txt');
// using stdin, stream and pipe, this will automatically log all the text you will type
process.stdin.pipe(writeStream);
process.stdin.on('data', (data) => {
if (data.toString().toLowerCase().trim() === 'exit>this') {
process.exit();
@MelodicCrypter
MelodicCrypter / piping-video.js
Created Aug 19, 2019
A sample of NodeJS Pipe to copy a video file.
View piping-video.js
const { createReadStream, createWriteStream } = require('fs');
const readStream = createReadStream(__dirname+'/powder-day.mp4');
const writeStream = createWriteStream(__dirname+'/copy.mp4' );
// Pipe, will handle backpressure automatically
readStream
.pipe(writeStream)
.on('error', console.error);
@MelodicCrypter
MelodicCrypter / backpressure-stream.js
Created Aug 19, 2019
NodeJS sample for copying files using streams with backpressure.
View backpressure-stream.js
const { createReadStream, createWriteStream} = require('fs');
// You should include a real file live video, image, etc
const readStream = createReadStream(__dirname+'/powder-day.mp4');
const writeStream = createWriteStream(__dirname+'/copy.mp4', { highWaterMark: 1628920 });
// => flowing stream
readStream.on('data', (chunk) => {
// if this will be false, meaning the stream is full
const result = writeStream.write(chunk);
@MelodicCrypter
MelodicCrypter / advanced-emitter.js
Created Aug 19, 2019
NodeJS advanced EventEmitter.
View advanced-emitter.js
const EventEmitter = require('events').EventEmitter;
const util = require('util');
// constructor function
const Person = function(name) {
this.name = name;
};
// let Person inherit all the EventEmitter features
util.inherits(Person, EventEmitter);
@MelodicCrypter
MelodicCrypter / readline-with-stream.js
Created Aug 19, 2019
A NodeJS sample for readline with stream.
View readline-with-stream.js
const readline = require('readline');
const rl = readline.createInterface(process.stdin, process.stdout);
const fs = require('fs');
const aPerson = {
name: '',
sayings: []
};
// ask a question, then use the callback to use the user's answer
@MelodicCrypter
MelodicCrypter / readline-sample.js
Created Aug 19, 2019
A simple NodeJS readline sample.
View readline-sample.js
const readline = require('readline');
const rl = readline.createInterface(process.stdin, process.stdout);
const aPerson = {
name: '',
sayings: []
};
// ask a question, then use the callback to use the user's answer
rl.question('What is your name? ', (nameAnswer) => {
@MelodicCrypter
MelodicCrypter / uniqueGenerator.js
Last active Aug 8, 2019
A small javascript utility that will generate unique (hashed-type) strings.
View uniqueGenerator.js
// Your unique variables here
const allCapsAlpha = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"];
const allLowerAlpha = [..."abcdefghijklmnopqrstuvwxyz"];
const allUniqueChars = [...'~!@#$%^&*()_+`-=[]\\{}|;:\'",./<>?'];
const allNumbers = [..."0123456789"];
// This is the 'pattern', alternate the order if you want.
// The final output (order of pattern) will not be the same though,
// but you can improve this utility to achieve that.
const base = [...allCapsAlpha, ...allNumbers, ...allLowerAlpha, ...allUniqueChars];
You can’t perform that action at this time.