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

标签:#Go

找到 1107 篇相关文章

AI 资讯

Leetcode 31: Next Permutation

Question : Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place and use only constant extra memory. Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column. Example : 1,2,3 → 1,3,2 3,2,1 → 1,2,3 1,1,5 → 1,5,1 Idea : Scan from right to left and find the first element that is less that its previous. eg: 1 6 3 5 -> here it is 3. Let's name it as index. Again scan from right to left and find the first element that is greater than 3 and that's 5. Let's mark it as idx. 3.In this step we swap 3 and 5. Reverse elements from index+1 till the array length. Code: public void nextPermutation(int[] nums) { int index = -1; for(int i=nums.length-1;i>0;i--){ if(nums[i]>nums[i-1]){ index = i-1; break; } } if(index==-1){ reverse(nums,0,nums.length-1); return; } int idx=0; for(int i=nums.length-1;i>=index+1;i--){ if(nums[i]>nums[index]){ idx=i; break; } } swap(nums,index,idx); reverse(nums,index+1,nums.length-1); } void swap(int[] nums,int i,int j){ int temp =nums[i]; nums[i] = nums[j]; nums[j] = temp; } void reverse(int[] nums,int i ,int j){ while(i<j){ swap(nums,i,j); i++; j--; } } Code Explanation : We first initialize index=-1 and traverse backward to find the first one with i that satisfy the condition nums[i]>nums[i-1] . We assign this to index and break out of the loop. for(int i=nums.length-1;i>0;i--){ if(nums[i]>nums[i-1]){ index = i-1; break; } } Next step we are discussing a corner case. For example if the given array is 3,2,1 then we cannot find the element that satisfies the previous condition. So when the array is given in decreasing order we just reverse it and return. if(index==-1){ reverse(nums,0,nums.length-1); return; } Next iteration we are considering another variable idx and traverse backw

2026-08-24 原文 →
产品设计

Construyendo un recomendador de emparejamiento de expertos

La forma del problema Un directorio es una superficie: el miembro lo abre y adivina. Un recomendador es una superficie de empujar: el sistema propone y tiene que justificarse. La justificación es la parte difícil, y es donde vive la estadística. Tres restricciones hicieron esto distinto de un recomendador de contenido: El item es una persona con capacidad finita. Un hilo se le puede recomendar a diez mil personas. Un experto no. Una mala recomendación es cara de los dos lados. Quien pide desperdicia una petición, el experto desperdicia una hora, y los dos aprenden a ignorar la superficie. La afirmación tiene que ser checable. "Quizá te guste este hilo" no necesita evidencia. "Esta persona está un nivel adelante de ti en diseño de sistemas" sí. Recuperación: híbrida, fusionada con RRF Tres recuperadores independientes sobre el conjunto de expertos elegibles, fusionados con Reciprocal Rank Fusion: def rrf_fuse ( * ranked_lists , k = 60 ): """ Fusiona listas de ids rankeadas. El score depende solo del rank, nunca de la escala propia del recuperador, que es el punto: la similitud coseno y un conteo de hilos resueltos no son números comparables. """ fused = {} for lst in ranked_lists : for rank , key in enumerate ( lst ): fused [ key ] = fused . get ( key , 0.0 ) + 1.0 / ( k + rank ) return fused RRF es la primitiva correcta aquí por una razón que vale la pena decir: los recuperadores emiten cantidades incomparables. Uno regresa un coseno en [-1, 1] , uno regresa un conteo entero de hilos resueltos, uno regresa un delta de nivel de escalera. Normalizarlos a una escala común requiere supuestos sobre sus distribuciones que nadie tiene a este volumen de datos. RRF descarta las magnitudes y se queda solo con el orden, que es exactamente la información que sobrevive a una muestra chica. k = 60 es la constante estándar de la formulación original de Cormack et al. Aplana la cabeza: la diferencia entre el rank 1 y el rank 2 es 1/61 - 1/62 ≈ 0.00026 , así que un recuperador no pu

2026-08-24 原文 →
AI 资讯

Why Fixed-Window Rate Limiters Fail (And How to Fix Them with Math)

If you’ve ever built an Express API, you’ve probably reached for standard rate-limiting middleware to protect your login or payment endpoints from DDoS and brute-force attacks. Under the hood, most simple limiters use a Fixed-Window Counter . It’s easy to write: count incoming requests, and once the minute rolls over, reset the counter to zero. However, from a security and algorithmic standpoint, Fixed-Window counters have a massive blind spot. The Boundary Vulnerability (The 2-Second Spike) Imagine your endpoint allows a maximum of 100 requests per minute , resetting every full minute on the clock ( :00 ). Here is how an attacker bypasses that limit without breaking your rules: At 12:00:59 , the attacker fires 100 requests. (Allowed: 100/100 used). At 12:01:00 , the clock resets your counter back to 0. At 12:01:01 , the attacker fires another 100 requests. (Allowed: 100/100 used). To your server code, everything looks fine. But in reality, 200 requests slammed your backend within a 2-second window. In FinTech or authentication systems, that burst is more than enough to overwhelm payment gateways or run a successful credential-stuffing attack. The Algorithmic Fix: Sliding Window Counter To stop boundary spikes, we need a continuously sliding window rather than a rigid clock reset. Attempt 1: The Sliding Window Log (High Memory) You store a timestamps array (a Deque) for every user request and drop timestamps older than 60 seconds. While accurate, storing every single request timestamp takes $O(N)$ space. If your API receives millions of requests, your server memory dies instantly. Attempt 2: Sliding Window Counter (Optimal O(1) Math) Instead of keeping thousands of timestamps, we track only two integers : the request count of the previous window and the count of the current window . When a request arrives, we calculate an estimated request count by weighting the previous window based on how much time has passed in the current window: Estimated Requests = Current Cou

2026-08-23 原文 →
AI 资讯

When Python is Too Slow

Python is a perfect language for Agile development, where requirements might change on the go. Especially if you are in a startup business, you will need to experiment and change things fast. However, Python is an interpreted language, and in certain situations you might need faster performance than what an interpreted language can provide. A common practice in these cases is using python-to-binary bindings, where the binary code is built with Rust, C++, or Go. In this article, I will explore bindings to Rust-based code. How do the bindings work The idea behind bindings is that you create a module with functions of a specific domain in a language that compiles to binary, and build it as a C-compatible dynamic library ( .so on Linux, .dylib on macOS, .dll on Windows). Then a Python wrapper is built as a Python package and installed together with the dynamic library, allowing you to import and use functions that pass control to the corresponding functions in the dynamic library. On some occasions, classes can be used instead of functions. If any parameters are complex, they must be serialized in the wrapper and passed to the dynamic library as a JSON string or as a set of individual primitive parameters. An experiment with benchmarks To try this Python-Rust communication, I vibe coded an experiment that reads a large CSV file and builds a new one with duplicates stripped out based on specified column indexes. In my test case, it was a 3 MB CSV file with data about European NGOs for the donation platform I am building, where I wanted to remove the NGOs that don't have website URLs listed. As benchmarked, the file was processed 4.3x faster with the Rust binding than directly with Python. Here is the repo to get a first glimpse into the code and structure. What is there to know about Rust A few things about Rust: Rust packages are built with Cargo, which is the equivalent of pip, virtualenv, and setuptools combined. A single package is called a crate, and it can be publi

2026-08-23 原文 →
开发者

How to Build a Real-Time Google Docs for Code

What happens when two developers edit the EXACT same line of code at the EXACT same millisecond? Race conditions, overwritten data, and a crashed server. Today, we’re tearing down the magic behind Figma and Google Docs to build a real-time collaborative code editor using Next.js 16 and CRDTs ⏱️ CHAPTER 1: The Collaborative Text Editing Trap "Building a single-user code editor is simple: a React state variable, a text area, and a save button.But the moment two developers open that same code file at the exact same millisecond... everything breaks. User A types a function name at index 5, while User B deletes a line at index 2. If you simply push text updates to a database over HTTP, you get catastrophic race conditions, overwritten code, and cursor teleportation.So, how do platforms like Google Docs, Figma, and Replit allow thousands of users to type simultaneously in real-time without locking files or destroying data? Welcome back to Behind the Abstraction. Today, we’re building a real-time collaborative code editor using Next.js 16. We’ll strip away the magic of real-time state, compare Operational Transformation vs CRDTs, and implement WebSocket edge routing using modern Full-Stack architecture." ⏱️ CHAPTER 2: OT vs CRDTs - The Core Math of Real-Time "Before writing a single line of Next.js code, we must solve a fundamental computer science problem: Mathematical Consistency across Distributed Systems.There are two primary ways to resolve typing conflicts: Operational Transformation (OT): Used by classic Google Docs. Every keypress sends an 'operation' (like Insert "a" at index 10) to a central server. The server acts as the absolute referee, transforming index positions and broadcasting the fix back to all clients. The Problem: Centralized OT servers are complex, memory-heavy, and difficult to scale horizontally at the Edge. CRDTs (Conflict-free Replicated Data Types): Used by modern tools like Figma and VS Code Live Share. Instead of raw array indexes, every chara

2026-08-23 原文 →
AI 资讯

Enterprise vibe coding: the governance framework for shipping AI-generated apps to production

Enterprise vibe coding: the governance framework for shipping AI-generated apps to production Published: August 22, 2026 Category: Enterprise · AI Deployments Reading time: 9 minutes Author: NEXUS AI Team Gartner forecasts that 40% of new enterprise production software will be built using vibe coding techniques by 2028. A 2026 scan of more than 1,400 live vibe-coded applications found that 65% already had a security issue, and 58% shipped with at least one critical vulnerability. Those two numbers describe the same industry moving in opposite directions at once: adoption is outrunning governance. This post covers what a governance framework for enterprise vibe coding actually looks like, the five controls it needs, and where most teams get it wrong. What is enterprise vibe coding? Enterprise vibe coding is the practice of using natural-language prompts to generate application code, then governing that code through mandatory review, access control, and audit before it reaches production, rather than letting it ship straight from a prompt to a live endpoint. The term (coined by Andrej Karpathy in early 2025) originally described a fast, low-friction way for one person to build a prototype. What "enterprise" adds is the governance layer prototyping was never built for: staging environments, encrypted secrets, role-based access, and a record of who approved what. That distinction matters because the adoption curve and the risk curve are not moving together. The governance gap, in three numbers 40% of new enterprise production software will be built using vibe coding techniques by 2028, according to Gartner's May 2025 report "Why Vibe Coding Needs to Be Taken Seriously," as reported by CIO Dive . 65% of vibe-coded production applications had a security issue, in a 2026 scan of more than 1,400 live apps by the API security firm Escape.tech, reported via a Cloud Security Alliance research note . 58% of those same applications shipped with at least one critical vulnerabilit

2026-08-23 原文 →
AI 资讯

Building an Escalation Root-Cause Agent with Gemini and ADK

Gen AI Academy APAC — Track 1 (AI Agents with Gemini, ADK, and Cloud Run) Why I built this I lead a customer service team of 25 agents at Amazon, handling both buyer-side and marketplace seller support. A big part of my job is reviewing escalated cases — calls or chats where a customer asked for a supervisor — and figuring out why they escalated in the first place. Was it a policy gap? A training issue? A system limitation nobody flagged? Right now, that review is manual. Every escalation gets read, tagged, and turned into a coaching note by a human — usually me, or one of my leads. It works, but it doesn't scale well, and patterns across dozens of cases are easy to miss when you're reviewing them one at a time between everything else on your plate. So for Track 1 of the Gen AI Academy APAC program, I built an agent that does the first pass of this analysis automatically: read an escalation summary, classify the root cause against a standard taxonomy, flag whether it looks like a repeat pattern, and draft a coaching note — the same way I would, just faster and more consistently. What it does The agent takes a case summary like this: Customer requested a refund for a damaged item outside the standard return window. Agent denied it citing policy; customer says a rep last month approved a similar exception for someone else. And returns a structured analysis: { "root_cause_category" : "policy_misapplication" , "severity" : "medium" , "is_likely_repeat_pattern" : true , "pattern_reasoning" : "Inconsistent policy application across agents suggests a training or documentation gap rather than an isolated error." , "coaching_note" : "..." } It's built on Google's Agent Development Kit (ADK) with Gemini as the underlying model, and deployed as a live service on Cloud Run . The agent has one tool — a lookup function for the standard root-cause taxonomy — which keeps the categories consistent and easy to update without touching the core prompt. For batch review, I also built a

2026-08-22 原文 →