Skip to content

Instantly share code, notes, and snippets.

View mortegac's full-sized avatar
🏖️
Working from Miami Beach

Manuel Ortega Carcamo mortegac

🏖️
Working from Miami Beach
View GitHub Profile
@mortegac
mortegac / use-copy-to-clipboard.ts
Created January 31, 2024 20:36 — forked from KristofferEriksson/use-copy-to-clipboard.ts
Custom React hook for effortless text copying to clipboard! It handles copy status with a customizable timer and error management.
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 {
@mortegac
mortegac / useConfirmation.ts
Created January 31, 2024 20:36 — forked from KristofferEriksson/useConfirmation.ts
Custom React hook for double-click confirmation for critical actions
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) => {
@mortegac
mortegac / useLocalStorage.ts
Created January 31, 2024 20:35 — forked from KristofferEriksson/useLocalStorage.ts
An easy-to-use API for storing and retrieving data from Local Storage in React, with built-in real-time synchronization
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));
@mortegac
mortegac / useIdle.ts
Created January 31, 2024 20:35 — forked from KristofferEriksson/useIdle.ts
React Hook to detect user inactivity based on specified events like mouse movements, touch events or key presses
import { useEffect, useState } from "react";
const defaultEvents = [
"mousemove",
"mousedown",
"touchstart",
"keydown",
"wheel",
"resize",
];
@mortegac
mortegac / useUndo.ts
Created January 31, 2024 20:33 — forked from KristofferEriksson/useUndo.ts
A React hook that enhances your components with powerful undo/redo functionality
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;
@mortegac
mortegac / chatgpt_api.py
Created March 26, 2023 03:20 — forked from mouredev/chatgpt_api.py
Ejemplo de uso del API de ChatGPT desde Python
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
@mortegac
mortegac / timezones.json
Created January 21, 2023 06:00 — forked from josephrexme/timezones.json
Timezones in JSON format
[
{
"value": "Dateline Standard Time",
"abbr": "DST",
"offset": -12,
"isdst": false,
"text": "(UTC-12:00) International Date Line West"
},
{
"value": "UTC-11",
@mortegac
mortegac / homebrew-permissions-issue.md
Last active October 8, 2021 20:40 — forked from irazasyed/homebrew-permissions-issue.md
Homebrew: Permissions Denied Issue Fix (OS X / macOS)

Homebrew Permissions Denied Issues Solution

sudo chown -R $(whoami) $(brew --prefix)/*

and

sudo chown -R $(whoami) /usr/local

@mortegac
mortegac / useCookie.js
Created September 9, 2021 20:34 — forked from lwkchan/useCookie.js
Simple React hook to get/set Cookies with 'universal-cookie' package 🍪
import {useState} from 'react';
import Cookies from 'universal-cookie';
const useCookie = (key, options = {}) => {
const cookies = new Cookies();
const [item, setItemValue] = useState(() => {
if (cookies.get(key)) {
return cookies.get(key);
}
return null;
@mortegac
mortegac / states.js
Created September 7, 2021 20:02 — forked from marshallswain/states.js
US States & Abbreviations as JavaScript Array
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'},