Skip to content

Instantly share code, notes, and snippets.

@OFark
OFark / Unraid Balancer.linq
Created January 1, 2023 12:13
Balances Unraid drives
<Query Kind="Program">
<NuGetReference>ByteSize</NuGetReference>
<Namespace>ByteSizeLib</Namespace>
<Namespace>System.Diagnostics.CodeAnalysis</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
<Namespace>System.Security</Namespace>
<Namespace>System.Text.Json</Namespace>
</Query>
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "unraidMap.Json");
@OFark
OFark / ApplicationInsightsOptions.cs
Created October 26, 2022 09:56
Adding Serilog and Application Insights to .Net core WebApp
public sealed record ApplicationInsightsOptions : ILoggerOptions
{
public bool Enabled { get; init; }
public string? InstrumentationKey { get; init; }
}
@OFark
OFark / InterpolatedStringFormatter.cs
Created October 15, 2022 15:19
Interpolated String Formatter
public readonly struct InterpolatedStringFormatter : IReadOnlyList<KeyValuePair<string, object>>
{
internal const int MaxCachedFormatters = 1024;
private const string NullFormat = "[null]";
private static int _count;
private static ConcurrentDictionary<string, StringValuesFormatter> _formatters = new ConcurrentDictionary<string, StringValuesFormatter>();
private readonly StringValuesFormatter _formatter;
private readonly object[] _values;
private readonly string _originalMessage;
@OFark
OFark / APIEndpoint.cs
Created August 26, 2022 14:17
Adding a matrix style authorization to FastEndpoints
// This file isn't necessary it just provides some handy Methods in a Endpoint Subclass
public abstract partial class APIEndpoint<TRequest, TResponse, TMapper> : APIEndpoint<TRequest, TResponse>, IHasMapper<TMapper>, IEndpoint where TRequest : notnull, new() where TResponse : notnull where TMapper : notnull, IMapper, new()
{
/// <summary>
/// the entity mapper for the endpoint
/// <para>HINT: entity mappers are singletons for performance reasons. do not maintain state in the mappers.</para>
/// </summary>
public static TMapper Map { get; } = new();
}