Skip to content

Instantly share code, notes, and snippets.

View senthilmpro's full-sized avatar

Senthil Muthuvel senthilmpro

View GitHub Profile
@senthilmpro
senthilmpro / script-block-images-puppeteer.js
Last active May 3, 2018 17:12
Block images from loading - Google Puppeteer
'use strict';
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', request => {
if (request.resourceType() === 'image')
@senthilmpro
senthilmpro / axios-async-download-js.js
Created May 4, 2018 23:05
Axios async download in nodeJS
// async download
const axios = require("axios"),
fs = require("fs"),
path = require("path");
const SUB_FOLDER = "";
const IMG_NAME = "img.jpg";
/**
* this will dl.image
@senthilmpro
senthilmpro / create-folder-node-js.js
Created May 6, 2018 20:26
Create folder into disk. ( check for existing folder)
const fs = require('fs');
// CREATE FOLDER
function createFolder(folderName) {
if (!fs.existsSync(folderName)) {
fs.mkdirSync(folderName, 0766, function (err) {
console.log(err);
});
} else {
console.log("ERROR >> cannot create folder. Folder already exists");
@senthilmpro
senthilmpro / bulk-rename-files.ps1
Created July 29, 2018 19:02
powershell rename bulk files in folder
dir | rename-item -NewName {$_.name -replace " ","_"}
@senthilmpro
senthilmpro / logging.js
Created August 17, 2018 19:31
Winston - Node.js basic logging example
const winston = require('winston');
var logger = winston.createLogger({
level : 'info',
format : winston.format.json(),
transports : [
new winston.transports.File({
filename : 'logs/error.log',
level : 'error'
}),
@senthilmpro
senthilmpro / daylight-ie.js
Created September 12, 2018 23:53
Internet Explorer Daylight savings - detect using Javascript
function stdTimezoneOffset() {
var d = new Date();
var jan = new Date(d.getFullYear(), 0, 1);
var jul = new Date(d.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
/**
* Gets offset of current timezone and calculates if it has daylight timings enabled.
* @returns {boolean}
@senthilmpro
senthilmpro / export-file-names-windows.ps1
Last active November 21, 2018 23:03
output list of files in a directory to file - windows powershell
Get-ChildItem -Path L:\senthil\ –Recurse | Out-File -filepath all-files-senthil.txt
@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 / 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 / async-await-es6-angular.js
Created November 21, 2019 22:25
async-await-es6-angular.js
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class AuthService {
httpClient : HttpClient;
constructor(httpClient : HttpClient) {
this.httpClient = httpClient;