javascript
import { useCallback, useMemo, useState } from 'react';

function compare(a, b) {
  if (typeof a === 'number' && typeof b === 'number') return a - b;
  return String(a ?? '').localeCompare(String(b ?? ''));
}

Building a Paginated, Sortable Data Table with a useTable Hook in React

react hooks pagination
by codesnips 3 tabs
javascript
import { useState, useEffect, useCallback } from 'react';

export function useLocalStorage(key, initialValue) {
  const readValue = useCallback(() => {
    if (typeof window === 'undefined') return initialValue;
    try {

Persist a React Shopping Cart to localStorage with a Context Provider

javascript react context
by codesnips 3 tabs
python
from django.conf import settings
from django.db import models
from django.utils import timezone


class InvoiceQuerySet(models.QuerySet):

Scope a Django DetailView to the Request User with get_queryset

django authorization class-based-views
by codesnips 3 tabs
php
<?php

declare(strict_types=1);

namespace App\Security;

PHP Login Rate Limiting with a Sliding-Window Throttle Middleware

php rate-limiting middleware
by codesnips 3 tabs
go
package upload

import (
	"errors"
	"io"
	"log"

Streaming Multipart File Uploads to Disk in Go net/http

go net-http multipart
by codesnips 3 tabs
php
<?php

namespace App\Http\Requests\Wizard;

use Illuminate\Foundation\Http\FormRequest;

Multi-Step Onboarding Wizard in Laravel with Per-Step Form Requests and Session Progress

laravel forms validation
by codesnips 4 tabs
php
<?php

namespace App\Models;

use App\Support\TransientUrl;
use Illuminate\Database\Eloquent\Model;

Generate Temporary Signed S3 Download URLs for Private Files in Laravel

laravel s3 storage
by codesnips 4 tabs
java
import org.springframework.hateoas.RepresentationModel;
import java.math.BigDecimal;

public class ProductModel extends RepresentationModel<ProductModel> {

    private final Long id;

Cursor-Based Pagination with HATEOAS Links in Spring Data REST

spring-boot spring-data-jpa hateoas
by codesnips 4 tabs
go
package proxy

import (
	"log"
	"net"
	"net/http"

Building a Reverse Proxy in Go with httputil.ReverseProxy and Header Rewriting

go reverse-proxy httputil
by codesnips 3 tabs
rust
use std::error::Error;
use std::fmt;
use std::io;
use std::num::ParseIntError;

#[derive(Debug)]

Custom Error Enum With From Conversions for the ? Operator in Rust

rust error-handling traits
by codesnips 3 tabs
rust
use crate::paginator::Paginator;

#[derive(Clone)]
pub struct Row {
    pub cells: Vec<String>,
}

Streaming Paginated PDF Report Sections From a Domain Model in Rust

rust pdf pagination
by codesnips 3 tabs
typescript
export interface DocState {
  text: string;
  selection: number;
}

export interface Command<S> {

Undo/Redo in a React Text Editor with a Command-History Stack

react hooks undo-redo
by codesnips 3 tabs