Skip to content

Instantly share code, notes, and snippets.

View CarmeloRicarte's full-sized avatar
🏠
Working from home

Carmelo Ricarte Rocamora CarmeloRicarte

🏠
Working from home
View GitHub Profile
@CarmeloRicarte
CarmeloRicarte / test-utils.tsx
Last active December 20, 2022 15:17
Render store hook with providers
import React, { PropsWithChildren } from "react";
import { renderHook, RenderOptions } from "@testing-library/react";
import { Provider } from "react-redux";
import { ToolkitStore } from "@reduxjs/toolkit/dist/configureStore";
import type { AppStore } from "../../src/store";
// This type interface extends the default options for render from RTL, as well
// as allows the user to specify other things such as store.
interface ExtendedRenderOptions extends Omit<RenderOptions, "queries"> {
store?: AppStore;
@CarmeloRicarte
CarmeloRicarte / time-since.ts
Created January 23, 2023 16:48 — forked from Klerith/time-since.ts
Fecha de creación humana
export const timeSince = ( date: string ) => {
const baseDate = new Date(date)
const seconds = Math.floor(( new Date().getTime() - baseDate.getTime() ) / 1000);
let interval = seconds / 31536000;
@CarmeloRicarte
CarmeloRicarte / CustomTable.css
Last active February 23, 2023 12:02
Custom table witn React, Typescript, CSS without libraries
.table-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
}
.table {
width: 100%;
max-width: 90vw;
@CarmeloRicarte
CarmeloRicarte / configurar-node-ts.md
Created September 26, 2023 07:20 — forked from Klerith/configurar-node-ts.md
Node con TypeScript - TS-Node-dev simplificado

Node con TypeScript - TS-Node-dev (preferido)

  1. Instalar TypeScript y demás dependencias
npm i -D typescript @types/node ts-node-dev rimraf
  1. Inicializar el archivo de configuración de TypeScript ( Se puede configurar al gusto)
npx tsc --init --outDir dist/ --rootDir src
@CarmeloRicarte
CarmeloRicarte / debounce.ts
Created April 22, 2025 14:16
Debounce with Typescript and example of use
// biome-ignore lint/suspicious/noExplicitAny
export function debounce<T extends (...args: any[]) => void>(func: T, timeout = 300): (...args: Parameters<T>) => void {
let timer: NodeJS.Timeout | undefined;
return (...args: Parameters<T>) => {
clearTimeout(timer);
timer = setTimeout(() => {
func(...args);
}, timeout);
};