Skip to content

Instantly share code, notes, and snippets.

View xiaomi7732's full-sized avatar

Saar Shen xiaomi7732

View GitHub Profile
@xiaomi7732
xiaomi7732 / PolymorphicSerialization.md
Last active January 6, 2023 22:58
How do I leverage .NET 7 Polymorphic Serialization when building Roshambo API

How did I leverage .NET 7 Polymorphic Serialization when building Roshambo API

Brief about the Roshambo project

It is a simple rock, paper, and scissors game used to study how to build a full RESTful API. You will be able to find the latest code in this repo. BTW, if you like it, give it a star.

To make it fun, I also released a live client at https://roshambo.codewithsaar.com.

The feature I want to build

@xiaomi7732
xiaomi7732 / GitHubWebHooks.Security.md
Last active March 23, 2026 23:13
Verify SHA256 signature by GitHub WebHooks in ASP.NET Core WebAPI

Verify SHA256 signature by GitHub WebHooks in ASP.NET Core WebAPI

Description

Sharing a secrect with GitHub, it is important to verify the signaure hashed by it. You don't want your API being called by malicious 3rd parties.

Here's how you do it in ASP.NET Core WebAPI.

Code

@xiaomi7732
xiaomi7732 / threadpoolsettings.md
Last active December 30, 2022 01:19
Customize thread pool defaults, avoid the caveats

Customize thread pool defaults, avoid the caveats

.NET runtime allows customize default thread pool settings. There are essentially 4 values that could be customized:

  • Minimum worker thread count;
  • Minimum IO thread count;
  • Maximum worker thread count;
  • Maximum IO thread count;

And there are 4 primary APIs, 2 to read min/max, 2 to set those values:

@xiaomi7732
xiaomi7732 / OptionalServiceInDotnetDI.md
Last active October 25, 2022 03:41
Make an optional service in .NET DI

Make an optional service in .NET DI Container

Services in DI container is by default required. To make it optional, give it a defualt value.

Assuming ConsumerService rely on AnotherService while AnotherService is not registered in DI container.

Solution

Having a default value for the optional service.

@xiaomi7732
xiaomi7732 / KubeCtlCustomNamespace.md
Last active October 25, 2022 03:40
Set default namespace for kubectl

Set default namespace for kubectl

kubectl config set-context --current --namespace=<insert-namespace-name-here>
# Validate it
kubectl config view --minify | grep namespace:
@xiaomi7732
xiaomi7732 / GoogleOffGoogleOn.md
Last active October 9, 2022 15:46
SEO: Skip tags for search engine
@xiaomi7732
xiaomi7732 / DoNotAutoLoadBlaozrWASM.md
Created October 9, 2022 15:30
Stop auto loading Blazor pages
<body>
    ...

    <script src="_framework/blazor.{webassembly|server}.js" autostart="false"></script>
    <script>
      document.addEventListener("DOMContentLoaded", function() {
        Blazor.start();
      });
 
@xiaomi7732
xiaomi7732 / Get.NETCoreNativeSymbols.md
Created September 28, 2022 22:41
Get .NET Core Native Symbols
@xiaomi7732
xiaomi7732 / FindPort.md
Last active September 28, 2022 18:05
How to find out which port is taken by which process on Windows

Known port

netstat -ano | findstr <port>

List all active port

netstat -ano
@xiaomi7732
xiaomi7732 / HttpFactoryInBlazorWASM.md
Last active September 25, 2024 09:43
Use HttpFactory for multiple HttpClients in Blazor WASM

Use HttpFactory for multiple HttpClients in Blazor WASM

Description

HttpClient Factory pattern allows multiple named http client for various backend. This is a note about how to use it in Blazor WASM (.NET 6).

Short version: Same as in a Web API.

Details