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'); | |
(async () => { | |
const domainToSearch = process.argv[2]; | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto('https://registro.br'); | |
await page.type('#is-avail-field', domainToSearch); | |
await page.click('button'); | |
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 CronJob = require('../lib/cron.js').CronJob; | |
//aqui é outra maneira que a lib aceita a inicialização do cron, mas é parecido, olha só | |
let date = new Date(); | |
date.setSeconds(date.getSeconds()+2); | |
const job = new CronJob(date, function() { | |
console.log('PLAU', new Date()); | |
}); | |
console.log('Vai disparar daqui 2s'); | |
job.start(); |
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
//Ex rápido | |
const cronJob = require('cron').job; | |
cronJob('* * * * * *', () => { | |
console.log('oi'); | |
}, null, true); |
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 sons = ["auau", "miau", "cócóricó"]; | |
const sonsHtml = sons.reduce((acc, som) => { | |
return (acc += `<li>${som}</li>`); | |
}, ""); | |
//Ou se você quiser economizar linhas. | |
const sonsHtml = sons.reduce((acc, som) => acc += `<li>${som}</li>`, ""); | |
//Retorno: | |
//"<li>auau</li> |
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
//funcao que retorna um array | |
const criaArray = ({ um, dois }) => [ um, dois ]; | |
//declarando um objeto | |
const objetaum = { um: 1, dois: 2, tres: 3 } | |
//desestruturando | |
let [ one, two ] = criaArray(objetaum); | |
console.log(one, two); // 1, 2 | |
//funcao que retorna um objeto | |
const criaObjeto = ([ um, dois ]) => { |
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 lista = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; | |
let [ um, dois, tres, ...resto ] = lista; | |
console.log(um); // 1 | |
console.log(dois); // 2 | |
console.log(resto); // [ 4, 5, 6, 7, 8, 9, 10 ] | |
let objetaum = { | |
one: 1, | |
two: 2, | |
three: 3, |
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 cumprimento = { | |
oi: 'eae meu consagrado', | |
tchau: 'te vejo mais tarde vazo', | |
nao: "não interessa pra voce" | |
} | |
let { oi, tchau, aa } = cumprimento; | |
console.log(oi); //'eae meu consagrado', | |
console.log(tchau); //'te vejo mais tarde vazo', | |
console.log(aa); //undefined |
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
dogsAgeSum = animais.reduce((total, elemento) => { | |
if (elemento.tipo === 'cao') return total += (elemento.idade *=7); | |
else return total}, 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
dogsAgeSum = animais.filter((animal) => animal.tipo === 'cao') | |
.map((cao) => cao.idade *= 7) | |
.reduce((total, cao) => total += cao) |
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
animais = [ | |
{ | |
nome: 'Fumaça', | |
idade: 3, | |
tipo: 'cao' | |
}, | |
{ | |
nome: 'Tobby', | |
idade: 6, | |
tipo: 'cao' |
NewerOlder