Skip to content

Instantly share code, notes, and snippets.

View egdavid's full-sized avatar
🏠
Working from home

David Eugene egdavid

🏠
Working from home
  • France
  • 00:20 (UTC +01:00)
View GitHub Profile
@egdavid
egdavid / gist:ed05c390bc4e567b92c037ddc0e2d2b5
Created March 2, 2022 19:40
Clean Await promise.all()
const callMethod = (methodName, ...params) => obj => obj[methodName](...params)
const awaitAll = promiseArray => Promise.all(promiseArray)
const prop = propName => obj => obj[propName]
const map = func => arr => arr.map(func)
const pipe = (...functions) => functions.reduce((compound, func) => (input => func(compound(input))))
const download = url => fetch(url).then(callMethod("json"))
download(
"http://swapi.co/api/people/2/"
)
@egdavid
egdavid / puppeteer-axios-pdf.js
Last active March 11, 2023 16:18
Getting a PDF from an URL in a secured session in NodeJS using Puppeteer, FileSystem, Axios and HTTPS
/**
* Download a file (PDF in this case) from a secure URL after puppeteer login
**/
// Puppeteer init
const browser = await puppeteer.launch(puppeteerOptions);
const page = await browser.newPage();
page.setViewport({ width: 1366, height: 768 });
// Add login logic