/**
* @param {number} numberOfUsers
* @param {string[][]} events
* @return {number[]}
*/
var countMentions = function(numberOfUsers, events) {
// Result: mentions per user
const mentions = new Array(numberOfUsers).fill(0);
// Online state and offline-until times
const online = new Array(numberOfUsers).fill(true);
const offlineUntil = new Array(numberOfUsers).fill(-1);
// Normalize and sort:
// - ensure timestamps are numbers
// - sort by timestamp ascending
### Caching using Redis (Summit)
#### Model Caching
```ruby
# controller
prod.get_cached_images
# product model
private
def get_cached_images
Rails.cache.fetch(['Product', 'images', id]) do
images.to_a
end
end
```
- `Rails.cache.fetch` is used to initiate the cache key and look for it in the
databse
- To expire the cache, when the model updates:
```ruby
# use a callback in the model
after_commit :flush_cache
private
def flush_cache
ExpireModelCacheJob...
# using rake task to expi.list {
list-style-type: none;
}
.list li::marker {
content: "";
}
# ------------------------------------------------------------
# Automatischer Paketimport & -Installation
# ------------------------------------------------------------
import sys
import subprocess
import importlib
import importlib.util
def ensure_package(pkg_name, import_name=None):
"""
Stellt sicher, dass ein Paket installiert und importierbar ist.
Falls nicht installiert, wird es automatisch via pip installiert.
"""
name_to_check = import_name or pkg_name
<div>
<style>
dialog::backdrop {
background: rgba(0, 0, 0, 0.6);
}
dialog {
border: none;
border-radius: 8px;
padding: 20px 30px;
max-width: 600px;
width: 90%;
text-align: center;
color: #000;
animation: fadeIn 0.2s ease-out;
background-color: #bc4749;
}
dialog h3{
color: white !important;
text-shadow: none !important;
}
dialog p {
color: wh# multi thread
Python 解释器会在以下情况释放 GIL:
1. **字节码计数器达到阈值**(默认每 100 条字节码)
2. I/O 操作(文件、网络、sleep 等)
3. 某些内置函数调用
4. 显式的 GIL 释放(如 C 扩展)
线程切换并不以方法为边界,方法中间也可能被切换。所以 GIL 并不能保证线程安全,需要以操作是否是原子来判断是否安全。
```python
# 原子操作:
x = 123 # 简单赋值
x = y # 变量赋值
L.append(x) # list.append
L1.extend(L2) # list.extend
x = L.pop() # list.pop
d[key] = value # dict 赋值
# 非原子操作:
x += 1 # 需要锁
x = x + 1 /**
* @param {number} n
* @param {number[][]} buildings
* @return {number}
*/
var countCoveredBuildings = function(n, buildings) {
// Guard: empty list -> no covered buildings
if (!buildings || buildings.length === 0) return 0;
// Step 1: Precompute extremes per row (y) and column (x).
// minX[y], maxX[y]: smallest and largest x in row y
// minY[x], maxY[x]: smallest and largest y in column x
const minX = new Map();
const maxX = new Map();
const minY = new Maadd_action('user_register', function($user_id) {
$user = get_userdata($user_id);
if (in_array('administrator', $user->roles, true)) {
require_once ABSPATH . 'wp-admin/includes/user.php';
wp_delete_user($user_id);
wp_die('Admin account creation is disabled.');
}
});/**
* @param {number[]} complexity
* @return {number}
*/
var countPermutations = function(complexity) {
const n = complexity.length;
const MOD = 1_000_000_007; // Large prime modulus for preventing overflow
// Check validity: all elements after the first must be strictly greater
for (let i = 1; i < n; i++) {
if (complexity[i] <= complexity[0]) {
return 0; // Invalid case
}
}
// Compute factorial of (n-1) modulo MOD
let result = 1;
- Download a stable release of the openwrt-x86-64-combined-ext4.img.gz image from targets/x86/64/ folder e.g. [https://archive.openwrt.org/releases/24.10.4/targets/x86/64/openwrt-24.10.4-x86-64-generic-ext4-combined.img.gz]()
- Uncompress the gziped img file. On Linux use the command `gzip -d openwrt-*.img.gz`. As a result you should get the raw `openwrt-x86-64-combined-ext4.img` image file.
- Convert it to native VBox format: `VBoxManage convertfromraw --format VDI openwrt-*.img openwrt.vdi`. T### Create TanStack Start Project with shadcn/ui
Source: https://ui.shadcn.com/docs/installation/tanstack
Initialize a new TanStack Start project with Tailwind CSS and shadcn/ui add-ons pre-configured. This command sets up the project structure and installs necessary dependencies in one command.
```bash
npm create @tanstack/start@latest --tailwind --add-ons shadcn
```
--------------------------------
### Install All shadcn/ui Components
Source: https://ui.shadcn.com/docs/installation/tanst<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<title>Nutrition Menu Demo</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: flex-start;
padding: 40px 16px;
background: #fff7fb;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
sans-serif;
}
.nutrition-card {
widef generate_forecast_features(start_date: str, end_date: str) -> pd.DataFrame:
"""
Generate a feature-engineered datetime DataFrame for model prediction.
Parameters
----------
start_date : str
Start date in 'YYYY-MM-DD' format.
end_date : str
End date in 'YYYY-MM-DD' format.
Returns
-------
pd.DataFrame
DataFrame indexed by datetime with all required time & cyclic features.
"""
# Convert input date/**
* @param {number[]} nums
* @return {number}
*/
var specialTriplets = function(nums) {
const MOD = 1e9 + 7; // modulus to avoid overflow
const n = nums.length;
// Frequency maps
let leftCount = new Map(); // counts of numbers before j
let rightCount = new Map(); // counts of numbers after j
// Initialize rightCount with all numbers
for (let num of nums) {
rightCount.set(num, (rightCount.get(num) || 0) + 1);
}
let result = 0;
from typing import Optional
from core.agents.architect import Architect
from core.agents.base import BaseAgent
from core.agents.bug_hunter import BugHunter
from core.agents.code_monkey import CodeMonkey
from core.agents.code_reviewer import CodeReviewer
from core.agents.developer import Developer
from core.agents.error_handler import ErrorHandler
from core.agents.executor import Executor
from core.agents.external_docs import ExternalDocumentation
from core.agents.human_input import HumanInput
fIssue:
> We are seeing incorrect refund amounts on imported historical orders that include discounts. Because discount amount is distributed between all items, refunding a full-price item can cause part of the original discount to be removed. A common scenario is an order containing a full-price item and a gift item discounted by 100%. When the full-price item is refunded, the system recalculates the discount distribution and the refund/discount amounts become inaccurate.
Reason:
> Shopify will