and
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useCallback, useState } from "react"; | |
| // Custom hook to copy text to clipboard | |
| const useCopyToClipboard = (timeoutDuration: number = 1000) => { | |
| const [copied, setCopied] = useState(false); | |
| const [error, setError] = useState<Error | null>(null); | |
| const copyToClipboard = useCallback( | |
| async (text: string) => { | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useCallback, useEffect, useRef, useState } from "react"; | |
| /** | |
| * Custom React hook for double-click confirmation for critical actions. | |
| * | |
| * @param action - The action to be executed on the second click. | |
| * @param timeout - Time in milliseconds to reset the unlocked state. | |
| * @returns The current unlocked state and the trigger function. | |
| */ | |
| const useConfirmation = (action: () => void, timeout: number = 5000) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from "react"; | |
| function useLocalStorage() { | |
| const [loadingStates, setLoadingStates] = useState<Map<string, boolean>>( | |
| new Map() | |
| ); | |
| const setStorageValue = <T>(key: string, value: T) => { | |
| try { | |
| window.localStorage.setItem(key, JSON.stringify(value)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from "react"; | |
| const defaultEvents = [ | |
| "mousemove", | |
| "mousedown", | |
| "touchstart", | |
| "keydown", | |
| "wheel", | |
| "resize", | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useCallback, useEffect, useRef, useState } from "react"; | |
| interface UseUndoHook<T> { | |
| value: T; | |
| onChange: (newValue: T) => void; | |
| undo: () => void; | |
| redo: () => void; | |
| clear: () => void; | |
| canUndo: boolean; | |
| canRedo: boolean; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import openai # pip install openai | |
| import typer # pip install "typer[all]" | |
| from rich import print # pip install rich | |
| from rich.table import Table | |
| """ | |
| Webs de interés: | |
| - Módulo OpenAI: https://github.com/openai/openai-python | |
| - Documentación API ChatGPT: https://platform.openai.com/docs/api-reference/chat | |
| - Typer: https://typer.tiangolo.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "value": "Dateline Standard Time", | |
| "abbr": "DST", | |
| "offset": -12, | |
| "isdst": false, | |
| "text": "(UTC-12:00) International Date Line West" | |
| }, | |
| { | |
| "value": "UTC-11", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var usStates = [ | |
| { name: 'ALABAMA', abbreviation: 'AL'}, | |
| { name: 'ALASKA', abbreviation: 'AK'}, | |
| { name: 'AMERICAN SAMOA', abbreviation: 'AS'}, | |
| { name: 'ARIZONA', abbreviation: 'AZ'}, | |
| { name: 'ARKANSAS', abbreviation: 'AR'}, | |
| { name: 'CALIFORNIA', abbreviation: 'CA'}, | |
| { name: 'COLORADO', abbreviation: 'CO'}, | |
| { name: 'CONNECTICUT', abbreviation: 'CT'}, | |
| { name: 'DELAWARE', abbreviation: 'DE'}, |
NewerOlder