Skip to content

Instantly share code, notes, and snippets.

View satinP's full-sized avatar
🤙

Pedro Satin satinP

🤙
View GitHub Profile
@satinP
satinP / randomPixKey.ts
Last active March 11, 2024 21:28
Máscara e Validador de Chave Pix Aleatória
function maskPixRandomKey(value: string): string {
/**
* Filtra caracteres de 0 a 9 e de a a f, conforme os manuais:
* https://www.bcb.gov.br/content/estabilidadefinanceira/pix/Regulamento_Pix/X_ManualOperacionaldoDICT.pdf - Página 14`
* https://www.bcb.gov.br/content/estabilidadefinanceira/pix/API-DICT-2.0.1.html#tag/Key
*/
const cleanValue = value.replace(/[^0-9a-f]/g, '').substring(0, 32)
if (cleanValue.length < 9) {
return cleanValue
@satinP
satinP / .gitconfig
Last active April 14, 2024 02:48
Git config values with aliases and pretty logs
# This is my daily use gitconfig, you should check if it fits your needs too
# Copy and paste into ~/.gitconfig
# Run `git alias` on terminal to show aliases and its command
# https://git-scm.com/docs/pretty-formats
[user]
name = X X
email = x@x.com
@satinP
satinP / Button.tsx
Last active January 7, 2024 20:13
Polymorphic TypeScript React component with `as` prop
import React from "react";
type ButtonProps<T extends React.ElementType> = {
as?: T
} & React.ComponentProps<T>
export const Button = <T extends React.ElementType = "button">(
{ as: Element = 'button', props }: ButtonProps<T>
) => <Element {...props} />
@satinP
satinP / pm.sh
Last active January 6, 2024 20:19
Shell function that runs nodejs package manager based on lockfile (npm, yarn, pnpm, bun)
function pm() {
if [ -f package-lock.json ]; then
echo "Running with $(tput bold)npm"
command npm "$@"
elif [ -f yarn.lock ]; then
echo "Running with $(tput bold)yarn"
command yarn "$@"
elif [ -f pnpm-lock.yaml ]; then
echo "Running with $(tput bold)pnpm"
command pnpm "$@"