Skip to content

Instantly share code, notes, and snippets.

View cloud-henrique's full-sized avatar
💻
Working...

Cláudio Henrique cloud-henrique

💻
Working...
View GitHub Profile
@cloud-henrique
cloud-henrique / innerHTML.js
Created September 6, 2020 21:59
Alternative to innerHTML
let product = 'Hello, friend.';
let nameEl = document.createElement('p');
// that way
let nameText = document.createTextNode(product.name);
nameEl.appendChild(nameText);
// is safer than
nameEl.innerHTML = product.name;
@cloud-henrique
cloud-henrique / 00_introduction.md
Last active August 30, 2020 07:21
Creating routes using express

Creating routes using express

After install NodeJS (sudo apt install nodejs or download direct from website) Verify if NodeJS was correctly installed by typing node -v on terminal, it must return any version number.

So, if you doesn't create a project folder, it's time. Then, on your folder, type npm init -y to set up a npm package. It must create a package.json file.

After that, install express package by typing npm i express on terminal. It will create a package-lock.json file, don't worry about it (and never change it manually).

To create a simple route, just to verify if everything is ok, let's create a .js file (e.g. server.js) on project folder.

@cloud-henrique
cloud-henrique / asyncAwait.js
Created August 29, 2020 06:29
Async/Await vs Then/Catch
// regular promise
const p = () =>
new Promise((resolve, reject) => {
setTimeout(() => {
resolve('ok');
}, 2000);
});
// using async/await
async function runP() {
@cloud-henrique
cloud-henrique / objectShortSynyax.js
Created August 29, 2020 04:55
Object Short Syntax: avoid code repetition
let name = 'Darlene';
let age = 30;
let user = {
name, // name : name
age, // age : age
dog: 'Flipper',
};
console.log(user);
@cloud-henrique
cloud-henrique / spreadOperator-01.js
Created August 29, 2020 04:42
Spread syntax (...): allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];
let arr3 = [...arr1, ...arr2];
console.log(arr3);
@cloud-henrique
cloud-henrique / rest-ex01.js
Created August 29, 2020 04:36
Rest: group the rest of values on an array or object (depending on param type)
let user = {
name: 'Cláudio Henrique',
age: 20,
job: 'full stack dev',
};
let { name, ...rest } = user;
console.log(name);
console.log(rest);
@cloud-henrique
cloud-henrique / arrayOperations.js
Last active August 29, 2020 02:08
Array operations - map, reduce, filter, find
// Array operations
let arr = [1, 5, 3, 6, 8, 6, 4];
/**
* The map() method creates a new array with the results of calling a function
* for each array element.
* In this case in particular, returns the array item (wich is a number) +
* the array index
*/
@cloud-henrique
cloud-henrique / importHeaderFooter.html
Last active August 29, 2020 04:10
First, you need to create 2 files: header (header.html) and footer (footer.html) templates. So, put the following code to apply header and footer on your wanted pages.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<header id="main-header"></header>
<div id="container"></div>
@cloud-henrique
cloud-henrique / includesAndRepeat
Created August 28, 2020 02:48
Includes(param) returns true if 'param' is on array. Otherwise, repeat(param) repeats the conten 'param' times.
// includes
let grocery = ['egg', 'coffee', 'rice', 'beans', 'pasta'];
grocery.includes('meat'); // returns false
// repeat
console.log('x'.repeat(9));