今日已更新 197 条资讯 | 累计 31025 条内容
关于我们

标签:#p

找到 12847 篇相关文章

AI 资讯

[Advanced Rust] 1.12. Lifetimes (Advanced) Pt.2 - Lifetime Variance, Covariance, Invariance, Contravariance

1.12.1. Lifetime Variance Variance is a concept in Rust’s type system. It describes how generic parameters — especially lifetime parameters — relate to one another in the type hierarchy. We can think of it simply as variance describes which types are “subtypes” of other types , where “subtype” is somewhat similar to the concept used in Java and C#. In addition, variance also cares about when a “subtype” can replace a “supertype” and vice versa . In general, if A is a subtype of B, then A is at least as useful as B. Here is a Rust example: if a function takes &'a str , then &'static str can be passed in. Because 'static is a subtype of 'a , 'static lives at least as long as any 'a (and 'static can remain valid for the entire program). 1.12.2. Three Kinds of Lifetime Variance All types have variance. The variance associated with each type defines which similar types can be used in that type’s position. Note: the following content is fairly difficult. It is recommended that you first recall the ideas of sufficient conditions and necessary conditions from high school math. 1. Covariant Covariant means that a type can be replaced only by a “subtype.” Covariance means: if A <: B (A is a subtype of B), then F<A> <: F<B> (F<A> is also a subtype of F<B>) This is a transitive inheritance relationship from smaller to larger , similar to reasoning from a sufficient condition : if A holds, then B must also hold (A is a sufficient condition for B). For example, &'static T can replace &'a T , because &T is covariant over the lifetime 'a , so 'a can be replaced by one of its subtypes, such as 'static . 2. Invariant Invariant means that you must provide the exact specified type. Invariance means: A <: B cannot imply F<A> <: F<B>, and F<B> <: F<A> also cannot be inferred This means there is not enough relationship between F<A> and F<B> to derive one from the other, so they are neither sufficient conditions nor necessary conditions ; they are independent. For example, the mutable refe

2026-07-28 原文 →
AI 资讯

[Advanced Rust] 1.11. Lifetimes (Advanced) Pt.1 - Review, Borrow Checker, Generic Lifetimes

1.11.1. Review In the beginner tutorial, we mentioned that every reference in Rust has a lifetime. A lifetime is the scope in which the reference remains valid, and in most cases it is implicit and inferred by the compiler. When you take a reference to a variable, the lifetime begins. When the variable is moved or goes out of scope, the lifetime ends. In other words, for a reference, a lifetime is the name of the code region in which it must remain valid. Lifetimes usually overlap with scopes, but not always. 1.11.2. Borrow Checker Whenever a reference with some lifetime 'a is used, the borrow checker checks whether 'a is still alive. The process is: Trace the path back to where 'a began — that is, where the reference was obtained From there, check whether there are conflicts along that path Ensure that the reference points to a value that can be accessed safely This example uses the rand crate. Add the following dependency to Cargo.toml : [dependencies] rand = "0.8" Consider this example: use rand :: random ; fn main () { let mut x = Box :: new ( 42 ); let r = & x ; if random :: < f32 > () > 0.5 { * x = 84 ; } else { println! ( "{}" , r ); } } x is of type Box<i32> Declaring r as a reference to x means the reference’s lifetime begins on that line (line 5) On line 7, the value of x is modified through dereferencing. That requires a mutable reference to x . At this point, the borrow checker looks for a mutable reference to x and checks whether its use conflicts with anything else. In this example there is no conflict, so the code is valid You may ask: line 7 is inside the scope of r . Since *x needs a mutable reference to x , shouldn’t having both the immutable reference r and the mutable reference *x in the same scope violate the borrowing rules and produce an error? In fact, Rust is smart enough to know that if the if branch is taken, the else branch cannot be taken. r is never used in the if branch at all, so using the mutable reference *x in the if branch is fine

2026-07-28 原文 →
AI 资讯

Private avatars in a Node.js SaaS: which object storage, and how to sign downloads

Use a private bucket with short-lived presigned URLs when an avatar belongs to exactly one user, and reach for a public CDN-backed bucket only when the images are genuinely public and you'd rather pay for cache hits than for signatures. For a Node.js SaaS that is the entire decision, and everything after it is plumbing: which S3-compatible provider you point at, how long a signature should live, and what happens to the stored object on the day a user deletes their account. Avatars are small. That removes half the hard problems. The half that's left is the half I get paged for, because an avatar key is written by an untrusted client, read on nearly every page render, cached in three places you don't control, and referenced from a database row that has its own opinion about which object is current. So the questions I ask a storage vendor aren't about upload throughput. They're about whether a partial write can ever be visible to a reader, what the durability number is actually measuring, and how I reconcile the bucket with my user table after a failed deploy. I've never watched a team lose avatar bytes. I've watched several lose track of which bytes were current, which is the same outage with a friendlier root-cause section. How should a Node.js SaaS store private user avatars in object storage? Three moves, in this order. Create one private bucket for the whole tenant base, write each avatar under a key that carries a random component, and mint a presigned GET at display time instead of persisting any URL. Store the key in your database, on the user row, and nothing else, because keys are stable and signatures expire — a URL you saved last Tuesday is a support ticket waiting to happen. Serving the image then costs you one signing call per render, which you can cache in Redis for slightly less than the signature's own lifetime. That random component does more work than it looks like it does. Overwriting a fixed path like users/8821/avatar.png puts you in a read-modify

2026-07-28 原文 →
AI 资讯

Picking a text-to-image API for a SaaS app: REST, pricing, and safety

If you just want the recommendation: call a plain REST image generation endpoint from your Node.js backend, keep the prompt-in / image-out path as dumb as you can stand, and add a chat model on top only when you actually need policy checks or structured prompts. For a first text-to-image feature inside a SaaS app, that is the entire architecture worth building. I've shipped that feature twice. Both times the generation call was the boring part. What ate the calendar was everything around it: deciding whether the output was safe to show a paying customer, reading the licence terms closely enough to know we could put generated art in a customer's exported PDF, storing the result somewhere that wasn't the provider's temporary URL, and — the part I got wrong, which I'll come back to — making retries safe. I run a one-person company, so I optimise for the number of moving parts I have to keep in my head at 2am, and a text-to-image feature that pulls in three new vendors is a feature I'll quietly regret. Your priorities may be different if you have an infra team. What should I look for in a text-to-image API for a SaaS app? Four things, in the order they'll actually hurt you. Model availability in your regions comes first. If you sell into both the US and the EU, check that the model you pick is served in both, because "we support Europe" sometimes means the marketing site and not the inference region. Ask for it in writing if the answer matters to your DPA. Commercial use terms come second, and they're the ones nobody reads until legal asks. Most of the big image models now permit commercial use of outputs, but the details differ on who owns the output, whether you can train on it, and what happens with likenesses and trademarks. Read the actual terms page for the model, not the aggregator's summary of it — aggregators route to several vendors and the upstream licence is what governs your PDF. Then pricing shape. Per-image billing is easy to model in a spreadsheet; per-s

2026-07-28 原文 →
AI 资讯

Why phpMyAdmin migrations break plugin settings — and why `wp search-replace` doesn’t

After a domain migration or HTTPS switch, "all plugin settings are gone" or "Elementor layouts are broken" is a common outcome. The cause, in most cases, is running a string replacement against the WordPress database without accounting for PHP serialized data. WordPress stores plugin configurations, custom field values, and widget settings in PHP’s serialized format. Standard SQL replacements — phpMyAdmin’s find-and-replace, raw UPDATE statements, sed on a .sql dump — rewrite the string value without updating the length metadata that serialization embeds alongside it. The result is a database that appears intact but returns false on every read of the affected values. wp search-replace handles this correctly. Understanding why makes the pre- and post-execution steps more deliberate. What PHP serialization stores alongside the value A serialized entry in WordPress looks like this: a : 2 : { s : 4 : "home" ; s : 22 : "http://example.com/top" ; s : 5 : "title" ; s : 8 : "My Site" ;} The segment s:22:"http://example.com/top" means "a string of 22 bytes." The s:N: prefix records the byte length. When a simple string replacement changes http://example.com to https://example.com : Before: s:22:"http://example.com/top" (22 bytes) After: s:22:"https://example.com/top" (23 bytes) The s:22 stays unchanged even though the actual string is now 23 bytes. PHP’s unserialize() detects this mismatch and returns false . The plugin reads false instead of its configuration array and behaves as though the settings were never saved. phpMyAdmin’s find-and-replace executes a SQL UPDATE at the storage layer. No PHP context exists there — it can’t know the column contains serialized data, and it doesn’t adjust the length prefix. How wp search-replace handles it wp search-replace operates at the PHP layer, not the SQL layer: Reads each column value Checks whether it’s serialized using is_serialized() If serialized: calls unserialize() to expand it into a PHP array or object Applies the string r

2026-07-28 原文 →
AI 资讯

AI-Native Redesign: The Principles Don't Change — Only the Machinery Does

AI assistance disclosure: This article was drafted with the help of Claude. All technical content, design decisions, code references, and screenshots reflect production systems I designed and operate at airCloset; the prose was revised by me prior to publication. Hi, I'm Ryan , CTO at airCloset (a fashion-rental subscription service based in Japan). "Everything changes with AI" is the prevailing mood. My experience building and then running an internal AI platform (cortex) points the other way. The principles don't change at all. Only the machinery does. This post is about what I've come to treat as principle, what I've concluded should be broken, and the thinking behind that split. Disclaimer : "cortex" in this article is the internal codename for the AI platform built in-house at airCloset. It is unrelated to existing commercial services like Snowflake Cortex or Palo Alto Networks Cortex. I've written about the individual pieces before: code-graph , product-graph , db-graph , biz-graph , AI-Observability , the auto-review harness , and Self-Healing . This post isn't about any of them. It's about the design principle sitting behind all of them, one abstraction level up, more essay than build log. The principle, in one sentence: how do we make accurate information accessible? It's an old question. Libraries, legal case books, encyclopedias, search engines — every era has had its own answer using whatever tools that era gave it. Even the technology revolutions people call "paradigm shifts" mostly just changed the means . The underlying question didn't move. Now AI has arrived, and my read (probably not a controversial one) is that its shift is at least on the scale of the internet, possibly larger. As with every previous paradigm shift, the means of answering "how do we make accurate information accessible?" will get redesigned from the ground up. That's what this post is about: AI-Native Redesign — a view where you rebuild the whole design with AI treated as a given

2026-07-28 原文 →
AI 资讯

How FaultBox helped me solve a storage corruption bug I couldn't reproduce

I was testing NodeDB-Lite and PageDB through a real memory-layer application built on top of them. NodeDB-Lite is the embedded form of NodeDB for local-first and in-process workloads, while PageDB is the encrypted page store underneath it. That application was part of the test strategy. I did not want to validate the storage stack only through unit tests, fixtures, and controlled benchmarks. I wanted a real workload to keep using it, stress it, restart it, grow its data, and exercise the boundaries that isolated tests usually miss. Then the store became corrupted. The visible symptom was an authenticated-page read failure around an FTS path. A page that should have passed its AEAD authentication check did not. The application restarted, opened the same damaged store, hit the failure again, and fell into a restart loop. The hard part was not proving that the store was corrupt. The hard part was reproducing how it became corrupt. I could not reproduce it inside PageDB . I could not reproduce it through NodeDB-Lite . I could not even make the application produce it on demand. I could use the application normally for a while and eventually see the failure, but I did not have a deterministic sequence that caused it. By the way, I still found bugs along the way. Some were real. Some looked close enough to the corruption path that I thought I had finally found the root cause. I fixed them, rebuilt, ran the tests, and went back to dogfooding. The corruption still came back. At that point, I stopped asking: Which storage bug looks plausible? The real question was: Where does it actually go wrong? I kept testing the wrong shape of failure My strongest theory was freed-page reuse, or something close to a use-after-free inside the store. It was a reasonable theory. If a page had been released and then reused while another structure still referenced it, a later authenticated read could land on bytes that were valid somewhere else but invalid for the page the reader expected. So

2026-07-28 原文 →
AI 资讯

Agentic Ledger: an open source flight recorder for AI agents (looking for testers and contributors)

I have been building an open source tool called Agentic Ledger and it just reached the point where I need more eyes on it than my own. This post is an introduction and an ask. The problem AI agents run unattended. They call LLMs in loops, use tools, spawn sub-agents, and spend real money, and most of that happens where you cannot see it. When an overnight coding loop burns $40 getting stuck on the same failing test, or a multi-agent crew quietly retries itself into a huge bill, you usually find out from the invoice. The observability tools that exist mostly want you to instrument your code with an SDK, and each one speaks one framework. I wanted the opposite: something that watches everything, requires changing nothing, and keeps the data on my machine. What it is Agentic Ledger is a transparent proxy that sits between your agent and the LLM provider. You point your agent's base_url at it, and it records every request and response, assigns each call an action id, works out what it cost, and passes the response through untouched. Your agent never knows it is there. Your Agent -> Agentic Ledger Proxy -> OpenAI / Anthropic / any gateway | SQLite or Postgres | Live dashboard + API No SDK, no decorators, no monkey patching. It works with any framework and any provider because it operates at the only layer they all share: the HTTP call. Everything is local-first. Your prompts stay in a SQLite file on your machine (or your own Postgres). MIT licensed. Try it in two minutes pip install -U agentic-ledger AGENTICLEDGER_UPSTREAM_URL = https://api.openai.com python -m agenticledger.proxy Or with Docker (multi-arch, non-root, Sigstore-signed): docker run -p 8000:8000 \ -e AGENTICLEDGER_UPSTREAM_URL = https://api.openai.com \ -v $( pwd ) /data:/data \ ghcr.io/shekharbhardwaj/agentic-ledger:latest Then point your agent at it: client = OpenAI ( base_url = " http://localhost:8000/v1 " , default_headers = { " x-agenticledger-session-id " : " run-1 " }, ) For coding agents like Claude

2026-07-28 原文 →
AI 资讯

Razer’s analog Huntsman V3 Pro is over 20 percent off

Gaming keyboards have evolved over the years to add RGB LEDs, extra knobs, and buttons with screens, but one feature has remained fairly consistent: the mechanical switch. That’s slowly changing, with brands introducing adjustable optical switches that are more customizable and have a faster response time. Razer’s Huntsman V3 Pro TKL is a compact, wired […]

2026-07-28 原文 →
AI 资讯

The Test Framework Is Not the Product

A few years ago, the hardest part of building a browser test framework was getting started. You had to choose a runner, configure browsers, create page objects, wire up reporting, add retries, manage secrets, connect it to CI, and convince someone else on the team to learn how the whole thing worked. Today, you can open an AI assistant and ask it to generate most of that before lunch. That sounds like a dramatic improvement. In some ways, it is. But it also moves the bottleneck. The question is no longer, “Can we create a framework?” The question is, “Can we operate what was created?” That distinction matters more than it appears. Generation cost is not ownership cost A generated framework feels cheap because the first version arrives quickly. The code compiles, a few tests pass, and the pull request looks more complete than anything you could have written in an afternoon. Then reality starts applying pressure. The application changes. Authentication behaves differently in staging. A shared helper starts hiding failures. Parallel workers collide over test data. Someone upgrades a dependency and three reporters stop agreeing with one another. The initial generation was fast. The ownership cost was merely deferred. This is the central problem described in what actually breaks when Claude generates a large Playwright framework . Large generated systems often fail in the seams: fixtures, abstractions, environment assumptions, test data, and conventions that were never explicitly agreed upon. The code may be readable line by line while the system remains difficult to reason about as a whole. That is a dangerous form of complexity because it looks productive. More code can hide less understanding Teams sometimes evaluate AI-generated automation by counting output: number of test files; number of scenarios; number of passing checks; number of prompts completed; number of lines added. Those numbers are easy to produce and easy to report. They are also weak proxies for confi

2026-07-28 原文 →
AI 资讯

AI Coding Agents Don't Understand APIs. They Memorize Them.

We've all had the same experience. You ask your coding agent to integrate with a new platform. It confidently writes code. It references endpoints that don't exist anymore. It misses required headers. It mixes API versions. It hallucinates authentication flows. None of this is surprising. Large language models don't "know" an API. They know about an API from their training data. Even when you hand them documentation, they're still trying to reconstruct a mental model from hundreds or thousands of pages of text. The problem isn't writing code. It's building context. Understanding an API is still mostly manual Every integration starts the same way. Read the authentication docs. Figure out the important entities. Learn the object relationships. Understand the common workflows. Find the endpoints that matter. Jump between documentation tabs for an hour. Only then do you actually start building. Ironically, AI made writing code dramatically faster while leaving this entire process mostly unchanged. Documentation wasn't designed for AI Most documentation is optimized for humans. OpenAPI specifications are optimized for machines. Neither tells the complete story on its own. The spec explains what exists. The documentation explains why it exists. Neither builds a coherent mental model. I wanted a better starting point That's why I built Scout. Scout takes an OpenAPI specification and the accompanying documentation, then synthesizes them into a grounded understanding of the platform. Instead of asking: "Can Claude figure this out?" The workflow becomes: import the API crawl the documentation build an understanding ask questions against grounded context generate integration code expose the same understanding to coding agents through MCP Everything runs locally. No hosted backend. No accounts. No telemetry. The interesting part isn't the AI The AI chat isn't the product. The generated code isn't the product. The MCP server isn't even the product. The product is the context tho

2026-07-28 原文 →
AI 资讯

One OpenAI-Compatible Endpoint for Multiple LLM Providers: A Practical Setup Guide

When an application starts using more than one language model provider, the hard part is rarely the first API call. The hard part is everything that follows: separate credentials, different request shapes, provider-specific errors, billing dashboards, and model migrations scattered across the codebase. A useful way to reduce that surface area is to keep one OpenAI-compatible client contract and move provider choice into configuration. This guide shows the smallest working setup with Routara , plus the production checks I recommend before sending real traffic. 1. Keep the SDK, change the endpoint If your project already uses the OpenAI Python SDK, the client initialization is the only part that needs to change: import os from openai import OpenAI client = OpenAI ( api_key = os . environ [ " ROUTARA_API_KEY " ], base_url = " https://api.routara.ai/v1 " , ) response = client . chat . completions . create ( model = " deepseek-chat " , messages = [ { " role " : " user " , " content " : " Explain idempotency in two sentences. " } ], ) print ( response . choices [ 0 ]. message . content ) Store the key in an environment variable. Do not put it in browser code, a public repository, screenshots, or support messages. The same pattern works in Node.js: import OpenAI from " openai " ; const client = new OpenAI ({ apiKey : process . env . ROUTARA_API_KEY , baseURL : " https://api.routara.ai/v1 " , }); const result = await client . chat . completions . create ({ model : " deepseek-chat " , messages : [{ role : " user " , content : " Return one short test sentence. " }], }); console . log ( result . choices [ 0 ]. message . content ); 2. Treat model IDs as configuration Do not spread model names throughout the application. Put them in environment variables or a typed configuration object: model_id = os . environ . get ( " ROUTARA_MODEL " , " deepseek-chat " ) That makes model evaluation and rollback much safer. Routara's live model catalog is the source of truth for current availa

2026-07-28 原文 →