web

swift
import UIKit
import WebKit

class WebViewController: UIViewController {
    private var webView: WKWebView!
    private var progressView: UIProgressView!

WKWebView for web content display

swift wkwebview webkit
by Sofia Martinez 1 tab
javascript
export const CACHE_VERSION = 'v7';

export const APP_SHELL = '/index.html';

export const PRECACHE_URLS = [
  '/',

Service worker: cache static assets safely

web performance pwa
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
python
from typing import Optional
from pydantic import BaseModel, EmailStr, Field, field_validator, model_validator


class CreateUserRequest(BaseModel):
    model_config = {"extra": "forbid"}

Validating JSON Payloads with Pydantic v2 and Returning Field-Level Errors in FastAPI

fastapi pydantic validation
by codesnips 3 tabs
ruby
class ParamSchema
  def initialize(fields)
    @fields = fields
  end

  def coerce(params)

Typed Query Param Coercion in a Sinatra before Filter with Schema Defaults

sinatra rack params
by codesnips 2 tabs
java
package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

CORS configuration for cross-origin requests

java spring-boot cors
by David Kumar 2 tabs
python
from flask import jsonify
from marshmallow import ValidationError as MarshmallowValidationError
from werkzeug.exceptions import HTTPException


class ApiError(Exception):

Structured JSON Error Handling for Flask API Validation Failures

flask rest-api error-handling
by codesnips 3 tabs
python
import re

EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")


class SignupValidator:

Validate a Flask Signup Form and Collect Per-Field Errors

flask validation forms
by codesnips 4 tabs
python
from datetime import datetime

from pydantic import BaseModel


class UserV1(BaseModel):

Versioning a FastAPI API With APIRouter Mounted Under /v1 and /v2 Prefixes

fastapi api-versioning apirouter
by codesnips 4 tabs
ruby
class CreateIdempotencyKeys < ActiveRecord::Migration[7.1]
  def change
    create_table :idempotency_keys do |t|
      t.string :key, null: false
      t.string :request_path, null: false
      t.datetime :locked_at

Idempotent Form Submissions in Rails with an Idempotency-Key Column and before_action Guard

rails idempotency postgres
by codesnips 4 tabs
python
import io
import os
from uuid import uuid4
from PIL import Image, UnidentifiedImageError

ALLOWED_FORMATS = {"JPEG", "PNG", "WEBP"}

Validate and Generate Image Thumbnails on a Flask Upload Endpoint With Pillow

flask pillow image-processing
by codesnips 3 tabs
rust
#[derive(Debug, Clone, Copy)]
pub struct ByteRange {
    pub start: u64,
    pub end: u64, // inclusive
}

Serving HTTP Range Requests in Axum with Partial Content Responses

axum http range-requests
by codesnips 3 tabs