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
| <input id="inputText" value="Text to copy"> | |
| <button id="copyInputText">Copy</button> | |
| <span id="elementText">More Text to copy</span> | |
| <button id="copyElementText">Copy</button> | |
| <script> | |
| const execCopy = () => { | |
| inputText.select(); | |
| document.execCommand('copy') |
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
| // Simple Node.js Echo Server that listens for data and sends a response with the data back to the client | |
| // Note: Responds to any verb eg. GET/POST etc. | |
| const createServer = require('http').createServer; | |
| const server = createServer((req, res) => { | |
| let body = ''; | |
| req.on('data', data => body += data) | |
| req.on('end', () => { |
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
| // [{_id:"someid", name:"someUserName", age:21, countPosts: 15}]; | |
| db.findOne({ _id }) | |
| .then(results => ({ id: results._id, username: results.name })) | |
| .then(results => res.json(results)); |
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 searchParams = new URLSearchParams(window.location.search); | |
| const decodedParams = Array | |
| .from(searchParams.keys()) | |
| .reduce((acc, key) => ({ ...acc, [key]: searchParams.get(key) }), {}); |
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
| fetch('https://api.ipify.org/?format=json') | |
| .then(results => results.json()) | |
| .then(console.log) // e.g. { ip: "113.114.194.164" } | |
| .catch(console.error); |
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"> | |
| <title>Submit a form with JavaScript</title> | |
| <style> | |
| html, body { | |
| height: 100%; |
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
| // app.js | |
| const MongoClient = require('mongodb').MongoClient; | |
| const passport = require('passport'); | |
| const LocalStrategy = require('passport-local').Strategy; | |
| const ObjectID = require('mongodb').ObjectID; | |
| MongoClient.connect('mongodb://localhost:27017/test', (err, client) => { | |
| if (err) throw err; | |
| const db = client.db('test'); | |
| const users = db.collection('users'); |
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
| router.get('/', (req, res, next) => { | |
| const users = req.app.locals.users; | |
| users | |
| .find({}) | |
| .toArray() | |
| .then(data => res.json(data)); | |
| }); | |
| router.post('/', (req,res, next) => { | |
| const users = req.app.locals.users; |
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 axios = require('axios'); | |
| const chalk = require('chalk'); | |
| const commander = require('commander'); | |
| commander | |
| .version('1.0.0') | |
| .option('-t --type <type>', 'Lookup type') | |
| .option('-n --number <number>', 'Number of results') | |
| .parse(process.argv); |