This file contains hidden or 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 resolveAfter2Seconds(x) { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| resolve(x); | |
| }, 2000); | |
| }); | |
| } | |
| async function add1(x) { |
This file contains hidden or 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 puppeteer = require('puppeteer'); | |
| let scrape = async () => { | |
| // Actual Scraping goes Here... | |
| // Return a value | |
| }; | |
| scrape().then((value) => { | |
| console.log(value); // Success! |
This file contains hidden or 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 puppeteer = require('puppeteer'); | |
| let scrape = async () => { | |
| const browser = await puppeteer.launch({headless: false}); | |
| const page = await browser.newPage(); | |
| await page.goto('http://books.toscrape.com/'); | |
| await page.click('#default > div > div > div > div > section > div:nth-child(2) > ol > li:nth-child(1) > article > div.image_container > a > img'); | |
| await page.waitFor(1000); |
This file contains hidden or 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 puppeteer = require('puppeteer'); | |
| let scrape = async () => { | |
| const browser = await puppeteer.launch({headless: false}); | |
| const page = await browser.newPage(); | |
| await page.goto('http://books.toscrape.com/'); | |
| const result = await page.evaluate(() => { | |
| let data = []; // Create an empty array that will store our data |
This file contains hidden or 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 doubleAfter2Seconds(x) { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| resolve(x * 2); | |
| }, 2000); | |
| }); | |
| } | |
| function addPromise(x){ | |
| return new Promise(resolve => { |
This file contains hidden or 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 doubleAfter2Seconds(x) { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| resolve(x * 2); | |
| }, 2000); | |
| }); | |
| } | |
| async function addAsync(x) { | |
| const a = await doubleAfter2Seconds(10); |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.11.0/d3.min.js"></script> | |
| <script src="https://d3js.org/d3-selection-multi.v1.min.js"></script> | |
| <title>D3</title> | |
| </head> |
This file contains hidden or 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 w = 400, h = 250; | |
| const padding = 4; | |
| const data = [50,100,150,200,250,130,210,30,170]; | |
| let svg = d3.select('body') | |
| .append('svg') | |
| .attr('width', w) | |
| .attr('height', h); | |
| svg.selectAll('rect') |
This file contains hidden or 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 arrMax = arr => Math.max(...arr); | |
| // arrMax([20, 10, 5, 10]) -> 20 |
This file contains hidden or 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 arrMin = arr => Math.min(...arr); | |
| // arrMin([20, 10, 5, 10]) -> 5 |