rust
use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher};
use std::path::{Path, PathBuf};
use std::sync::mpsc;

pub fn spawn_watcher(root: &Path) -> notify::Result<(RecommendedWatcher, flume::Receiver<PathBuf>)> {
    let (raw_tx, raw_rx) = mpsc::channel::<notify::Result<Event>>();

Debouncing Rapid Filesystem Events in a Rust Directory Watcher

rust filesystem notify
by codesnips 3 tabs
javascript
const fs = require('fs');
const readline = require('readline');

async function* streamCsvRows(filePath) {
  const stream = fs.createReadStream(filePath, { encoding: 'utf8' });
  const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });

Stream and Import a Large CSV File Line-by-Line with Node.js readline

nodejs streams readline
by codesnips 3 tabs
python
import functools
import threading
import time
from collections import OrderedDict

Custom TTL + LRU Cache Decorator for Expensive Python Computations

python caching lru
by codesnips 2 tabs
javascript
import { useEffect, useState } from "react";

export function useDebounce(value, delay = 300) {
  const [debounced, setDebounced] = useState(value);

  useEffect(() => {

Debounced Search Box With Live Autocomplete in React

react hooks debounce
by codesnips 3 tabs
java
import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Predicate;

public final class RetryPolicy {
    private final int maxAttempts;

Async Retry With Exponential Backoff and Full Jitter Using ScheduledExecutorService

java retry backoff
by codesnips 3 tabs
typescript
export interface Todo {
  id: string;
  title: string;
  completed: boolean;
}

Optimistic UI Updates with Rollback Using React Query useMutation

react react-query optimistic-ui
by codesnips 3 tabs
go
package fetch

import (
	"context"
	"net/http"

Bounded Fan-Out With Worker Pool, errgroup, and Result Collection in Go

go concurrency goroutines
by codesnips 3 tabs
java
import jakarta.persistence.*;
import java.math.BigDecimal;
import java.util.Objects;

@Entity
@Table(name = "accounts")

Optimistic Locking with JPA @Version and Retry on Concurrent Updates

jpa hibernate spring
by codesnips 3 tabs
javascript
const RETRYABLE_STATUS = new Set([408, 429, 500, 502, 503, 504]);

export function fullJitter(attempt, baseDelay = 300, maxDelay = 10_000) {
  const ceiling = Math.min(maxDelay, baseDelay * 2 ** attempt);
  return Math.random() * ceiling;
}

Fetch With Exponential Backoff and Full Jitter Retries

fetch retry exponential-backoff
by codesnips 3 tabs