Skip to content

Archive / page 45

All articles

Every practical article from the Nalar archive, newest first.

Cybersecurity 11 Sep 2026 7 min read

Secure Archive Extraction Against Path Traversal

Archive extraction looks simple: open a ZIP or TAR file, iterate over its entries, and write each entry under a destination directory. The dangerous detail is that archive entries carry names and, in some formats, filesystem object types. Those fields come from the archive creator. If extraction code joins an untrusted entry name to a trusted destination without enforcing containment, an entry such as ../../app/config.json can escape the intended directory. A crafted archive can then overwrite files that the application account is permitted to modify.

Artificial Intelligence 11 Sep 2026 9 min read

Score Candidates with Energy-Based Models

Score Candidates with Energy-Based Models Many AI systems need to decide which candidate fits an input: which reply matches a conversation, which label fits an image, or which configuration is plausible. A common design makes the model output a probability directly. Energy-based models take a more general route: they assign each input-candidate pair a scalar energy, with lower values representing greater compatibility. That simple change is useful because the model can focus on relative preference without requiring every architecture to produce a normalized probability during scoring. It also introduces real engineering challenges. Training needs informative alternatives, probability normalization can be expensive, and inference may require searching a large candidate space.

Artificial Intelligence 11 Sep 2026 10 min read

RMSNorm in Transformers

RMSNorm in Transformers A transformer repeatedly adds residual updates to its hidden states. Without some way to control the scale of those values, training deep networks becomes harder to manage. Normalization layers are one of the mechanisms used to keep that computation well behaved. RMSNorm, short for root mean square normalization, is a normalization method used in many transformer architectures. It looks similar to LayerNorm, but it deliberately leaves out one operation: subtracting the mean. Instead, RMSNorm measures the root mean square magnitude of a hidden vector and rescales the vector by that magnitude.

Artificial Intelligence 11 Sep 2026 11 min read

Reweight Long-Tailed Classification with Effective Sample Counts

A classifier trained on a long-tailed dataset can see thousands of examples from common classes and only a handful from rare ones. Ordinary empirical risk minimization gives the common classes more influence simply because they appear more often. A tempting fix is to weight each class by the inverse of its example count, but that can make a tiny class disproportionately influential, including any mislabeled examples it contains. Class-balanced loss based on the effective number of samples provides a smoother way to derive class weights. Instead of treating every additional example as equally informative, it models diminishing returns within a class and weights classes according to an adjusted, or effective, sample count.

Go 11 Sep 2026 5 min read

Reverse Go Slices in Place with slices.Reverse

Sometimes the order stored in a slice needs to change, not just the order in which code visits its elements. A queue may need newest-first presentation, a collected path may need to run from origin to destination, or a stack snapshot may need its top element first. slices.Reverse handles that edit directly. The key detail is mutation. slices.Reverse rearranges the existing slice in place. It doesn’t return a replacement slice, and code sharing the same backing array can observe the new order.

Go 11 Sep 2026 5 min read

Reserve Go Slice Capacity with slices.Grow

Repeated append calls can force a Go slice to move to a larger backing array when its capacity runs out. If code already knows that several more elements are about to arrive, slices.Grow can reserve enough room before those appends happen. The key detail is that slices.Grow changes capacity when needed, not length. Existing elements stay in place logically, and the returned slice still contains the same number of elements.

Software Engineering 11 Sep 2026 7 min read

Replacing Type Branches with Polymorphism

Replacing Type Branches with Polymorphism A type-based switch can be perfectly clear. Trouble starts when the same cases appear across several operations. Adding one new type then means editing pricing, validation, formatting, scheduling, and other branches in separate places. The type list has become a change axis, but the code still represents it as scattered conditionals. Replacing type branches with polymorphism moves behavior for each variant behind a shared contract. Callers ask for an operation without selecting the implementation themselves. This can concentrate related rules and reduce repeated branching, but it also introduces more types and indirection. The refactoring pays off only when that trade is useful.

Software Engineering 11 Sep 2026 8 min read

Replacing Inheritance with Delegation

Replacing Inheritance with Delegation A class needs three useful methods from another class, so extending that class seems convenient. Months later, the subclass also inherits methods it shouldn’t expose, depends on initialization details it doesn’t control, and breaks when the superclass changes an internal assumption. The problem isn’t inheritance itself. The problem is using an is-a relationship to obtain code reuse when the real relationship is uses-a. Replacing inheritance with delegation makes that relationship explicit: the object keeps a collaborator and forwards only the behavior it actually needs.

Software Engineering 11 Sep 2026 8 min read

Replace Nested Conditionals with Guard Clauses

Replace Nested Conditionals with Guard Clauses A method often starts simple and becomes deeply nested one condition at a time. A null check wraps a permission check. That wraps a state check. The actual operation ends up several indentation levels from the method boundary, even though it is the main path a reader cares about. Guard clauses handle exceptional or disqualifying conditions near the top of a method and exit immediately. The remaining code can then describe the normal path with less structural noise.

Software Engineering 11 Sep 2026 8 min read

Replace Magic Numbers with Named Domain Values

Replace Magic Numbers with Named Domain Values A condition such as attempts >= 5 is easy to execute and surprisingly hard to review. Why five? Is it a security policy, a technical limit, a temporary experiment, or just an arbitrary value copied from somewhere else? The code contains the number but not the reason it exists. A magic number is a numeric literal whose meaning isn’t clear from its context. Replacing one well means more than moving it into a constant. The goal is to preserve the value’s meaning, units, and ownership so a future change has an obvious place to happen.

Software Engineering 11 Sep 2026 8 min read

Replace Data Clumps with Parameter Objects

Replace Data Clumps with Parameter Objects A method takes startDate, endDate, and timezone. Another method takes the same three values. A third passes them unchanged to a lower layer. Soon, changing what “reporting period” means requires editing signatures across the codebase. This is a common design smell called a data clump: several values repeatedly appear together because they are really parts of one concept, but the code still treats them as unrelated pieces. A parameter object gives that concept a name and a boundary.

Go 11 Sep 2026 5 min read

Replace a Range in Go Slices with slices.Replace

Replacing part of a slice often starts as an append expression that works but takes a moment to decode. slices.Replace gives that operation a direct name: choose the half-open range s[i:j], provide replacement values, and keep the returned slice. The replacement doesn’t have to be the same size as the removed range. It can be shorter, longer, or empty, which makes slices.Replace useful for more than one-for-one edits. Replace a slice range with slices.Replace The basic call replaces every element from index i up to, but not including, index j:

Go 11 Sep 2026 4 min read

Remove Adjacent Duplicates from Go Slices with slices.Compact

Duplicate values often arrive in runs: repeated status events, sorted IDs, or adjacent tokens produced by a parser. When only consecutive duplicates need to disappear, slices.Compact handles the operation without a handwritten loop. The distinction is specific. slices.Compact collapses adjacent equal values; it doesn’t search the entire slice for duplicates. It also modifies the slice’s backing storage, so callers need to account for aliasing. Remove adjacent duplicates with slices.Compact Pass a slice whose element type is comparable and assign the returned slice:

Go 11 Sep 2026 6 min read

Remove a Range from Go Slices with slices.Delete

Removing a known range from a Go slice is easy to express with slices.Delete. Give it the slice and a half-open index range, and it closes the gap for you. The small details matter. slices.Delete changes the slice’s contents, returns a slice with a new length, and panics for an invalid range. Using it well means treating those behaviors as part of the operation rather than as implementation trivia. Remove a range with slices.Delete Suppose a pipeline contains stages that are no longer needed:

Cybersecurity 11 Sep 2026 8 min read

Reject Duplicate JSON Keys at Security Boundaries

JSON looks simple enough that teams often treat parsing as a solved problem. A payload arrives, a library turns it into an object, validation runs, and the application uses the result. That model breaks when an object contains the same member name more than once. Different parsers, frameworks, gateways, signature layers, and application components can resolve duplicate names differently. One component may keep the first value, another may keep the last, and another may reject the payload. If a security decision is made using one interpretation and an action is performed using another, the gap becomes a security boundary failure.

Cybersecurity 11 Sep 2026 10 min read

Reject Ambiguous HTTP Request Framing

A reverse proxy and an application server can both accept the same HTTP connection and still disagree about where one request ends and the next begins. That disagreement is more than a parsing bug. On a reused connection, bytes that one component treats as part of a request can be interpreted by another component as the start of a second request. This class of problem is called HTTP request smuggling, or more generally HTTP desynchronization. The practical defensive goal isn’t to recognize every historical attack variation. It is to make request boundaries unambiguous at every hop, reject malformed framing instead of guessing, and test the exact proxy-to-backend path that production traffic uses.

Artificial Intelligence 11 Sep 2026 9 min read

Reduce Vision Transformer Compute with Token Merging

Reduce Vision Transformer Compute with Token Merging Vision transformers can spend substantial computation processing many patch tokens that carry similar information. A patch covering one part of a clear sky may produce a representation close to nearby sky patches, yet ordinary self-attention continues to process each token separately. Token merging reduces that redundancy by combining selected tokens as they move through the network. Unlike token pruning, which removes tokens, merging tries to preserve their information in a smaller set of representations. The practical goal is simple: reduce the token count in later transformer blocks while keeping task quality within an acceptable range.

Cybersecurity 11 Sep 2026 9 min read

Publish a security.txt File for Vulnerability Reports

A security flaw can be reported only if the person who finds it can locate a usable reporting route. When that route is buried in a support portal, points to an abandoned mailbox, or varies across domains, a valid report can be delayed or sent to the wrong place. security.txt gives a web service a standard place to publish vulnerability-reporting contact details. The file is deliberately small. Its value comes from making the route predictable and keeping the route operational.

Artificial Intelligence 11 Sep 2026 11 min read

Prevent VAE Posterior Collapse with Free Bits

Prevent VAE Posterior Collapse with Free Bits A variational autoencoder can appear to train normally while its latent representation becomes nearly useless. The decoder learns to explain the data without depending on the latent variable, the encoder moves toward the prior, and the KL divergence shrinks toward zero. This failure mode is called posterior collapse. Free bits is a small change to the VAE objective that can reduce one source of that collapse. It stops the KL term from rewarding the optimizer for squeezing an already-small amount of latent information even closer to zero. The technique is simple, but its name and common shorthand can lead to a misleading mental model. Free bits does not force a latent variable to contain a chosen amount of information. It changes the optimization pressure below a threshold.

Go 11 Sep 2026 5 min read

Preserve Equal Element Order in Go with slices.SortStableFunc

Sometimes sorting by one field is only half the requirement. You may want jobs grouped by priority while keeping their arrival order inside each priority, or records grouped by category without disturbing an earlier ranking. slices.SortStableFunc is built for that case. It sorts a slice in place using a custom comparator, but elements that compare equal keep their original relative order. Preserve equal elements with slices.SortStableFunc Suppose jobs arrive in this order:

Cybersecurity 11 Sep 2026 9 min read

Plan Certificate Revocation Before a Key Is Compromised

A TLS certificate can still be inside its validity period when you need clients to stop trusting it. The private key may have been exposed, an identity may no longer be valid, or an issuing system may have made a serious mistake. Waiting for the certificate to expire leaves a gap between “we know this credential should no longer be trusted” and “clients stop accepting it.” Certificate revocation is the mechanism for communicating that change before normal expiry. The difficult part is operational: revocation information has to reach the relying parties that make trust decisions, and their behaviour when that information is stale or unavailable may differ.

Cybersecurity 11 Sep 2026 8 min read

Pin JWT Verification to Approved Algorithms

A JSON Web Token can carry identity and authorization claims across service boundaries. Its compact format also carries a header that describes cryptographic processing, including an alg field. That field comes from the token itself. It is attacker-controlled input until verification succeeds. A verifier therefore must not treat alg as permission to select any cryptographic mode a library happens to support. The application must decide which algorithm, key type, issuer, audience, and other verification rules are acceptable. The token may identify a candidate within that fixed policy, but it must not define the policy.

Tech 11 Sep 2026 9 min read

Phone Storage Speed: What It Changes in Everyday Use

A phone with plenty of free storage can still feel slow when opening a large app, installing an update, or moving a big video. Capacity tells you how much data fits on the device. Storage speed describes how quickly that data can be read or written. That distinction matters because phones constantly use internal storage. Apps read code and resources from it, the camera writes photos and video to it, and the operating system uses it for updates, caches, and other files.

Tech 11 Sep 2026 9 min read

Pass-Through Charging in Power Banks: What It Actually Does

A power bank normally has two separate jobs: it charges its own battery from a power source, and later it uses that stored energy to charge another device. Pass-through charging combines those jobs by allowing the power bank to receive power while it is also supplying power to a connected device. That sounds simple, but it doesn’t mean every power bank behaves like an extension lead for USB power. The power bank still has to manage incoming power, its own battery, and the output sent to the other device. Product design and supported charging protocols determine what happens.