Skip to content

Instantly share code, notes, and snippets.

View franciscojsc's full-sized avatar
👨‍💻
🚀 🚀coding 🚀 🚀

Francisco Chaves franciscojsc

👨‍💻
🚀 🚀coding 🚀 🚀
View GitHub Profile
@franciscojsc
franciscojsc / convertToHex.js
Last active September 29, 2021 22:22
Convert to hex
const convertToHex = (color) => {
const colors = {
red: '#A31419',
green: '#10A337',
blue: '#4C91F0',
yellow: '#F0EA6F',
purple: '#8132A3',
};
return colors[color] || 'Not found color' ;
};
@franciscojsc
franciscojsc / exemplo-regex.js
Created August 8, 2021 21:17
Exemplo de uso de Regex
// Fonte - https://www.youtube.com/watch?v=sCk8DHeGQfo
// expressões regulares
// 5 padrões que você
// precisa conhecer
// padrao 1 : | or
const reg1 = new RegExp("franciscochaves.com.br|franciscojsc.github.io");
const str1 = "franciscochaves.com.br";
const match1 = str1.match(reg1);
@franciscojsc
franciscojsc / checkTime.js
Created July 26, 2021 03:09
Realiza o cálculo de diferença entre duas datas em JavaScript
var startTime = "07/26/2021 02:48:56"
var endTime = "07/27/2021 02:48:56"
function run(start, end) {
return Math.abs(new Date(start).getTime() - new Date(end).getTime())
}
var milliseconds = run(startTime, endTime)
var second = run(startTime, endTime) / 1000
var minute = run(startTime, endTime) / (1000 * 60)
@franciscojsc
franciscojsc / checkUser.js
Created July 26, 2021 02:26
Verifique se existe a ocorrência de um usuário pelo nome.
function run(name, users) {
if (typeof users == "string") users = JSON.parse(users);
return !!verifyUser(name, users);
}
function verifyUser(name, users) {
return Object.values(users).filter(function(user) {
return user.name == name;
})[0];
}
@franciscojsc
franciscojsc / checkText.js
Last active July 11, 2021 13:14
Verifique a ocorrência do texto usando Regex
/**
* @description Identificar a ocorrência do texto por meio de Regex
*
* @param {String} text Texto informado pelo usuário
* @param {Object} options Objeto com os pares de chave e valor
*
* @return {String} Retorna a opção selecionada pelo usuário ou o valor padrão
**/
function run(text, options) {
if (typeof options == "string") options = JSON.parse(options);
@franciscojsc
franciscojsc / mirror-site.sh
Created July 4, 2021 23:32
Clone site with software wget
#!/usr/bin/env bash
# Author: Francisco Chaves <https://franciscochaves.com.br>
# Description: Clone site with software wget.
URL=$1
if [ -z $(which wget) ]; then
echo -e "Please install wget\nsudo apt install wget"
fi
@franciscojsc
franciscojsc / index.html
Created July 4, 2021 04:09
WebCam Web 📷
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>WebCam Web</title>
</head>
<body>
<video id="video" autoplay muted></video>
@franciscojsc
franciscojsc / github-user-data.js
Created June 27, 2021 16:21
Github user data using JavaScript fetch API
const URL = 'https://api.github.com/users/franciscojsc'
fetch(URL)
.then((data) => data.json())
.then((result) => console.log(result))
@franciscojsc
franciscojsc / cash-machine.js
Created June 25, 2021 01:37
Número de notas disponíveis no caixa eletrônico em JavaScript
let valor = 1686;
const nota100 = parseInt(valor / 100);
valor %= 100;
const nota50 = parseInt(valor / 50);
valor %= 50;
const nota20 = parseInt(valor / 20);
valor %= 20;
@franciscojsc
franciscojsc / average-consumption.js
Created June 25, 2021 01:35
Consumo médio do automóvel em JavaScript
const distanciaTotal = 650;
const combustivelGasto = 40.0;
const resultado = parseFloat(distanciaTotal / combustivelGasto).toFixed(3);
console.log(`Consumo médio: ${resultado} km/l`);