Skip to content

Instantly share code, notes, and snippets.

// Read line by line from a file.
const fs = require('fs');
const readline = require('readline');
const stream = require('stream')
function processFile(inputFile) {
const instream = fs.createReadStream(inputFile);
const outstream = new (stream)();
const rl = readline.createInterface(instream, outstream);
@AttilaGal
AttilaGal / logcolors.js
Last active October 15, 2018 07:58
console.log colors
console.log('\x1b[36m%s\x1b[0m', 'I am cyan', '\x1b[0m'); //cyan
console.log('\x1b[33m%s\x1b[0m', stringToMakeYellow, '\x1b[0m'); //yellow
// Colors reference
// Reset = "\x1b[0m"
// Bright = "\x1b[1m"
@AttilaGal
AttilaGal / tryCatch.js
Last active June 19, 2018 14:35
express tryCatch helper
************************************************************
the helper function
************************************************************
const tryCatch = (func) => (req, res, next) => {
try {
await func(req, res, next);
} catch (err) {
next(err);
}
};
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js",
"protocol": "inspector",
"runtimeExecutable": "nodemon",
"restart": true
}
this command removes all local branches which have already been merged into a main branch
git branch --merged | egrep -v "(^\*|master|development|test)" | xargs git branch -d
extra info found here: https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged
// jasmine only:
{
"name": "Tests",
"type": "node",
"protocol": "inspector",
"request": "launch",
"program": "${workspaceRoot}/node_modules/jasmine/bin/jasmine.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
@AttilaGal
AttilaGal / angularInsert.js
Last active December 11, 2016 15:20
adds and ES2015 import statement for angular in any js/ts file within a directory
/*
This is a helper script that can be used to recursively insert an
angular import statement into all .ts files in a given directory.
call:
node renamer <directory>
*/
var fs = require('fs');
var path = require('path');
var linesert = require( "linesert" );
@AttilaGal
AttilaGal / renamer.js
Last active April 19, 2022 19:28
rename all js to ts recursively
/*
This is a helper script that can be used to recursively rename all
JavaScript files within a given directory into TypeScript files.
call:
node renamer <directory>
*/
var fs = require('fs');
var path = require('path');
var ANSI_GREEN = '\x1b[32m';