Skip to content

Archive / page 77

All articles

Every practical article from the Nalar archive, newest first.

Software Engineering 04 Sep 2026 9 min read

Parse Boundary Data into Trusted Types

Validation often starts as a small check near the edge of a program. As the system grows, the same fact gets checked again in handlers, services, helpers, and background jobs because none of those places can tell whether the value they received has already been validated. The result is defensive code everywhere and uncertainty about what a function may safely assume. A useful design technique is to parse boundary data into a trusted type. Instead of checking a raw value and then continuing to pass that raw value around, convert it into a representation that can exist only after the required checks succeed. Core code receives that representation and can rely on the facts it expresses.

Python 04 Sep 2026 8 min read

Order Dependency-Driven Work in Python with graphlib.TopologicalSorter

Many automation tasks are not really lists. They are dependency graphs. A deployment may need a database migration before the API starts, while static assets can build independently. A data pipeline may need two source extracts before a join can run. A build system may have several targets that become runnable as soon as their prerequisites finish. If you encode this work as one hand-written sequence, you hide the real constraint: which tasks depend on which other tasks. That makes the sequence harder to change and can prevent independent work from running concurrently.

Tech 04 Sep 2026 8 min read

Optical vs Digital Zoom: What Changes in Your Phone Camera

Pinch outward in a phone camera app and the subject becomes larger on screen. That simple gesture can hide an important difference: sometimes the phone changes how the scene is captured, while other times it mainly enlarges a smaller part of an image it already has. These approaches are commonly described as optical zoom and digital zoom. The distinction matters because making a subject look larger is not the same as recording more detail about it.

Cybersecurity 04 Sep 2026 10 min read

Normalize Security-Sensitive Input Before Making Decisions

Security checks often compare names, paths, identifiers, hosts, or other values against a rule. The rule may be correct and the comparison may look correct, yet the system can still make the wrong decision if different components interpret the same input differently. For example, one layer may treat two textual forms as equivalent while another treats them as different. A validator can approve one representation, then a later component can normalize or decode it into a different value before using it. The security check and the operation are no longer reasoning about the same thing.

Artificial Intelligence 04 Sep 2026 10 min read

Negative Sampling for Representation Learning

Some representation-learning problems have an awkward shape: each training example has one observed target, but the model could choose from thousands or millions of alternatives. Computing a score and normalization term for every alternative on every update can become a major training cost. Negative sampling changes the training problem. Instead of comparing the observed target with every possible alternative, the model learns from the observed positive pair and a small set of deliberately sampled negative pairs. The update becomes much cheaper, but it also optimizes a sampled discrimination objective rather than the exact full-class objective.

Tech 04 Sep 2026 7 min read

Modem vs Router: What Each Device Does at Home

Home internet equipment can be confusing because one box may seem to do everything. You connect a phone to Wi-Fi, the phone reaches the internet, and the equipment near the wall quietly handles the rest. When something stops working, labels such as modem, router, and gateway suddenly matter. The simplest distinction is this: a modem or similar access device connects your home to your internet provider’s network, while a router connects your local devices to one another and directs their traffic toward other networks. Wi-Fi is commonly built into the router, but Wi-Fi itself is not the same thing as internet service.

Python 04 Sep 2026 11 min read

Model Combinable Options in Python with enum.Flag and IntFlag

Some values represent one choice from a fixed set. A log level might be INFO, WARNING, or ERROR. Python’s Enum is a natural fit because one value should identify one member. Other values represent a combination of independent options. A file operation may allow reading and writing. A protocol field may enable compression and encryption. A component may expose several capabilities at the same time. Representing those combinations as ordinary booleans works at first:

Artificial Intelligence 04 Sep 2026 11 min read

Mean Teacher for Semi-Supervised Learning with Unlabeled Data

Many machine learning projects have far more raw examples than labeled ones. A team may have millions of images, audio clips, or sensor readings, but only a small subset has been reviewed by people. Standard supervised training ignores the unlabeled remainder because it has no target labels to compare with the model’s predictions. Mean Teacher provides a way to use those unlabeled examples without pretending that their unknown labels are known. It trains a student model to make predictions that stay consistent with a more slowly changing teacher model. The teacher is not a separately trained expert: its parameters are an exponential moving average of the student’s parameters.

Software Engineering 04 Sep 2026 7 min read

Making Time an Explicit Dependency

Code that asks the system clock for the current time looks harmless. The difficulty appears when behavior depends on the answer. A test for an expired reservation may pass now and fail later. A boundary such as midnight can become awkward to reproduce. Business logic becomes tied to an environmental input that callers cannot see or control. A useful design move is to treat the current time as a dependency. Instead of letting decision-making code reach for a clock whenever it needs one, obtain the time at a clear boundary and pass the relevant value or clock into the code that makes the decision.

Cybersecurity 04 Sep 2026 9 min read

Make Security-Sensitive State Changes Atomic

Security checks can be individually correct and still fail when two requests run at the same time. A request checks that a recovery code is unused, a withdrawal is within a limit, or an approval is still pending. Before it records the state change, another request performs the same check against the same old state. Both requests then proceed even though the rule was meant to allow only one. This is a race condition: correctness depends on the relative timing of concurrent operations. A common form is a time-of-check to time-of-use problem, often shortened to TOCTOU, where the fact established by a check can become false before the protected action uses it.

Artificial Intelligence 04 Sep 2026 10 min read

Macro F1 and Balanced Accuracy for Imbalanced Classifiers

A classifier can report impressive accuracy while failing on the cases you care about most. This happens easily when one class is much more common than another. Imagine a model that detects defective components on a production line. In a test set of 1,000 components, 950 are normal and 50 are defective. A model that predicts normal for every component is correct 95% of the time, yet it detects none of the defects.

Software Engineering 04 Sep 2026 9 min read

Limiting Object Navigation to Protect Encapsulation

A method can depend on far more of a system than its parameter list suggests. The warning sign is often a chain that reaches through one object to inspect several others: order.customer.address.country.code The expression is short, but the caller now knows that an order has a customer, the customer has an address, the address has a country, and the country exposes a code. A change anywhere along that path can force the caller to change even when the caller’s real question has not changed.

Artificial Intelligence 04 Sep 2026 10 min read

Layer Normalization in Transformers

Transformer diagrams often contain small boxes labeled LayerNorm or Norm. They are easy to treat as plumbing between attention and feed-forward layers, but normalization has an important job: it controls the scale of hidden activations as information passes through many residual blocks. That matters because a transformer repeatedly adds new updates to an existing residual stream. If activation scales become poorly behaved, optimization can become harder and numerical problems can become more likely. Layer normalization gives each normalized hidden vector a predictable scale while preserving learnable degrees of freedom.

Software Engineering 04 Sep 2026 9 min read

Keeping Framework Code Thin with Humble Objects

Some code is difficult to test for reasons that have little to do with the business rule it implements. A user-interface handler may need a framework event. A scheduled job may be created by a runtime. A message consumer may receive objects owned by a library. The code then mixes two jobs: interacting with an awkward environment and deciding what the application should do. When those jobs stay together, a small rule can require a large test setup. Developers may respond by skipping tests, mocking many framework details, or testing through slow integration paths even when the important logic is simple.

Software Engineering 04 Sep 2026 9 min read

Keeping Behavior Close to the Data It Needs

A method can belong to one module while doing most of its thinking with data owned by another. When that happens repeatedly, a small change to the data often forces changes in distant code as well. This design smell is commonly called feature envy: behavior appears more interested in another object or module than in the one that contains it. The useful lesson is broader than the name. When a piece of behavior depends heavily on particular data and the rules around that data, keeping them close usually makes those rules easier to find, protect, and change together.

Cybersecurity 04 Sep 2026 10 min read

Keep Redirect Targets Inside Trusted Destinations

Redirects are useful after sign-in, checkout, account setup, and many other workflows. The danger appears when an application lets request data decide the destination without enforcing where that destination may point. For example, a sign-in page might accept a next value and redirect the user there after authentication. If any absolute URL is accepted, an attacker can create a link on the application’s real domain that sends the user to an unrelated site. The first URL looks legitimate, but the final destination is controlled by someone else.

Cybersecurity 04 Sep 2026 9 min read

Keep Internal Error Details Out of Client Responses

When an application fails, developers need enough detail to diagnose the problem. The client usually does not. If the same exception text, stack trace, database error, filesystem path, or upstream response is sent to both places, an ordinary failure can become an information leak. The consequence is not that every leaked error immediately compromises a system. The problem is that internal details can reveal data, identifiers, software structure, trust relationships, or assumptions that were never meant to cross the application’s public boundary. They can also expose secrets when sensitive values have been included in an exception or diagnostic message.

Cybersecurity 04 Sep 2026 11 min read

Keep File Access Inside an Intended Directory

Applications often let a caller identify a file: download an invoice, open an exported report, read a template, or retrieve an uploaded document. The dangerous version of this design treats a caller-controlled path as if it were already a permitted file. A path can describe movement through a filesystem, not just a filename. If untrusted input is combined with an application directory without a reliable containment check, the resulting path may resolve somewhere outside that directory. A read operation can expose configuration or private data; a write or delete operation can have more serious consequences.

Cybersecurity 04 Sep 2026 11 min read

Keep Encryption Nonces Unique

Modern authenticated encryption can protect both the confidentiality and integrity of data, but some algorithms depend on a small operational rule that is easy to overlook: do not reuse a nonce with the same key. A nonce is a value supplied to a cryptographic operation for a particular invocation. The word comes from “number used once,” but a nonce is not necessarily secret and is not necessarily a simple counter. What matters is the requirement of the algorithm using it. For widely used authenticated-encryption schemes such as AES-GCM and ChaCha20-Poly1305, nonce reuse under the same key can invalidate important security guarantees.

Cybersecurity 04 Sep 2026 9 min read

Keep Data Separate from Interpreter Syntax

Applications constantly move data into systems that interpret syntax: databases parse queries, shells parse commands, browsers parse HTML, and template engines parse expressions. A security problem appears when data that should remain inert can change the structure of those instructions. That is the core of injection. If an attacker can influence where instructions end and data begins, the receiving interpreter may perform work the developer never intended. The consequence depends on the interpreter: unauthorized database operations, unintended operating-system actions, or active content in a browser are all possible outcomes of the same design mistake.

Artificial Intelligence 04 Sep 2026 9 min read

Interpret Language Model Perplexity Correctly

A language model can improve on its training objective while still leaving an important question unanswered: how well does it predict text it did not train on? Perplexity is a compact way to measure that predictive fit for autoregressive language models, but the number is easy to misuse. A lower perplexity can mean that a model assigns higher probability to held-out text. It does not automatically mean that the model follows instructions better, reasons more reliably, hallucinates less, or produces more useful answers. Comparisons can also become misleading when tokenization, evaluation data, or context handling differs.

Linux 04 Sep 2026 11 min read

Integrate Timers into Linux Event Loops with timerfd

Event loops work best when unrelated kinds of work have one common waiting mechanism. Sockets become readable. Pipes become writable. A child-process descriptor or signal descriptor can become ready. Timers are often the awkward exception. A program can call sleep() or nanosleep(), but that blocks the thread instead of letting it wait for I/O. It can pass a timeout to poll() or epoll_wait(), but one timeout becomes difficult to manage when the program has several independent deadlines. Traditional POSIX timers can deliver signals, which introduces a second asynchronous control path.

Tech 04 Sep 2026 7 min read

How Haptic Feedback Makes Touchscreens Feel Responsive

Tap a key on a touchscreen keyboard and you may feel a tiny pulse even though the glass itself never moves like a physical key. Drag a control into place and the phone may produce a brief click-like sensation. These responses are examples of haptic feedback: physical feedback generated by a device to accompany an action or event. Haptics can make a touchscreen feel more responsive because they give your sense of touch another signal that something happened. The screen still detects the touch electronically, and software still decides what the touch means. The vibration is feedback after or alongside that process, not the mechanism that detects your finger.

Tech 04 Sep 2026 9 min read

How Browser Autofill Works and Why It Sometimes Gets Forms Wrong

Autofill can turn a long checkout or registration form into a few clicks. A browser recognises fields for your name, address, phone number, or other information and offers to fill them from details you previously saved. When it works, it feels as if the browser understands the page. When it does not, a phone number may appear in an address field or an old address may be offered at the wrong time.