Skip to content

Instantly share code, notes, and snippets.

View Luisgustavom1's full-sized avatar

Luis Gustavo Macedo Luisgustavom1

View GitHub Profile
@Luisgustavom1
Luisgustavom1 / example.ts
Last active October 12, 2023 22:34
The purpose this code is to study about more complex type system of typescript. Its a query builder type system
interface User {
id: number;
name: string;
email: string;
password: string;
updated_at: Date;
}
interface Product {
id: number;
@Luisgustavom1
Luisgustavom1 / VScode extensions
Created May 22, 2023 22:57
My vscode extensions
bradlc.vscode-tailwindcss
clinyong.vscode-css-modules
dbaeumer.vscode-eslint
eamodio.gitlens
EditorConfig.EditorConfig
esbenp.prettier-vscode
glenn2223.live-sass
golang.go
jock.svg
Luisao.one-more-coffee
@Luisgustavom1
Luisgustavom1 / settings.json
Last active December 3, 2023 18:23
My VSCode settings
{
"explorer.confirmDragAndDrop": true,
"diffEditor.wordWrap": "on",
"editor.fontSize": 18,
"editor.insertSpaces": true,
"editor.detectIndentation": true,
"launch": {
"configurations": []
},
"editor.codeActionsOnSave": {
@Luisgustavom1
Luisgustavom1 / css-reset.css
Last active May 7, 2023 20:41
A simple reset css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
@Luisgustavom1
Luisgustavom1 / new Proxy().js
Last active November 12, 2022 20:18
An example of new Proxy use
const user = {
name: 'luis'
}
const messages = {
hello: (userName) => `Ola ${userName}, seja bem vindo ao nosso sistema`,
goodBye: (userName) => `Até mais ${userName}, esperamos que volte sempre aqui`,
}
const messagesHandler = {
get(target, prop, receiver) {
return target[prop](user.name)
@Luisgustavom1
Luisgustavom1 / useLocalStorage.ts
Created September 8, 2022 01:26
Hook to use states based in local storage
import React from 'react'
export const useLocalStorage = <T extends string | object>(
item: string,
initialValue = '',
): [string, React.Dispatch<(value: T) => T>] => {
const [localStorageItem, setLocalStorageItem] = React.useState(() => {
const itemStoraged = localStorage.getItem(item)
if (itemStoraged) {
@Luisgustavom1
Luisgustavom1 / ComposeProviders.tsx
Last active December 27, 2022 19:10
Compose React Providers to avoid too much chaining
import React from 'react'
interface IComposeProvidersProps {
with: Array<React.ElementType>
children: React.ReactNode
}
export const ComposeProviders = ({
with: Providers,
children,
type Diff<
Obj1,
Obj2,
SameKeys extends keyof Obj1 = keyof Obj1 & keyof Obj2
> = Omit<{
[K in (keyof Obj1 | keyof Obj2)]:
K extends keyof Obj1
? Obj1[K]
: K extends keyof Obj2
? Obj2[K]
@Luisgustavom1
Luisgustavom1 / Reverse.ts
Last active August 25, 2022 12:55
This is a reverse string using type level of typescript
type Reverse<A extends string> =
`${A}` extends `${infer H}${infer T}`
? `${Reverse<T>}${H}`
: A
@Luisgustavom1
Luisgustavom1 / kebabcase.ts
Created July 31, 2022 23:04
Type-challenges - 612 Medium kebabcase
// 00612 - Medium kebabcase
type KebabCase<T extends string> =
T extends `${infer F}${infer R}`
? R extends Uncapitalize<R>
? `${Uncapitalize<F>}${KebabCase<R>}`
: `${Uncapitalize<F>}-${KebabCase<R>}`
: T
export type KebabCaseResult = KebabCase<'FooBarBaz'> //foo-bar-baz