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 dimensions = await page.evaluate(() => { | |
| let sources = []; // an array of the links to each image | |
| document.querySelectorAll( | |
| "#react-root > div > div > div > main > div > div.css-1dbjc4n.r-aqfbo4.r-1niwhzg.r-16y2uox > div > div.css-1dbjc4n.r-14lw9ot.r-1tlfku8.r-1ljd8xs.r-13l2t4g.r-1phboty.r-1jgb5lz.r-1ye8kvj.r-13qz1uu.r-184en5c > div > div > div.css-1dbjc4n.r-1jgb5lz.r-1ye8kvj.r-6337vo.r-13qz1uu > div > section > div > div > div img" | |
| ).forEach(img => { | |
| if (img.src) { | |
| sources.push(img) | |
| } | |
| }); |
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
| import puppeteer from "puppeteer"; // import the npm package that we installed | |
| (async () => { | |
| // the rest of the code must be enclosed in an `async` function to be able to `await` for results | |
| const browser = await puppeteer.launch(); // launches an "invisible" chromium browser | |
| const page = await browser.newPage(); // takes the browser to a new tab (page) | |
| await page.goto("https://example.com"); // takes the page to a specific url | |
| // Get the "viewport" of the page, | |
| // as reported by the page. |
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
| let a = String::from("Dude, Rust is sick."); | |
| { | |
| let b = &a; // ok | |
| let c = &a; // ok | |
| } | |
| { | |
| let b = &mut a; // mutable reference. ok. | |
| *b = String::from("Different!"); // change value. ok | |
| } |
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
| let a = String::from("Hello, world!"); // a is the owner | |
| let b = a; // ownership has changed to b. What is a? | |
| println!("{}", a); // error[E0382]: borrow of moved value: `a` |
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
| { // s is not valid here, it’s not yet declared | |
| let s = "hello"; // s is valid from this point forward | |
| // do stuff with s | |
| } // this scope is now over, and s is no longer valid |
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 a() { | |
| test123(); | |
| } |
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
| let a = 4; | |
| function doit() { | |
| exec(); | |
| } |
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
| // this doesn't create a new user but rather updates an existing one by the user name | |
| // a request looks like this: `https://nodeserver.com/username23?pass=12345` plus the associated JSON data sent in the body of the req | |
| app.put("/:user", (req, res) => { | |
| // get the user, compare the hashed + salted password sent in the query to the one in the database, if they match, then update the data | |
| collection.find({ user: req.params.user }).toArray((err, docs) => { | |
| if (err) { | |
| res.send("An error occured in getting the user info." ); | |
| } else { | |
| // there were matches (there are users with that username) | |
| if (docs.length > 0) { |
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
| // Example request: https://mynodejsurl.com/myusername?pass=mypassword123 | |
| // sends back the user information if the hashed query parameter for `pass` (password) is the right one for the user | |
| // sends back object with database information as well as a field called `correctPassword` which is either true or false | |
| app.get("/:user", (req, res) => { | |
| collection.find({ user: req.params.user }).toArray((err, docs) => { | |
| if (err) { | |
| res.send({ response: "An error occured in getting the user info." }); | |
| } else { | |
| if (docs.length > 0) { // if there were matches (there are users with that username) | |
| // get the first users password (each user should have a unique username) |
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
| // the password is sent in the body of the request as the `pass` field | |
| app.post("/:user", (req, res) => { | |
| // generate the salt using the npm package 'csprng'. | |
| // The first argument is the number of bits and the second is the radix (how many characters to choose from, basically) | |
| const salt = csprng(160, 36); | |
| // hash the password with the salt prepended | |
| req.body.pass = hash(`${salt}${req.body.pass}`); | |
| // inserts a new document on the server. make sure to store the hash and salt |