This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delay(timeout) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, timeout); | |
}); | |
} | |
/** | |
* then use it like this. | |
* async function f1() { | |
* await delay(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// async download | |
const axios = require("axios"), | |
fs = require("fs"), | |
path = require("path"); | |
const SUB_FOLDER = ""; | |
const IMG_NAME = "img.jpg"; | |
/** | |
* this will dl.image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir | rename-item -NewName {$_.name -replace " ","_"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
OlderNewer