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 / script-replace-selector-content.js
Created May 3, 2018 17:10
Replace HTML Selector inner text/ content via Google Puppeteer script
async function setSelectVal(sel, val) {
await page.evaluate((data) => {
// this innerHTML can be replaced with .value (based on HTML type)
return document.querySelector(data.sel).innerHTML = data.val;
}, {sel, val});
}
@senthilmpro
senthilmpro / async-time-delay.js
Created May 3, 2018 17:11
Asynchronously (await) delay timer
function delay(timeout) {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}
/**
* then use it like this.
* async function f1() {
* await delay(3000);
@senthilmpro
senthilmpro / axios-download-image-to-disk.js
Created May 4, 2018 22:54
Download Images to Disk using Axios JS
// sample code to DL using axios.
const axios = require("axios"),
fs = require("fs"),
path = require("path");
const SUB_FOLDER = "";
const IMG_NAME = "img.jpg";
/**
* this will dl.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 / download-file-axios-nodejs.js
Last active August 2, 2024 13:33
Download File using axios : Node.js program
'use strict'
const Fs = require('fs')
const Path = require('path')
const Axios = require('axios')
async function downloadImage () {
const url = 'https://unsplash.com/photos/AaEQmoufHLk/download?force=true'
const path = Path.resolve(__dirname, 'images', 'code1.jpg')
@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}