How to Exclude Your Windows App from Screen Capture and Recall

 
 
  • Gérald Barré
Some applications are displaying sensitive information. With Recall, Windows can take a screenshot of your screen regularly and store sensitive information. You can exclude your application from this feature, and screen capture more generally, by using SetWindowDisplayAffinity and the WDA_EXCLUDEFROMCAPTURE flag. This is a Windows API function that allows you to set the display affinity of a window, which… [read more]

Automatically Rerun Failed GitHub Actions Workflows

 
 
  • Gérald Barré
GitHub Actions doesn't provide a built-in way to rerun a run automatically. If you have some flakiness in your jobs, this can be a pain as you have to rerun the workflow manually. Hopefully, you can use the workflow_run event to trigger a new workflow when a previous one fails. This allows you to rerun the failed workflow automatically. Note that the following sample workflow will only rerun the failed… [read more]

How to Merge Two Git Repositories While Preserving History

 
 
  • Gérald Barré
Merging two Git repositories can be useful in scenarios where you want to consolidate related projects into a single repository for easier management, collaboration, and version control. This approach is particularly helpful when two repositories share a common purpose or are tightly coupled, as it simplifies dependency management and ensures all related code resides in one place. Additionally, it can… [read more]

Automating Null-Forgiving Operator Removal in C# Projects

 
 
  • Gérald Barré
Nullable Reference Types are a feature in C# that helps developers avoid null reference exceptions by providing compile-time checks for nullability. This feature was introduced in C# 8.0 and is designed to improve code quality and reduce runtime errors. When the compiler cannot handle all cases, so developers may need to use the null-forgiving operator ! to suppress warnings. This operator tells the… [read more]

Using Pattern Matching in C# for Performance Optimization

 
 
  • Gérald Barré
The C# compiler is smart enough to understand some constructs and generates optimized code. However, C# gives you multiple ways to express the same intent. The compiler is not always smart enough to optimize every single ways. In this post, I will show you how to use pattern matching syntax to improve the performance of your code in some cases. Here's an example that checks if a version number is one of… [read more]

Resize Ubuntu Partitions in Hyper-V to Use Full Disk

 
 
  • Gérald Barré
When creating a new virtual machine in Hyper-V with Ubuntu Server with all the default settings, the partition will have 60GB of space instead of 127GB (default size of the virtual hard disk). Maybe there is a setting somewhere that I missed during the setup, but I couldn't find it. The solution is to resize the partition after the installation. This can be done with the following commands: First, check… [read more]

Use C# 14 extensions to simplify enum Parsing

 
 
  • Gérald Barré
In .NET, many types provide a static Parse method to convert strings into their respective types. For example: int.Parse("123"); double.Parse("123.45"); DateTime.Parse("2023-01-01"); IPAddress.Parse("192.168.0.1"); However, enums require the use of the Enum.Parse method: Enum.Parse<MyEnum>("Value1"); // MyEnum.Parse("Value1"); // This doesn't work Wouldn't it be more intuitive if enums supported a Parse… [read more]

StringComparison.InvariantCulture is not always invariant

 
 
  • Gérald Barré
CultureInfo.InvariantCulture is not invariant for all operations. It is a special culture that is used for formatting and parsing operations that do not depend on any specific culture. For instance, this is well-suited to format values in order to persist them. However, it is not invariant for string comparisons. Comparing strings using InvariantCulture can lead to different results depending on the… [read more]

Remove empty folders using PowerShell

 
 
  • Gérald Barré
Here's a PowerShell script that removes empty folders recursively: $rootFolder = 'C:\Temp' Get-ChildItem $rootFolder -Recurse -Directory -Force | Sort-Object -Property FullName -Descending | Where-Object { $($_ | Get-ChildItem -Force | Select-Object -First 1).Count -eq 0 } | Remove-Item The logic is following: Get all directories recursively, use -Force to get hidden folders Sort them in descending order… [read more]