Explore

Public snippets from the community.

qwewqe

@bfzli·10m ago

JavaScript
console.log('hello')
100

r

Anonymous·17m ago

JavaScript
hello
100

One-line UUID v4

Anonymous·7h ago

JavaScript
// Generate an RFC 4122 v4 UUID using the Web Crypto API
const uuid = () =>
    ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
        (
6600

Debounced search input

@maya_dev·13h ago

TSX
function SearchBox({ onSearch }: { onSearch: (q: string) => void }) {
    const [value, setValue] = useState('')
    const debounced = useDebounce(value, 250)
20301

Find the 20 largest files

@linuxgnu·1d ago

Shell
# Find the 20 largest files under the current directory
find . -type f -printf '%s\t%p\n' 2>/dev/null \
  | sort -nr \
  | head -n 20 \
8701

Postgres upsert with ON CONFLICT

@linuxgnu·2d ago

SQL
-- Insert a row, or update it if the unique key already exists
INSERT INTO settings (user_id, key, value)
VALUES ($1, $2, $3)
ON CONFLICT (user_id, key)
15601

Tailwind cn() class merger

@maya_dev·3d ago

TypeScript
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'

// Merge conditional class names and resolve Tailwind conflicts.
12800

Python retry decorator

Anonymous·4d ago

Python
import time
from functools import wraps

def retry(times=3, delay=0.5):
9900

useDebounce hook

@maya_dev·5d ago

TypeScript
import { useState, useEffect } from 'react'

export function useDebounce<T>(value: T, delay = 300): T {
    const [debounced, setDebounced] = useState(value)
34221

Graceful HTTP shutdown in Go

@linuxgnu·8d ago

Go
func main() {
    srv := &http.Server{Addr: ":8080", Handler: routes()}

    go func() {
51011