Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Max Rogério max10rogerio

🎯
Focusing
  • Maringá, Paraná - Brasil
View GitHub Profile
@max10rogerio
max10rogerio / yup.locale.pt-br.js
Last active Apr 3, 2022
Translation of the main messages from the Yup library into the Pt-Br language.
View yup.locale.pt-br.js
/* 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 / slugify.ts
Last active Dec 17, 2021
Typescript slug function
View slugify.ts
// ref: https://gist.github.com/codeguy/6684588#gistcomment-3426313
export const slugify = (...args: (string | number)[]): string => {
const value = args.join(' ')
return value
.normalize('NFD') // split an accented letter in the base letter and the acent
.replace(/[\u0300-\u036f]/g, '') // remove all previously split accents
.toLowerCase()
.trim()
@max10rogerio
max10rogerio / example.ts
Last active Nov 24, 2021
Typescript spy mock pattern example
View example.ts
/**
* 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 Sep 6, 2021
POSTGRES - DOCKER - Restore database
View command.sh
❯ 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 Aug 31, 2021
useQuery Hook - React with react-router-dom - TS
View useQuery.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 Jun 14, 2021
Replace object param keys for number ref to use with postgres driver
View postgres-sql-with-json-parameters.ts
// Example
// https://www.typescriptlang.org/play?#code/MYewdgziA2CmB0w4EMBOAKAlAKG6SALgATCqzIGwBKsAZrGWMLEQLxHpm0BcRYArgFsARg0y8IBVAEswAczYA+IgAMAOgBINAby4BfFXnCSSZCrAAKaZINiVUAaVgBPNhwDWLiVNlzxRSRl5JVVuHU9nA1x8EwIQAGUARQAZNwAeABUiWAAPSjAAEwgiEGEAK1hgYnZkMGdFdAgAR2hvILkAGiIAB2tbewheDP8AbUDfLtrnEYBdGZDtbCJlojhiLgBJQty3AEYllbW+WAB3eJa3ZugD5ZjiWDAfWGL2AHlyyoJ4B6eIdF7UDY7AwIDgViRjMQ0KgrIDBC8iLNcODaCAMHdEREugA3ZDQfiweYgWjZR4yZ6YIiLcHgjEAoH2NykciUWEMhhOZzoCJgmm3SFEMhyHbsMCnIg0OQAURy3X+fWBqC6AHI5MreXyMVwGA9mEyzJQaPRGMxOHQtgVcjgbjSxWcLqLTudoPAyN1oMhTULcl1tSbYNa+ctoWz4fBuvwIAALdC4-EBm3gzbbHIAalTNr0yJWZAI-FQYERdudk1QML6EBm2Cz2Fk9lonpYoeK1JWYCBbV8NrRltQvGVAEF4gBhZVEAA+RGVABEpSPlTboNJBNICLwBCIGNXcAB6HdECJ8IFEWREWjSVAmbogCCr6TgIyEHoV3a8ZtuVvLdu2fuCZA5ZUOm7VBe37IdRyA8ElxXNciF2AAGICaz3A8XCPWwT0LD0rxvO8HzpCsACY3wrD9gNAqdwMAxdl1XXgEMgtsOynP8AKQ6IBSuNxDHBCBYDgKoiETFYACpGL5bhoNXIghxPfIIAAfW6BglOQYUbVoVAQEEISgyIAhkGEOBdJWE4ox1Ey+TAbSWHYbhv1gciGCIYRXAcohuB7LcoNo4hJN87BDEfEwyAgfhoAIXY3DiJJkjSZsGiuLp6XhXYcC1Z5woIQjooSFJ4orRKWmSojr
@max10rogerio
max10rogerio / basic-clean-example.ts
Created Mar 24, 2021
Exemplo mostrando em como padronizar a resposta de uma api para camelCase e separar as resposabilidades
View basic-clean-example.ts
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
View template-literal-type.ts
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 Jan 21, 2021
Simple map column to annotations typeorm
View columns-to-annotations.sql
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';
@max10rogerio
max10rogerio / clipboard.ts
Last active Jul 13, 2020
Example Copy to Clipboard with Typescript
View clipboard.ts
// 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;