Archives de la catégorie Trucs & Astuces

Using LoraTap Curtain controller in HomeAssistant with LocalTuya integration

For a long time, I wanted to replace the regular Tuya integration that allowed my HomeAssistant to control my curtain controllers with the LocalTuya integration, thereby avoiding cloud for controlling local devices. Since, this morning, after a router restart and/or maybe some HomeAssistant upgrade, my controllers escaped the HomeAssistant control, I decided to try with […]

, ,

Pas de commentaire

Recovering a MacBook Pro of 2012 in 2025

I was preparing to give away my old MacBook Pro. I reinstalled the good old HDD of back then and wanted to run the system recovery to provide it as a fresh system (and thereby clearing the HDD content). Device spec This is a MacBook Pro from mid 2012, using an Intel Core i5 CPU. […]

,

Pas de commentaire

Mid-point and linear interpolation done right

How many times did we write code like: Although this code is correct, it may suffer from overflows. The typical way to avoid those is to cast to a wider type. But how can you do this when the start and stop values are already using the largest integer type (eg. int64_t) ? The C++ […]

,

Pas de commentaire

The hidden cost of std::ranges

At work, we have recently adopted some commercial static checker to hunt bugs in our codebase. The tool does not only identify bugs and security vulnerabilities. It is also advising you on opportunities to modernize your code to use the latest and greatest of the C++ language and of its standard library. One of the […]

,

Pas de commentaire

Overflow-safe integer mul&div

When you do a multiply & divide operation, to ensure you don’t loose precision, you would start by the multiplication before the division. But in that case, it could be that the result of the multiplication overflows. The natural solution would go to use an intermediate storage of larger size. This uses concepts (C++20). For […]

, ,

Pas de commentaire

Clamping values with style

The following question was raised in one of our software devs channel at work: On style and readability and intent : std::min or std::clamp or explicit if/reassign. Option 1: int x = someValue;if (x > max) { x = max;} Option 2: int x = std::min(someValue, max); Option 3: int x = std::clamp(someValue, 0, max); […]

Pas de commentaire

Proper handling of temporary objects

Purpose Making a wrapper that keeps reference to some constructor arguments.That’s OK as long as the wrapper lifetime is longer or equal to its construction arguments. If the wrapper is created from temporary objects, it should better be used in the same line _or_ it will make reference to possibly destroyed objects. Example Available on […]

Pas de commentaire

The Hidden Dangers of std::function and lambdas

Once upon a time, there was an active object which had callbacks using std::function.On the same day, a user of this object registered a callback function which, in its core, cancelled the registration. That callback was a lambda that aside of that took some reference in the current context.And guess what happened ? Here is […]

Pas de commentaire

Making patch files

Assume you have a library X, version 1.2.3, extracted in libX-1.2.3/ and that you have to integrate some fix in the build process. You would create a patch file that is applied before building that library. But how do you make the patch files depend on how you apply them. To start, you save the […]

Pas de commentaire

Panic moments: Ubuntu wouldn’t boot properly after upgrade to Xenial

Xenial being released for quite some time now, I decided on a sunny Friday afternoon to do the big jump from Trusty to the latest greatest release. Used to the command line, I launch the "do-release-upgrade" command. 1500+ MB of packets to be downloaded, thousands to be upgraded, some new to be installed and about […]

,

Pas de commentaire