Skip to content

Instantly share code, notes, and snippets.

@usausa
usausa / ClusterColors.cs
Created July 2, 2025 09:13
Bitmap color clustering by ML.NET
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.Trainers;
using SkiaSharp;
public record ColorCount(
byte R,
byte G,
byte B,
@usausa
usausa / CognitiveService.cs
Last active June 24, 2025 13:43
Using Custom Vision model on MAUI
using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using SkiaSharp;
public record DetectResult(
float Left,
float Top,
float Right,
float Bottom,
public static class IncrementalGeneratorInitializationContextExtensions
{
public static IncrementalValuesProvider<T> ForAttributeWithMetadataNameWithOptions<T>(
this IncrementalGeneratorInitializationContext context,
string fullyQualifiedMetadataName,
Func<SyntaxNode, CancellationToken, bool> predicate,
Func<GeneratorAttributeSyntaxContext, AnalyzerConfigOptions, CancellationToken, T> transform)
{
var syntaxContext = context.SyntaxProvider.ForAttributeWithMetadataName(
fullyQualifiedMetadataName,
using Microsoft.Extensions.DependencyInjection;
public sealed class KeyedServiceProxy<T>
where T : notnull
{
private readonly IServiceProvider serviceProvider;
public KeyedServiceProxy(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
@usausa
usausa / Program.cs
Last active February 4, 2024 09:33
Command line server
Directory.SetCurrentDirectory(AppContext.BaseDirectory);
var host = Host.CreateDefaultBuilder(args)
.UseWindowsService()
.UseSystemd()
.ConfigureLogging(config =>
{
config.ClearProviders();
})
.ConfigureServices((context, services) =>
@usausa
usausa / CallBenchmark.cs
Last active December 22, 2023 12:23
CallBenchmark
namespace CallBenchmark;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
@usausa
usausa / TcpServer.cs
Created October 1, 2023 12:04
TCP server using Microsoft.AspNetCore.Connections
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseKestrel(options =>
{
options.ListenLocalhost(9999, config =>
{
config.UseConnectionHandler<MyConnectionHandler>();
});
});
var app = builder.Build();
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
public static class HexEncoder
{
private static ReadOnlySpan<byte> HexTable => new[]
{
(byte)'0', (byte)'1', (byte)'2', (byte)'3',
(byte)'4', (byte)'5', (byte)'6', (byte)'7',
(byte)'8', (byte)'9', (byte)'A', (byte)'B',
(byte)'C', (byte)'D', (byte)'E', (byte)'F'
};

interface

7FF81390136B mov       rcx,[rsi+8]
7FF81390136F mov       r11,7FF8135903A8
7FF813901379 call      qword ptr [7FF8135903A8]

abstract