Skip to content

Instantly share code, notes, and snippets.

View chamatt's full-sized avatar

Matheus Vicente chamatt

View GitHub Profile
@chamatt
chamatt / FormularioEnviar.js
Created December 1, 2018 00:14
Enviar formulário
const formulario = document.querySelector("form");
formulario.addEventListener("submit", event => {
event.preventDefault(); //Previne a atualização da pagina após enviar o formulário
const dadosDoFormulario = {
title: formulario.children.title.value,
body: formulario.children.body.value,
image: formulario.children.image.value
}; // Pega os dados do formulário
EnviarPost(dadosDoFormulario); // Chama a função que vai realizar a requisição
@chamatt
chamatt / EnviarPost.js
Created December 1, 2018 00:24
Enviar Post
function EnviarPost(dadosDoFormulario) {
axios
.post("http://localhost:3000/posts", dadosDoFormulario)
.then(() => ObterPosts())
.catch(e => console.log(e));
}
@chamatt
chamatt / DeleteThis.js
Created December 1, 2018 00:36
DeleteThis
function DeletarPost(elemento) {
const post = elemento.parentNode.parentNode.parentNode;
const id = post.dataset.postId;
axios.delete(`http://localhost:3000/posts/${id}`).then(() => ObterPosts());
}
@chamatt
chamatt / uploadCloudinary.js
Created May 2, 2019 00:35
Cloudinary Avatar Upload
const express = require("express");
const router = express.Router();
const passport = require("passport");
// Multipart form data handler middleware
var multer = require("multer");
var upload = multer({ dest: "uploads/" });
const autoReap = require("multer-autoreap");
// Cloudinary
@chamatt
chamatt / parseSelect.js
Last active May 24, 2019 16:18
Parse value and label out of a select
JSON.stringify(Array.from(HTMLCollection).map((opcao) => ({ value: opcao.value, label: opcao.label})))
Books:
Burkov, Andriy - The hundred-page machine learning book-Andriy Burkov (2019)
Aurélien Géron - Hands-On Machine Learning with Scikit-Learn and TensorFlow Concepts, Tools, and Techniques to Build Intelligent Systems-O’Reilly Media (2017)
Courses MOOC:
Deep Learning Specialization
https://www.coursera.org/learn/neural-networks-deep-learning
Deep Learning MIT
@chamatt
chamatt / lista python 1.ipynb
Created March 16, 2020 21:08
Lista Python 1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chamatt
chamatt / closeOnClickOutside.jsx
Created July 15, 2020 23:01
Close on click outside in react (for custom dropdown components)
const CustomDropdown = () => {
const [isOpen, setIsOpen] = useState(false);
const handleBlur = e => {
const currentTarget = e.currentTarget;
setTimeout(() => {
if (!currentTarget.contains(document.activeElement)) {
setIsOpen(false);
}
}, 0);
const fibRange = n => [...Array(n).keys()].reduce((acc) => acc.concat(acc.at(-1) + acc.at(-2)), [0,1])
const fib = n => fibRange(n)[n]
@chamatt
chamatt / getToastTimeout.ts
Created July 27, 2022 16:42
Get optimized timeout for human reading speed using the text size
// minimum timeout
const BASE_HIDE_TIMEOUT = 3000 //ms
export const getFlashTimeout = (message: string) => {
const averageWordsPerSecond = 4 // average number of words per second a human can read
const amountOfWords = message.split(" ").length
const idealTimeout = (amountOfWords / averageWordsPerSecond) * 1000
// factor in reading pauses for longer sentences
const factor = Math.floor(amountOfWords / 10)