This file contains 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 http = require('http') | |
const port = 3000 | |
const server = http.createServer((req, res) => { | |
res.statusCode = 200 | |
res.setHeader('Contenty-Type', 'text/html')/ | |
res.end('Hi, one messagem from Node with HTML') | |
}) |
This file contains 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 db = require('./database'); | |
beforeAll(async () => { | |
await db.sequelize.sync({ force: true }); | |
}); | |
test('create person', async () => { | |
expect.assertions(1); | |
const person = await db.Person.create({ | |
id: 1, |
This file contains 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
//Referential transparency in computer science | |
// Function is pure if the return value is got just trough its own entry values, without side effects. | |
// Above is a impure function because depends on PI value (something extern) | |
const PI = 3.14 | |
function calculator_area(radius){ | |
return radius * radius * PI | |
} |
This file contains 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
//returning many functions result | |
function sum(a){ | |
return function(b){ | |
return function(c){ | |
return a + b + c | |
} | |
} | |
} |
This file contains 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
//Memoization is an optimization technique used primarily to speed up computer programs by storing the results | |
//of expensive function calls and returning the cached result when the same inputs occur again | |
//That's can be applied for calculating Fibonacci and Factorial | |
const memoizedSum = () => { | |
let cache = {}; | |
return (n) => { | |
if (n in cache) { |
This file contains 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
//True returns the first parameter | |
const True = a => b => a | |
//False returns the second parameter | |
const False = a => b => b | |
//messages to show represeting each state | |
const isTrue = () => "it's true!" | |
const isFalse = () => "it's false!" |
This file contains 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
//True returns the first parameter | |
const True = a => b => a | |
//False returns the second parameter | |
const False = a => b => b | |
//messages to show represeting each state | |
const isTrue = () => "it's true!" | |
const isFalse = () => "it's false!" |
This file contains 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
//Make all the queries in parallel (asynchronously). Resulting in each query firing at the same time. | |
let promise1 = new Promise((resolve) => resolve(executeQuery(...)) | |
let promise2 = new Promise((resolve) => resolve(executeQuery(...)) | |
let promise3 = new Promise((resolve) => resolve(executeQuery(...)) | |
let responses = await Promise.all([promise1, promise2, promise3, ...]) | |
for(let response of responses) { | |
// some processing | |
} |
This file contains 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
//IIFE (Immediately Invoked Function Expression) é uma função em JavaScript que é executada assim que definida. | |
/* É um Design Pattern também conhecido como Self-Executing Anonymous Function e contém duas partes principais. | |
A primeira é a função anônima cujo escopo léxico é encapsulado entre parênteses. Isso previne o acesso externo | |
às variáveis declaradas na IIFE, bem como evita que estas variáveis locais poluam o escopo global. | |
*/ | |
//A segunda parte corresponde à criação da expressão (), por meio da qual o interpretador JavaScript avaliará e | |
//executará a função. |
This file contains 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 express = require('express'); | |
const app = express(); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: true })); | |
const multer = require('multer'); | |
const upload = multer({ dest: 'uploads/' }); | |
// Configuramos o upload como um middleware que |
OlderNewer