Skip to content

Instantly share code, notes, and snippets.

View chamatt's full-sized avatar

Matheus Vicente chamatt

View GitHub Profile
@chamatt
chamatt / RefetchManager.tsx
Last active September 12, 2023 23:31
Apollo Refetch Manager - Control apollo client refetch behavior from the parent component
import { PropsWithChildren, createContext, useContext, useMemo } from "react"
import { DocumentNode } from "@apollo/client"
import { getOperationName } from "@apollo/client/utilities"
import { groupBy } from "lodash-es"
type MutationQueryPair = {
mutation: DocumentNode
queries: DocumentNode[]
}
@chamatt
chamatt / .bashrc
Created December 29, 2022 06:07
Ammend Old Commits with file changes
git-amend-old() (
# Stash, apply to past commit, and rebase the current branch on to
of the result.
# For Gerrit.
https://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit/53$
current_branch="$(git rev-parse --abbrev-ref HEAD)"
apply_to="$1"
git stash
git checkout "$apply_to"
git stash apply
@chamatt
chamatt / WithNavigation.tsx
Last active November 6, 2022 23:03
Expo-router utility to set options
export type RouteTypes = {
home: undefined
postDetail: { id: string }
postList: undefined
login: undefined
signUp: undefined
}
type ScreenOptionsProps = {
@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)
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 / 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);
@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.
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 / 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})))
@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