Skip to content

Instantly share code, notes, and snippets.

View senthilmpro's full-sized avatar

Senthil Muthuvel senthilmpro

View GitHub Profile
@senthilmpro
senthilmpro / angular-keypress-together.js
Created November 21, 2019 06:46
angular-keypress-together.js
export class AppComponent {
title = 'ui';
keys = {
space : false,
ctrl : false
}
@HostListener('window:keydown', ['$event'])
keyEventDown(event: KeyboardEvent) {
if(event.keyCode === 17){
@senthilmpro
senthilmpro / delay-es6.js
Created November 12, 2019 02:57
es6-javascript-wait-function-promise
/**
* Sets a delay for 'wait' milliseconds
* @param {Number} wait - wait time in milliseconds
*/
let delay = async (wait) => {
console.log(`Waiting for ${wait} milliseconds`);
return new Promise(p => setTimeout(p, wait));
}
@senthilmpro
senthilmpro / deep-flatten-array-js.js
Created October 23, 2019 18:55
Deep Flatten Array - Javascript
function deepFlatten(arr){
return [].concat.apply([], arr.map(x => Array.isArray(x) ? deepFlatten(x) : x));
}
@senthilmpro
senthilmpro / fastify-server.js
Created April 16, 2019 22:01
fastify-server setup
const fastify = require('fastify')({ logger: true });
const axios = require('axios');
const path = require('path');
const routes = require('./routes/route');
//console.log(route);
routes.forEach((route, index) => {
fastify.route(route)
});
@senthilmpro
senthilmpro / read-files-from-folder.js
Created April 1, 2019 23:24
Node.js Read files from Folder
const path = require('path');
const fs = require('fs');
function readFilesFromDir(dir) {
var filelist = [];
walkSync(dir, filelist);
return filelist;
}
@senthilmpro
senthilmpro / create-acc-arch1ve-new.js
Last active April 27, 2024 05:26
create-acc-arch1ve-new.js
async function createAccount(){
var USER_PREFIX = 'USERNAME'; // change here.
var USER_PASS = 'PASSWORD'; // change-here
var TIMER_DELAY = 400;
// username
await delay(TIMER_DELAY);
var randomGuid = guid();
@senthilmpro
senthilmpro / host-local-files.js
Created March 28, 2019 04:25
host local files serve-index
var express = require('express'),
directory = require('serve-index'),
app = new express();
var hourMs = 1000*60*60;
app.use(express.static(__dirname + '/public', { maxAge: hourMs }));
app.use(directory(__dirname + '/public', { 'view' : 'details'}));
app.listen(4433);
@senthilmpro
senthilmpro / downloader.js
Created March 6, 2019 23:37
Node.js downloader.js
var fs = require('fs');
var axios = require('axios');
const async = require('async');
const path = require('path');
const DL_INTERVAL_TIMER = 500; //in milliseconds.
module.exports = {
createFolder: function (dir) {
if (!fs.existsSync(dir)) {
@senthilmpro
senthilmpro / read-files-in-a-folder.js
Last active February 14, 2019 00:20
node.js read files from a directory
//requiring path and fs modules
const path = require('path');
const fs = require('fs');
/**
* Read contents of files inside a folder.
* @param {*} folderName
* @param {*} rootDir
*
* @example : readFolder("data", __dirname)
@senthilmpro
senthilmpro / mongo-db-connect.js
Created November 27, 2018 22:34
Node.js MongoDB connect
var db = null // global variable to hold the connection
MongoClient.connect('mongodb://localhost:27017/', function(err, client) {
if(err) { console.error(err) }
db = client.db('test') // once connected, assign the connection to the global variable
})
app.get('/', function(req, res) {
db.collection('test').find({}).toArray(function(err, docs) {
if(err) { console.error(err) }