Skip to content

Instantly share code, notes, and snippets.

View MelodicCrypter's full-sized avatar

Hugh Caluscusin MelodicCrypter

View GitHub Profile
@MelodicCrypter
MelodicCrypter / next.config.js
Last active February 13, 2020 07:58
Using Bulma, Sass and Image Optimization with NextJS configuration.
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
const nextConfig = {
webpack(config, options) {
config.module.rules.push({
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: {
@MelodicCrypter
MelodicCrypter / .eslintignore
Last active September 14, 2020 03:59
Common Dev Dependencies and Their Configurations (ESLint and Prettier). Check all four files inside this gist. TL-DR: yarn add -D babel-eslint babel-plugin-module-resolver eslint eslint-config-airbnb eslint-config-prettier eslint-plugin-import eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks gatsby-plugin-eslint eslint-loader…
node_modules
.next
@MelodicCrypter
MelodicCrypter / common.gitignore
Last active December 6, 2019 13:12
Common gitignore stuffs that I have already generated using GitIgnore.io API. Included are Git, Node, React, React Native, MacOS, Windows, WebStorm, PhpStorm, JetBrains, and SublimeText.
# Created by https://www.gitignore.io/api/git,node,react,macos,windows,webstorm,phpstorm,jetbrains,reactnative,sublimetext
# Edit at https://www.gitignore.io/?templates=git,node,react,macos,windows,webstorm,phpstorm,jetbrains,reactnative,sublimetext
### Git ###
# Created by git for backups. To disable backups in Git:
# $ git config --global mergetool.keepBackup false
*.orig
# Created by git when using merge tools for conflicts
*.BACKUP.*
@MelodicCrypter
MelodicCrypter / create-append-node.js
Created August 19, 2019 08:25
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.
// 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 August 19, 2019 06:38
A NodeJS sample for uploading videos and then streaming the video with range feature. Multiparty is a NPM module for uploading file in Node.
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 August 19, 2019 06:30
A NodeJS sample of using Util's promisify to write a file.
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 August 19, 2019 06:26
A NodeJS sample using Pipe that automatically logs whatever the user types in the console.
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 August 19, 2019 06:22
A sample of NodeJS Pipe to copy a video file.
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 August 19, 2019 06:20
NodeJS sample for copying files using streams with backpressure.
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 August 19, 2019 06:16
NodeJS advanced EventEmitter.
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);