Skip to content

Instantly share code, notes, and snippets.

View MichalBrylka's full-sized avatar

Michał Bryłka MichalBrylka

View GitHub Profile
@MichalBrylka
MichalBrylka / Checker.js
Last active December 17, 2024 21:08
UnicodeCodePointsChecker
function findCodePointsLikeAtoZ() {
const targetLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const normalizationResults = {};
// Initialize the dictionary for each letter
for (const letter of targetLetters) {
normalizationResults[letter] = [];
}
// Iterate over all Unicode code points
@MichalBrylka
MichalBrylka / Program.cs
Created November 17, 2024 14:28
Guid.CreateVersion7
using System.Runtime.InteropServices;
var now = DateTimeOffset.UtcNow;
TryGenerate(() => Guid.NewGuid(), " v4");
TryGenerate(() => Guid.CreateVersion7(now), " v7");
TryGenerate(() => CreateVersion7(now), "MBv7");
TryGenerate(() => Ulid.NewUlid(now).ToGuid(), "Ulid");
static void TryGenerate(Func<Guid> generator, string name)
// See https://aka.ms/new-console-template for more information
using FluentResults;
//1. simple
Console.WriteLine(Divide(5, 0));
//2. fluent
var fluent = Result.Fail("error message 1")
.WithError("error message 2")
@MichalBrylka
MichalBrylka / Program.cs
Created February 5, 2024 11:09
Result public
// See https://aka.ms/new-console-template for more information
using ConsoleApp1;
var nameEntities = new[] { "", null, "Dawid", "Kacper", "Wojciech", "Michał M", "Michał B", "Rafał", "Anna", "Floris" }
.Select(CreateUser).ToList();
var index = 0;
foreach (var ne in nameEntities)
{
if (ne.TryGetValue(out var u)) Console.WriteLine($"{index++}. User created: {u}");
@MichalBrylka
MichalBrylka / InterceptorsLogging.cs
Created November 27, 2023 13:59
Interceptor for logging
using System.Runtime.CompilerServices;
namespace Net8.Features;
[Order(9)]
internal class InterceptorsLogging : IShowable
{
public void Show()
{
var todo = new TodoApi();
@MichalBrylka
MichalBrylka / LogCallBenchmarks.cs
Created February 22, 2023 13:21
TestLoggerCallsPerf
using System;
using BenchmarkDotNet.Attributes;
using Serilog;
namespace TestLoggerCallsPerf;
/*Console
| Method | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |
|----------- |---------:|--------:|---------:|------:|--------:|----------:|------------:|
| ParamsArgs | 477.0 ms | 8.56 ms | 8.01 ms | 1.00 | 0.00 | 3.75 MB | 1.00 |
@MichalBrylka
MichalBrylka / Benchmarks.csproj
Last active February 6, 2023 22:17
LINQ benchmarks
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
@MichalBrylka
MichalBrylka / JsonTableFontAwesome.csproj
Created January 8, 2023 14:36
Generate FontAwsome free list
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
@MichalBrylka
MichalBrylka / Extensions.cs
Last active December 9, 2022 14:24
Generic matrix
using System.Buffers;
namespace GenMath;
public static class Extensions
{
public static TResult[] ToArray<TResult>(this Range range, Func<int, TResult> transformer)
{
if (range.Start.IsFromEnd || range.End.IsFromEnd) throw new NotSupportedException("'FromEnd' ranges are not supported ");
@MichalBrylka
MichalBrylka / DoubleVector.cs
Last active June 17, 2025 12:23
Generic math performance
using System.Numerics;
namespace Benchmarks;
readonly struct DoubleVector
{
private readonly double[] _values;
public DoubleVector(double[] values) => _values = values;
public double Average()