timers

typescript
import { useCallback, useEffect, useReducer } from "react";

type State = { secondsLeft: number; isRunning: boolean };
type Action =
  | { type: "start"; seconds: number }
  | { type: "tick" }

Resend-Code Button With a Countdown Timer Using useEffect Cleanup

react hooks useeffect
by codesnips 3 tabs
javascript
export const MAX_VISIBLE = 4;

const DEFAULTS = {
  variant: "info",
  duration: 4000,
};

Toast Notification Queue in React with Context and useReducer

react context-api usereducer
by codesnips 3 tabs
python
import functools
import threading


def debounce(wait):
    def decorator(func):

Debounce Repeated Function Calls With a Thread-Safe Python Decorator

python decorators debounce
by codesnips 2 tabs
javascript
import { useState, useRef, useEffect, useCallback } from "react";

export function useCarousel(length, { delay = 4000 } = {}) {
  const [index, setIndex] = useState(0);
  const [paused, setPaused] = useState(false);
  const savedCallback = useRef(null);

Autoplay Image Carousel in React with Pause-on-Hover via useRef and useEffect

react hooks carousel
by codesnips 3 tabs
go
package watch

import (
	"sync"
	"time"
)

Debounce Filesystem Change Events Before Triggering a Rebuild in Go

fsnotify debounce filewatcher
by codesnips 3 tabs
typescript
export interface CronFields {
  minute: Set<number>;
  hour: Set<number>;
  dayOfMonth: Set<number>;
  month: Set<number>;
  dayOfWeek: Set<number>;

Cron-Expression Scheduler with Field Parser and a Tick Loop in TypeScript

cron scheduler parser
by codesnips 3 tabs