Skip to content

Instantly share code, notes, and snippets.

View brunofilho1's full-sized avatar
💻
Focusing

Bruno Filho brunofilho1

💻
Focusing
View GitHub Profile
@brunofilho1
brunofilho1 / spicetify-win-installer.bat
Created December 6, 2024 12:50
Quick Spicetify installer for Windows using Powershell
@echo off
powershell -NoProfile -ExecutionPolicy Bypass -Command "iwr -useb https://raw.githubusercontent.com/spicetify/cli/main/install.ps1 | iex"
powershell -ExecutionPolicy Bypass -Command "iwr -useb https://raw.githubusercontent.com/spicetify/marketplace/main/resources/install.ps1 | iex"
pause
@brunofilho1
brunofilho1 / useDebounceValue.ts
Created January 26, 2024 11:57
A hook to make debounce effect on case of request with search filter
import { useEffect, useState } from 'react'
export function useDebounceValue<T = unknown>(value: T, delay: number) {
const [debouncedValue, setDebouncedValue] = useState(value)
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(value)
}, delay)
@brunofilho1
brunofilho1 / react.code-snippets
Last active June 11, 2024 17:34
My simple snippets file for React apps
{
"Generate React Page": {
"prefix": "genreactpage",
"body": [
"export default function ${1:PageName}() {",
" return (",
" <div>",
" <h1>${1:PageName}</h1>",
" </div>",
" );",
@brunofilho1
brunofilho1 / settings.json
Created January 23, 2024 17:14
My Visual Studio Code settings.json file with themes, icons and general settings
{
// EDITOR
"editor.fontSize": 14,
"editor.fontFamily": "JetBrains Mono", // CaskaydiaCove Nerd Font
"editor.fontLigatures": true,
"editor.fastScrollSensitivity": 5,
"editor.padding.bottom": 30,
"editor.wordWrap": "on",
"editor.linkedEditing": true,
"editor.lineHeight": 20,
@brunofilho1
brunofilho1 / regexMaskCpf.js
Created February 11, 2023 21:39
An RegEx for CPF number.
const cpf = "12345678900";
function maskCpf(cpf) {
maskedCpf = cpf
.replace(/\D/g, '')
.replace(/(\d{3})(\d{3})(\d{3})(\d)/, '$1.$2.$3-$4')
return maskedCpf;
}
@brunofilho1
brunofilho1 / regexMaskPhone.js
Created February 11, 2023 21:11
An RegEx for number phones.
const phoneNumber = "99988663355";
function maskPhone(phone) {
if (phone.length == 10) {
const stringValue = phone.toString();
const maskedPhone = stringValue
.replace(/\D/g, '')
.replace(/(\d{2})(\d)/, '($1) $2')
.replace(/(\d{4})(\d{4})/, '$1-$2');
@brunofilho1
brunofilho1 / browserSpeaker.js
Created January 4, 2023 18:38
Make browser speak with robot voice - speechSynthesis
const message = new SpeechSynthesisUtterance();
mensagem.text = 'Good night, Bruno!';
window.speechSynthesis.speak(message);
@brunofilho1
brunofilho1 / ReactModal.tsx
Created November 6, 2022 11:28
Pure React modal with Context Api
import React from "react";
import { useModal } from "../../contexts/modalContext";
type ModalProps = {
children: React.ReactNode;
modalButton: React.ReactElement;
};
export function ReactModal({ children, modalButton }: ModalProps) {
const { isOpen, setIsOpen } = useModal();
@brunofilho1
brunofilho1 / updateAnObjectInAnArray.jsx
Created October 6, 2022 19:13
Update an object in an array in React
const [data, setData] = useState([
{id: 1, country: 'Austria'},
{id: 2, country: 'Belgium'},
{id: 3, country: 'Canada'},
]);
const updateState = () => {
setData(prevState => {
const newState = prevState.map(obj => {
if (obj.id === 2) {
@brunofilho1
brunofilho1 / ContextMenu.tsx
Last active June 30, 2022 18:38
Creating an Context Menu with React and Styled-Components
import { useEffect, useState, ReactNode } from 'react'
import { ContextMenuTooltipStyle } from './styles'
type ContextMenuProps = {
children: ReactNode
}
export function ContextMenu({ children }: ContextMenuProps) {
const [show, setShow] = useState(false)
const [points, setPoints] = useState({ x: 0, y: 0 })