Skip to content

Instantly share code, notes, and snippets.

View LeandrodeLimaC's full-sized avatar
🎯
Focusing

Leandro de Lima LeandrodeLimaC

🎯
Focusing
View GitHub Profile
/*
TODO: Simplify this type by creating a PolymorphicComponentWithoutRef
first and then a PolymorphicComponentWithRef using React.ElementRef<'div'>
*/
/**
* Props for a polymorphic React component that includes a ref.
*
* @template E - The expected React element type.
* @template P - Additional props specific to the component.
@LeandrodeLimaC
LeandrodeLimaC / DistributiveOmit.ts
Created March 21, 2024 16:42
A utility type that omits specified keys from an object type in a distributive manner. It uses conditional types to distribute the operation over each property in `T`.
/**
* A utility type that omits specified keys from an object type in a distributive manner.
* It uses conditional types to distribute the operation over each property in `T`.
*
* @template T - The input object type.
* @template TOmitted - The keys to be omitted from the input type.
*/
export type DistributiveOmit<T, TOmitted extends PropertyKey> = T extends any
? Omit<T, TOmitted>
: never
@LeandrodeLimaC
LeandrodeLimaC / FixForwardRef.ts
Created March 21, 2024 16:40
This updated version of ForwardRef was created to be used with generics typescript can't infer correctly the type of the reference in this scenario. The downside is that using this function, we will lose the dsiplayName property and some other stuff like defaultProperties. ref: https://fettblog.eu/typescript-react-generic-forward-refs/#option-3%…
/**
* This updated version of ForwardRef was created to be used with generics
* typescript can't infer correctly the type of the reference in this scenario.
*
* The downside is that using this function, we will lose the dsiplayName property
* and some other stuff like defaultProperties.
*
* ref: https://fettblog.eu/typescript-react-generic-forward-refs/#option-3%3A-augment-forwardref
*/
export type FixedForwardRef = <T, P = {}>(
@LeandrodeLimaC
LeandrodeLimaC / axios-timing.ts
Created March 21, 2024 16:38 — forked from forivall/axios-timing.ts
Axios Timing helper POC
import http = require('http')
import https = require('https')
import url = require('url')
import {AxiosInstance, AxiosInterceptorManager} from 'axios'
import {HttpRequestOptions as HttpFollowRequestOptions, http as httpFollow, https as httpsFollow} from 'follow-redirects'
import now = require('performance-now')
import httpAdapter = require('axios/lib/adapters/http')
import InterceptorManager = require('axios/lib/core/InterceptorManager')
@LeandrodeLimaC
LeandrodeLimaC / exercicios.sql
Last active February 12, 2024 23:13
Execícios finais do curso de SQLite Online: executando consultas SQL do Alura
-- Selecione os primeiros 5 registros da tabela clientes, ordenando-os pelo nome em ordem crescente.
Select * from Colaboradores
Order By nome
LIMIT 5;
-- Encontre todos os produtos na tabela produtos que não têm uma descrição associada (suponha que a coluna de descrição possa ser nula).
SELECT * from HistoricoEmprego
WHERE datatermino IS NULL;
@LeandrodeLimaC
LeandrodeLimaC / Split.ts
Last active October 13, 2023 21:56
Simple implementation of a recursive Utility Type to extract substrings using a delimiter
/**
* Splits a string based type into an tuple using a delimiter.
*
* @template S - The input string to be split.
* @template D - The delimiter string used for splitting.
* @template T - The resulting array of substrings.
*
* @returns A tuple of strings representing the segments of the original string after being split by the delimiter.
*
* @example
export function bufferPromise<
T,
PromiseFactoryFn extends (...args: any) => Promise<T>
>(
promiseFactoryFn: PromiseFactoryFn,
maxConcurrency = 5
) {
const activePromises: Array<Promise<T>> = [];
const queuedPromises: Array<() => Promise<T>> = [];
@LeandrodeLimaC
LeandrodeLimaC / index.ts
Created March 13, 2023 19:59
undoRedo function
type History<T> = Partial<T>[]
const undoRedo = <T extends Record<string, unknown>>(object: T) => {
const history: History<T> = [{...object}]
let currIndex = 0
const getState = (key: any) => {
const state = history[currIndex][key]
return state
@LeandrodeLimaC
LeandrodeLimaC / useUserDevice.tsx
Created December 9, 2022 14:49
React hook to check if user is on a Mobile devive
import { useEffect, useState, useRef } from 'react'
const MOBILE_BREAKPOINT = 640
let defaultWindowWidth = 0
/*
If using Nextjs, the following validation is necessary to ensure that we only try
to access the innerWidth when our code is running on user browser (client-side)
*/
if (typeof window !== 'undefined') {
@LeandrodeLimaC
LeandrodeLimaC / .babelrc
Created May 19, 2022 21:32
Desafio de Code Dojo Alliar :)
{
"presets": [
"@babel/preset-env"
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}