Skip to content

Instantly share code, notes, and snippets.

View max10rogerio's full-sized avatar
🎯
Focusing

Max Rogério max10rogerio

🎯
Focusing
  • Maringá, Paraná - Brasil
View GitHub Profile
@max10rogerio
max10rogerio / slugify.ts
Last active September 29, 2024 22:27
Typescript slug function
// MIT License
// Copyright (c) 2023 Max Rogério
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@max10rogerio
max10rogerio / yup.locale.pt-br.js
Last active May 10, 2024 17:02
Translation of the main messages from the Yup library into the Pt-Br language.
/* eslint-disable */
// For more infos, see: https://github.com/jquense/yup/blob/master/src/locale.js
import { setLocale } from 'yup'
const translation = {
mixed: {
default: '${path} é inválido',
required: '${path} é um campo obrigatório',
oneOf: '${path} deve ser um dos seguintes valores: ${values}',
notOneOf: '${path} não pode ser um dos seguintes valores: ${values}',
@max10rogerio
max10rogerio / clipboard.ts
Last active November 22, 2023 00:13
Example Copy to Clipboard with Typescript
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard
/**
* Interface CopyToClipboard params
*/
interface ICopyToClipboard {
/** HTML reference identifier ```<div id="foo"></div>``` */
target?: string;
/** String value */
value?: string;
@max10rogerio
max10rogerio / example.ts
Last active November 24, 2021 17:35
Typescript spy mock pattern example
/**
* global describe
*/
namespace Command {
export type NotAsync = String
}
/**
* Generic interface basead in design pattern: https://refactoring.guru/design-patterns/command
@max10rogerio
max10rogerio / command.sh
Created September 6, 2021 17:59
POSTGRES - DOCKER - Restore database
❯ cat database.dump | docker exec -i server_postgres_1 psql -U postgres -W postgres -p 5432 -h 127.0.0.1 -d database
@max10rogerio
max10rogerio / useQuery.ts
Created August 31, 2021 01:52
useQuery Hook - React with react-router-dom - TS
import { useLocation } from "react-router-dom";
/**
* Get URL query params as object
*
* Example:
*
* ```tsx
* type Query = {
* q: string
@max10rogerio
max10rogerio / postgres-sql-with-json-parameters.ts
Last active June 14, 2021 20:14
Replace object param keys for number ref to use with postgres driver
// Example
// https://www.typescriptlang.org/play?#code/MYewdgziA2CmB0w4EMBOAKAlAKG6SALgATCqzIGwBKsAZrGWMLEQLxHpm0BcRYArgFsARg0y8IBVAEswAczYA+IgAMAOgBINAby4BfFXnCSSZCrAAKaZINiVUAaVgBPNhwDWLiVNlzxRSRl5JVVuHU9nA1x8EwIQAGUARQAZNwAeABUiWAAPSjAAEwgiEGEAK1hgYnZkMGdFdAgAR2hvILkAGiIAB2tbewheDP8AbUDfLtrnEYBdGZDtbCJlojhiLgBJQty3AEYllbW+WAB3eJa3ZugD5ZjiWDAfWGL2AHlyyoJ4B6eIdF7UDY7AwIDgViRjMQ0KgrIDBC8iLNcODaCAMHdEREugA3ZDQfiweYgWjZR4yZ6YIiLcHgjEAoH2NykciUWEMhhOZzoCJgmm3SFEMhyHbsMCnIg0OQAURy3X+fWBqC6AHI5MreXyMVwGA9mEyzJQaPRGMxOHQtgVcjgbjSxWcLqLTudoPAyN1oMhTULcl1tSbYNa+ctoWz4fBuvwIAALdC4-EBm3gzbbHIAalTNr0yJWZAI-FQYERdudk1QML6EBm2Cz2Fk9lonpYoeK1JWYCBbV8NrRltQvGVAEF4gBhZVEAA+RGVABEpSPlTboNJBNICLwBCIGNXcAB6HdECJ8IFEWREWjSVAmbogCCr6TgIyEHoV3a8ZtuVvLdu2fuCZA5ZUOm7VBe37IdRyA8ElxXNciF2AAGICaz3A8XCPWwT0LD0rxvO8HzpCsACY3wrD9gNAqdwMAxdl1XXgEMgtsOynP8AKQ6IBSuNxDHBCBYDgKoiETFYACpGL5bhoNXIghxPfIIAAfW6BglOQYUbVoVAQEEISgyIAhkGEOBdJWE4ox1Ey+TAbSWHYbhv1gciGCIYRXAcohuB7LcoNo4hJN87BDEfEwyAgfhoAIXY3DiJJkjSZsGiuLp6XhXYcC1Z5woIQjooSFJ4orRKWmSojr
@max10rogerio
max10rogerio / basic-clean-example.ts
Created March 24, 2021 13:00
Exemplo mostrando em como padronizar a resposta de uma api para camelCase e separar as resposabilidades
interface Api {
post: <R = any, P = any>(params: P) => Promise<R>
}
/*
A api espera user_login, user_password
E response user_name, user_age, user_status
*/
type ApiResponse = {
user_name: string
@max10rogerio
max10rogerio / template-literal-type.ts
Created October 23, 2020 13:38
Snake case to CammelCase
interface Example {
first_name: string,
last_name: string,
home_town: string,
}
type CamelizeString<T extends PropertyKey> = T extends string ? string extends T ? string :
T extends `${infer F}_${infer R}` ? `${F}${Capitalize<CamelizeString<R>>}` : T : T;
type Camelize<T> = { [K in keyof T as CamelizeString<K>]: T[K] }
@max10rogerio
max10rogerio / columns-to-annotations.sql
Created January 21, 2021 14:06
Simple map column to annotations typeorm
SELECT
E'@Column({ name: \'' || column_name || E'\', type: \'' || data_type || E'\'})'
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'yourtable'
AND TABLE_SCHEMA = 'your schema if necessary';