const rules = {
required: (v) => v.trim() !== '' || 'This field is required.',
email: (v) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v) || 'Enter a valid email.',
min: (n) => (v) => v.length >= n || `Minimum ${n} characters required.`,
max: (n) => (v) => v.length <= n || `Maximum ${n} characters allowed.`,
from django.db import models
from django.utils import timezone
class TimestampMixin(models.Model):
/**
* Throttle: fire at most once per `limit` ms
*/
export function throttle(fn, limit = 200) {
let inThrottle = false;
/* Holy Grail Layout */
.holy-grail {
display: grid;
grid-template:
"header header header" 64px
// Deep partial
type DeepPartial<T> = T extends object
? { [K in keyof T]?: DeepPartial<T[K]> }
: T;
[alias]
# Short status
st = status -sb
# One-line log with graph
<?php
/**
* Human-readable time diff (like "3 hours ago").
*/
function time_ago( int $timestamp ): string {
-- Running total
SELECT
order_date,
amount,
SUM(amount) OVER (ORDER BY order_date) AS running_total
const BASE = '/wp-json/snipshare/v1';
async function request(path, options = {}) {
const res = await fetch(`${BASE}${path}`, {
headers: {
use std::fmt;
#[derive(Debug)]
pub enum AppError {
Io(std::io::Error),
package middleware
import (
"log"
"net/http"
<dialog id="modal" class="modal" aria-labelledby="modal-title" aria-describedby="modal-body">
<div class="modal__inner" role="document">
<header class="modal__header">
<h2 id="modal-title" class="modal__title">Confirm Action</h2>
<button class="modal__close" aria-label="Close dialog" autofocus>✕</button>
from datetime import datetime, timedelta
from typing import Optional
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
import { useState, useMemo } from 'react';
export default function SortableTable({ columns, data }) {
const [sort, setSort] = useState({ key: null, dir: 'asc' });
<?php
add_action( 'init', 'register_book_cpt' );
function register_book_cpt() {
$labels = [
version: '3.9'
services:
app:
build: .
export class EventEmitter {
#listeners = new Map();
on(event, listener) {
if (!this.#listeners.has(event)) {
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
interface RateLimiterOptions {
windowMs: number;
max: number;
}
import time
import contextlib
from typing import Generator