Skip to content

Instantly share code, notes, and snippets.

@usausa
usausa / App.razor
Last active May 22, 2022 06:37
Blazor router
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<ExtendedErrorBoundary @ref="errorBoundary">
<ChildContent>
<ExtendedAuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" NotAuthorizedLayout="@typeof(ErrorLayout)">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<Server.Pages.Login Reload="true" />
@usausa
usausa / LoadingOverlay.cs
Last active June 20, 2022 07:37
MAUI WindowOverlay
public sealed class LoadingOverlay : WindowOverlay
{
public LoadingOverlay(IWindow window)
: base(window)
{
AddWindowElement(new LoadingElementOverlay());
EnableDrawableTouchHandling = true;
}
private class LoadingElementOverlay : IWindowOverlayElement
@usausa
usausa / ISectionCallback.cs
Last active June 28, 2022 04:58
Blazor section
public interface ISectionCallback
{
void SetMenu(RenderFragment value);
}
@usausa
usausa / TimeAxisCalculator.cs
Last active August 30, 2022 10:48
AxisCalculator
public static class TimeAxisCalculator
{
private static readonly TimeSpan[] CandidateValues =
{
TimeSpan.FromMinutes(1),
TimeSpan.FromMinutes(2),
TimeSpan.FromMinutes(5),
TimeSpan.FromMinutes(10),
TimeSpan.FromMinutes(15),
TimeSpan.FromMinutes(30),
@usausa
usausa / SlidingPager.cs
Created September 4, 2022 05:21
SlidingPager
public sealed class SlidingPager<T> : IList<T>
{
private readonly List<T> source;
private readonly Func<T, DateTime> selector;
private int end;
private int start;
@usausa
usausa / Program.cs
Last active November 1, 2022 09:59
Microsoft.Data.Sqlite Mutlithread test
using System.CommandLine;
using System.CommandLine.NamingConventionBinder;
using System.Diagnostics;
using Microsoft.Data.Sqlite;
using Smart.Data.Mapper;
#pragma warning disable CA1812

interface

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

abstract

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'
};
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
@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();