typescript
import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';

function hasActualValue(control: AbstractControl | null): boolean {
  return !!control && control.value !== null && control.value !== '';
}

Cross-Field Password-Confirmation Validator for Angular Reactive Forms

angular reactive-forms validators
by codesnips 3 tabs
java
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

import Transaction.Category;

Grouping and Summarizing Transactions with Java Stream Collectors

java streams collectors
by codesnips 3 tabs
rust
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EmailAddress(String);

impl EmailAddress {
    pub fn parse(raw: &str) -> Result<Self, String> {
        if raw.contains('@') && !raw.starts_with('@') {

Bidirectional From Conversions Between Domain and API DTO Types in Rust

rust serde dto
by codesnips 3 tabs
javascript
export const wizardMachine = {
  initial: 'account',
  states: {
    account: {
      next: 'profile',
      canLeave: (data) => Boolean(data.email && data.password),

Multi-Step Wizard Form With a Context-Driven State Machine in React

react state-machine context
by codesnips 3 tabs
javascript
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["input", "frame"]
  static values = { url: String, delay: { type: Number, default: 300 }, min: { type: Number, default: 2 } }

Debounced Search Suggestions With a Turbo Frame Lazy-Loaded Results Partial

rails hotwire turbo
by codesnips 4 tabs
typescript
import { AxiosError } from 'axios';

export const RETRY_CONFIG = {
  maxRetries: 4,
  baseDelayMs: 200,
  maxDelayMs: 5_000,

Exponential-Backoff Retry Interceptor Around NestJS HttpService

nestjs http retry
by codesnips 3 tabs
python
from marshmallow import (
    Schema, fields, validates, validates_schema,
    ValidationError, RAISE,
)
from marshmallow.validate import Length, Email, Equal

Field-Level Signup Validation in Flask with Marshmallow Schemas

flask marshmallow validation
by codesnips 3 tabs
java
package com.example.ratelimit;

public class TokenBucket {

    private final long capacity;
    private final long refillTokens;

Per-Client Token Bucket Rate Limiting with a Spring Boot HandlerInterceptor

spring-boot rate-limiting token-bucket
by codesnips 4 tabs
javascript
import { useState, useRef, useEffect, useCallback } from 'react';

export function useOnScreen(options = {}) {
  const [node, setNode] = useState(null);
  const [isIntersecting, setIsIntersecting] = useState(false);

Infinite Scroll in React with an IntersectionObserver useOnScreen Hook

react hooks intersection-observer
by codesnips 3 tabs
typescript
export interface QueryCodec<T> {
  parse: (raw: string | null) => T;
  serialize: (value: T) => string | null;
}

export function stringParam(fallback = ""): QueryCodec<string> {

Sync Typed Form State to the URL Query String with a useQueryState Hook

react hooks url-state
by codesnips 3 tabs
python
from datetime import date, datetime
from decimal import Decimal, InvalidOperation
from enum import Enum

from pydantic import BaseModel, field_validator

Parsing and Normalizing a Transactions CSV into Typed Records with Pydantic

csv pydantic data-parsing
by codesnips 2 tabs
rust
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppConfig {
    #[serde(default)]
    pub server: ServerConfig,

Layered Config Loading From TOML File and Environment Variables in Rust

config serde toml
by codesnips 3 tabs