Random snippets of all sorts of code, mixed with a selection of help and advice.
Async interface, sync-only implementation: Which of `Task.FromResult` or async-over-sync is the lesser evil?
1 April 2026 @ 10:25 am
I have this interface to access files from various providers:
interface IFileProvider
{
Task<bool> FileExistsAsync(string filePath);
...
}
Some of its implementations use network requests supporting asynchronous calls, but one does not: The basic filesystem implementation, using File.Exists().
Performance-wise or deadlock-risk-wise, which is the lesser evil, between just doing the blocking call on the calling thread:
class FileSystemImplementation : IFileProvider
{
Task<bool> FileExistsAsync(string filePath) => Task.FromResult(File.Exists(filePath));
}
or doing async-over-sync?
class FileSystemImplementation : IFileProvider
{
Task<bool> FileExistsAsync(string filePath) => Task.Run(() => File.Exists(filePath));
}
or even
class FileSystemImplementation : IFileProvider
{
async Task<bool> FileExistsAsync(s
Angular unit test - update a signal value for a specific test without affecting others
1 April 2026 @ 10:24 am
I have a signal that's been injected from a service and I want to test a scenario when the value has a specific property set.
Here's how the spec is defined:
describe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
// This is the spy for the service I'm injecting to get the signal from
let myServiceSpy: Spy<MyService>;
const mockSignalValue = {someProperty: ''};
const mockSignalValueWithExtraProperty = {...mockSignalValue, extraProperty: ''};
beforeEach(async () => {
myServiceSpy = createSpyFromClass(MyService);
Object.defineProperty(myServiceSpy, 'mySignal', {
get: () => signal(mockSignalValue),
configurable: true,
});
await TestBed.configureTestingModule({
imports: [MyComponent];
providers: [
{ provide: MyService, useValue: myServiceSpy },
],
}).compileComponents;
fixture = TestBed.createComponent(MyComponent);
Can I create a layer in Keras that de-scales my output?
1 April 2026 @ 10:20 am
I am working on a keras regression network that takes about 60 input variables and outputs 35 variables. For both the input and output, about half of the variables are in the range of +/- 10, while the other half of the variables are around the 100 000s. So there's a large disparity in magnitude, but I want all the inputs/outputs to be treated as equally important. As such, I currently do a max-mean scaling of the both the input and output data, such that each distribution is entered at zero and within a [-1,1] range: $x_i' = \frac{x_i - mean(X)}{max(|X|)}$
This means that I have to save the max and mean values for each of the input and output variables. Then, during testing or prediction, I have to re-load these max and mean values to scale the inputs and then un-scale the predictions that my model gives back.
I'm wondering if there is any way to sort of "bake-in" this scaling such that I don't have to re-load the max and mean values. For example, I saw
Python treemap with first level as color and legend rather than labels
1 April 2026 @ 10:15 am
I would like to try and create treemaps in Python that look similar to these ones :
enter image description here
enter image description here
What I like about those is that the colors allow to easily see the first level and its size, but only the 2nd level squares are represented. I feel it makes for easier reading than what i am currently able to make (see below)
#test data
import pandas as pd
product = ["Pins", "Binders", "Paper",
"Pins", "Binders", "Paper"]
city = ["Amsterdam", "Amsterdam", "Amsterdam",
"Brussels", "Brussels", "Brussels"]
sales = [6, 4, 1, 5, 3, 1]
df = pd.DataFrame(
dict(product=product, city=city, sales=sales)
)
df
product city
IFERROR+INDEX+MATCH Required Strings 5 OR 6 Digits Now
1 April 2026 @ 10:05 am
I have an IFERROR+INDEX+MATCH formula to return a child action number based on the parent action number. The parent can have multiple child actions, but I just need one. They're written as a string in the report as 123451234512345 for a parent with three child actions. We now have actions with 6 digits. Here is the original formula:
=IFERROR(VALUE(RIGHT(INDEX('Source Data'!G:G,(MATCH(B15,'Source Data'!D:D,0))),5)),"")
If the parent is abcde and the child is 12345, the code returns 12345. If the parent has a child as 123456, the code returns 56 (the actual action number for example is 100025, so the zeros get dropped). If I change the 5 to a 6, then it returns the blank, since 512345 doesn't exist. I tried to include OR in the formula, but it only returned TRUE rather than the action number. Not sure what I should do. I need a code to return either a 5-digit or a 6-digit action number that's stored as a string.
Can I Use Swift 5 SDKs in Swift6 Codebase Smoothly?
1 April 2026 @ 10:01 am
I want to migrate to swift 6 from swift 5. My app has multiple SDKs which are using Swift 5. My question is that will it cause any issue in terms of app build or performance?
I have read that Swift 6 more likely provide thread safety for compile time. As I'm in planning phase, it will help me to decide whether should I wait for the migration or not.
Should one (almost) always use English for software implementation and documentation?
1 April 2026 @ 8:52 am
On the Software Engineering SE, a discussion came up regarding whether one should always use English for names and comments in software development.
Some users argue that sometimes, a project that is implemented by a local team and aimed at a local user would not benefit from that. On the contrary, the English used by non-native speakers (like me) is likely imperfect and may lead to unclear or misleading names or comments, actually creating a disadvantage.
From personal experience, I strongly think that using any other language is a relatively serious mistake that will later come to hurt you. One reason is that the world is becoming increasingly globalized. New team members may be from other countries, and the common denominator language is usually English: After all, it is the lingua franca of computer related fields. Another reason is that software lives longer than originally antici
How to distinguish interface names of Hotspot and WiFi?
1 April 2026 @ 8:45 am
I have been working on a 1v1 Android game. In one of the game modes, one phone acts as the server and turns on it's Hotspot, whereas the other phone (the client) connects to the Hotspot of the server via WiFi.
The problem I'm having is that, I don't know the interface name (like wlan0, wlan2, ap0 etc) of the Hotspot and the WiFi (for sure). I can query the names and addresses of all interfaces in my C/C++ code, but that doesn't solve the problem of distinguishing WiFi from Hotspot. Is there anything in the android NDK that could help?
I looked into this matter, but most posts I find either tell that the IP addresses of such interfaces are 192.168.43.x which is absolutely wrong! The interface names also don't follow any proper standards like the one which systemd has. Apart from this, most of the things like netlink sockets and information regarding networking is locked down pretty hard in modern versions on Android (I think 11+?)
From my research so far, Many An
How to calculate MAX/MIN from grouped AVG values in Apache IoTDB Tree Model?
1 April 2026 @ 8:28 am
I am testing Apache IoTDB version 2.0.6 and want to perform some aggregation queries through SQL statements. For example, calculate the average value by grouping, and then get the maximum and minimum values from those averages.
Table Model - Raw Data
CREATE TABLE modbus_tcp_connector ( rcvalue DOUBLE field, device_id STRING tag);
INSERT INTO modbus_tcp_connector(`time`, rcvalue, device_id)
VALUES
('2026-03-18 09:00:05', 23.5, 'device_001'),
('2026-03-18 09:00:12', 24.1, 'device_001'),
('2026-03-18 09:00:18', 23.8, 'device_001'),
('2026-03-18 09:00:25', 24.5, 'device_001'),
('2026-03-18 09:00:35', 23.2, 'device_001'),
('2026-03-18 09:00:42', 24.8, 'device_001');
Table Model - Query Statement
SELECT MAX(avg_val), MIN(avg_val)
FROM (
SELECT date_bin(10s, `time`) AS avg_time, AVG(rcvalue) AS avg_val
FROM modbus_tcp_connector
WH
Why people use "src" variables in make instead of just an "obj"?
31 March 2026 @ 10:34 pm
I always created makefiles like this:
src = file1.c file2.c
obj = $(SRCS:.c=.o)
and never really thought much about it, but now that I want to understand more about make, I do not really see why I use them like that; I could've just created a obj variable and put my .c files with .o:
obj = file1.o file2.o
Is there any reason to have them separated? Is it good practice or more readable?