on-internet

Finding the index of the closest element to a target in a sorted array using binary search in Java

I am trying to find the index of the element in a sorted integer array (nums) that is closest to a given target value. If there's a tie in difference, I want to handle it correctly. Here is the binary search approach I wrote: public class Solution { public static int binarySearchClosest(int[] nums, int left, int right, int target) { if (target <= nums[left]) return left; if (target >= nums[right]) return right; int low = left, high = right; int closestIndex = left; while (low <= high) { int mid = low + (high - low) / 2; if (nums[mid] == target) { return mid; } if (Math.abs(nums[mid] - target)

Join the discussion →

Overwhelmed routers from 2001 grounded all US flights on Friday as FAA’s decades-old server infrastructure buckled under network traffic — creaking air traffic communication system became overloaded…

submitted by eicker to technology 2 points | 1 comments https://www.tomshardware.com/networking/two-hpe-juniper-network-routers-grounded-all-the-us-flights-on-friday-faas-decades-old-copper-network-buckled-under-a-feature-hpe-says-worked-as-intended-creaking-air-traffic-communication-system-became-overloaded-by-very-high-rate-pinging

Join the discussion →

Mini, spoiler free review of *The Raven Scholar*, by Antonina Hodgson

submitted by AFKBRBChocolate to books 1 points | 0 comments cross-posted from: lemmy.ca/post/73960044 The empire of Orrun is protected by eight mythological guardians: fox, raven, tiger, ox, bear, monkey, hound and dragon. Each has its own temple and society/guild, with attributes and traditions based on the guardian. Neema is an archivist with the ravens, who prize knowledge and understanding above all things. She is gifted, but shunned by many because of her poor origins. Because of her exceptional calligraphy, she is asked by the emperor to produce a proclamation that will change her life,

Join the discussion →

Dynamic equivalent to the import statement in Python 3.15+

importlib.import_module() (and the discouraged builltins.__import__() / importlib.__import__) allow dynamically importing a module. However, it has one important difference from the import statement: it doesn't respect lazy filters (a feature in Python 3.15+). For example, let's make all imports lazy: import sys make_normal_imports_also_lazy = lambda importing, imported, fromlist: True sys.set_lazy_imports('all') sys.set_lazy_imports_filter(make_normal_imports_also_lazy) Now if I use the import stmt, I get a lazy import: import json print(type(globals()['json'])) # <class 'lazy_import'> But if

Join the discussion →

Just 400 US Data Centers Use More Electricity Than Michigan

An anonymous reader quotes a report from Wired: Just 400 hyperscale data centers connected in the US used as much electricity as the state of Michigan in a single year, new Harvard research has found. The study, published Monday in Nature Sustainability, also finds that the majority of that electricity was generated using fossil fuels, and data center emissions are three times higher than they were before the AI boom. Federal and state governments do not track data center use separate from the rest of the power sector, despite mounting projections that data centers are putting serious strain o

Join the discussion →

How can I build a dynamic WHERE clause efficiently?

I need to build a WHERE clause dynamically based on the filters a user selects, such as a date range, a list of stock symbols, or a price range. I’m using DolphinDB’s sql function to construct and evaluate the query. t = table( take(2025.01.01..2025.01.05, 100) as date, take(`A`B`C`D`E, 100) as sym, rand(100.0, 100) as price ) // Filter expressions dateFilter = expr(parseExpr("date >= 2025.01.03")) symFilter = expr(parseExpr("sym in `A`B`C")) // Construct and evaluate the query dynamicSQL = sql(select=t, where=<[date >= 2025.01.03, sym in `A`B`C]>) result = dynamicSQL.eval() In my tests, this

Join the discussion →

Apple Metal C++ Bindings Memory Leak in Hello World Program

I am trying to write an Apple Metal application in C++ using the metal-cpp binding. However, in a simple hello, world program I get a memory leak from simply importing the libraries. I followed the setup on Apple's official "Get started with Metal-cpp". #define NS_PRIVATE_IMPLEMENTATION #define CA_PRIVATE_IMPLEMENTATION #define MTL_PRIVATE_IMPLEMENTATION #include <Foundation/Foundation.hpp> #include <Metal/Metal.hpp> #include <QuartzCore/QuartzCore.hpp> #include <iostream> int main(int argc, const char * argv[]) { // insert code here... std::cout << "Checking for metal-cpp memory leaks..." <<

Join the discussion →

Configure PLOTLY within Jupyterlab Notebook

I am running Linux MINT v22.3 and, as far as I know, the installed software is the latest offered by the Linux-Mint Synaptic Package Manager. I am just getting started with Jupyterlab (v. 3.6.2-1 Desktop / v 6.4.12-2.2Notebook). My platform's hard-drive has Python3 and the Plotly extensions installed. Again, these are the latest from the Linux-Mint Synaptic Package Manager. Here I must note that latest Jupyterlab Desktop offering is at version 4.6.3-1, and JPL Notebook is now at v7. When I try to run any Plotly demonstration code from the Plotly website (see Plotly heatmap example ) import pan

Join the discussion →

Nayax Spark Remote Start: can Settlement be lower than the pre-authorised amount, and how long can an authorisation stay open?

I'm building a backend for unattended beverage machines in the UAE. A Nayax terminal is fitted to each machine, and the backend uses the Spark server-to-server API in the Remote Start pre-authorisation flow: StartAuthentication → StartAuthenticationResponse TriggerTransaction → TriggerTransactionResponse Customer taps their card on the terminal Nayax sends TransactionCallback, and we reply with TransactionCallbackACK (HTTP 200) The machine makes the drink We send Settlement if the drink was made, or CancelTransaction if it failed A customer can order up to 4 drinks in one transaction, and the

Join the discussion →
Older stories