Skip to content

Instantly share code, notes, and snippets.

View Nirmal4G's full-sized avatar
🆖
Something BIG is brewing!

Nirmal Guru Nirmal4G

🆖
Something BIG is brewing!
View GitHub Profile
@vhanla
vhanla / wsaclientdetails.md
Last active July 10, 2024 21:57
Windows Subsystem for Android - WSA Client interesting params and stuff

WSA Client (wsaclient.exe) is the manager UI application for Windows 11's Windows Subsystem for Android platform and here I collect interesting stuff that I found in wsaclient.exe

  1. One instance application.

wsaclient.exe is the only application that runs, and handles params for different actions, like uninstall, launch APKs, restart, etc.

To check and block other instances, it uses MUTEX strings and it is this one (it might change in future versions)

Mutex = CreateMutexExW(0, L"{42CEB0DF-325A-4FBE-BBB6-C259A6C3F0BB}", 0, 0x1F0001u);

Building a universal Windows 7/Windows 10 .NET EXE

The problem with building a .NET (classic) executable that runs on both clean Windows 7 install and on Windows 10 is that Windows 7 only ships with .NET 3.5 inbox and Windows 10 ships with .NET 4.X. A .NET 3.5 executable will not run on a (clean install) Windows 10 directly. It can be coerced to do so in multiple ways, but none of them are "worry-free single file" solutions (config file, registry settings, environment variables, etc.).

One of the solutions is to set COMPLUS_OnlyUseLatestCLR environment variable to 1 before the process starts. This will allow .NET 4.X to take over execution of the program. This still doesn't qualify as "worry-free" because we need a batch file or something else to set the envionment for us before the process start (it's too late once Main is executing).

One weird trick to run the same executable on both Windows 7 and Windows 10

When I said we need to set COMPLUS_OnlyUseLatestCLR environment variable to 1 bef

Create Windows Terminal shortcut in Windows + X context menu

Windows Terminal shortcut in WinX context menu

In Windows PowerShell do the following:

$folderPath = "$ENV:LOCALAPPDATA\Microsoft\Windows\WinX\Group3"
$adminFilePath = Join-Path $folderPath "00 - Windows Terminal.lnk"
$normalFilePath = Join-Path $folderPath "00a - Windows Terminal.lnk"
@optimizedaway
optimizedaway / div128.h
Last active May 6, 2020 10:24
128 by 64 bit integer division for gcc and clang
#include <stdint.h>
// 128 by 64 bit integer division for gcc and clang
inline uint64_t udiv128_64(unsigned __int128 a, uint64_t b)
{
// We don't want 128 bit software division
uint64_t alo = (uint64_t)a;
uint64_t ahi = (a >> 64);
uint64_t d, e;
__asm__("divq %[b]"
@buybackoff
buybackoff / Benchmark.md
Last active April 22, 2024 06:49
Avx2/branch-optimized binary search in .NET

Binary search is theoretically optimal, but it's possible to speed it up substantially using AVX2 and branchless code even in .NET Core.

Memory access is the limiting factor for binary search. When we access each element for comparison a cache line is loaded, so we could load a 32-byte vector almost free, check if it contains the target value, and if not - reduce the search space by 32/sizeof(T) elements instead of 1 element. This gives quite good performance improvement (code in BinarySearch1.cs and results in the table 1 below).

However, for larger N the search space reduction is quite minimal and the most gains come from switching to linear search. After an interesting discussion in Twitter (especially with @trav_downs), and trying to widen the pivot area to use 2 AVX2 vectors it became clear that just switching to linear search sooner is more important than using AVX2 vectors as pivots.

The linear search was not using AVX2, and for linear

{
"defaultProfile": "{79285a8e-036c-446f-8a9c-78994e34bf85}",
"initialRows": 30,
"initialCols": 120,
"alwaysShowTabs": true,
"showTerminalTitleInTitlebar": true,
"showTabsInTitlebar": true,
"requestedTheme": "dark",
"profiles": [
{
@bohops
bohops / poc.png
Created May 22, 2019 19:17
MSBuild - Property functions -
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<Target Name="Hello" >
<!-- Call ANY .NET API -->
<!--
Author: Casey Smith, Twitter: @subTee
License: BSD 3-Clause
@dotMorten
dotMorten / MSBuildCheatSheet.xml
Created January 14, 2019 23:19
MSBuild Cheat Sheet
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
How to define a variable.
Just stick a new node in a property group.
-->
<PropertyGroup>
<!-- This node in a property group will define a variable -->
<TestVariable>Test Variable Value</TestVariable>
@jeffkl
jeffkl / Improvements to MSBuild 15.md
Last active November 17, 2022 23:45
Improvements to MSBuild 15

Improvements to MSBuild 15

In MSBuild 15, we've been hard at work adding features that make it easier to manage your build. The development world has evolved greatly in the last 10 years with NuGet packages, more platforms, and the internet in general. We wanted to modernize some of MSBuild to propel it forward to a new era.

Open Source

MSBuild 15 is open source for the first time. This has allowed us to work in the open in a tighter loop with our customers. It also has allowed community contribution so that features of MSBuild can be provided that the core MSBuild development team does not have time to implement.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>