SShortSingh.
Back to feed

Developer builds a swinging lanyard badge in React without a physics library

0
·6 views

A developer wanted an ID badge that swings and flies when grabbed and thrown, but found existing examples relied on heavy physics engines and 3D renderers. Instead, they modeled the strap as a chain of points using Verlet integration, which makes throwing work naturally because each point's velocity is implicit in its previous position. Distance constraints keep the rope lengths consistent, with weighting that makes the card hang and swing like a pendulum. A spring-driven angle adds lag and overshoot, and the developer fixed issues like stretching and runaway flick speeds, while stopping the loop when idle and respecting reduced-motion settings. The complete implementation comes to about 500 lines in a single file with only React and one Motion hook as dependencies.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Firecracker Rate Limiters Use Token Buckets to Cap VM Network, Disk and Entropy Use

A microVM with unrestricted network or disk throughput can degrade performance for other VMs on the same host, so Firecracker applies rate limits to each emulated device. These limits are implemented with token buckets, configured through a small set of integer parameters that are easy to misread. Limiters can be applied to network receive and transmit, block devices, the entropy device, and the serial console, with bandwidth (bytes) and operations-per-second limits working independently. Each bucket is defined by a size, a refill time that sets the sustained rate, and an optional one-time initial burst. The article illustrates the arithmetic with example configurations, noting that the values should be chosen based on host capacity and the number of VMs sharing it.

0
ProgrammingDEV Community ·

Making Python Background Jobs Reliable with Retries, Idempotency, and Recovery

Moving slow work like emails, uploads, and report generation out of HTTP requests keeps APIs responsive, but it does not by itself make that work reliable. Workers can crash, networks can time out, and external services can fail, and tasks may occasionally run twice. The article contrasts a simple in-process approach, such as FastAPI's BackgroundTasks, which loses jobs on restart, with durable distributed queues like Celery, RQ, and Dramatiq. It recommends separating job submission from execution so clients receive a task ID and can check status later. The author argues that engineers should plan for failure from the outset, covering sensible retries, idempotency to prevent duplicate work, and recovery after errors.

0
ProgrammingDEV Community ·

OpenAI may be shifting to cost control as AI development expenses rise

A developer writing on DEV Community suggests that OpenAI may be operating in cost control mode amid a recent shift in its approach. The author notes that training large language models is expensive, drawing on their own unsuccessful attempt to train a small model. They also describe scaling back AI features in a client chatbot project after weighing costs against value. The piece questions whether a stronger focus on cost efficiency could limit creativity and experimentation in generative AI.

0
ProgrammingDEV Community ·

Why AI agent frameworks alone don't make agents production-ready

A developer notes that agents that demo well often fail when regulated customers ask for proof of approved behavior, auditability, and compliance visibility. The author argues that the gaps are structural rather than solved by better frameworks or models, since frameworks like LangGraph, CrewAI, and Microsoft Agent Framework place control logic inside the agent's own code. The proposed alternative is a system-first runtime in which the model only translates user input into structured intent, and a separate runtime decides whether that intent becomes an action. The runtime is configured by a declarative YAML contract covering data access, governance rules, workflows, and integrations, which compliance teams can read and sign. Actions not declared in the contract have no tool available to the model and are rejected as unknown.