Skip to content

Instantly share code, notes, and snippets.

View MichalBrylka's full-sized avatar

Michał Bryłka MichalBrylka

View GitHub Profile
@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()
@MichalBrylka
MichalBrylka / Program.cs
Created November 29, 2022 08:09
Generic Physics
var distances = Enumerable.Range(1, 10).Select(i => new Distance(i)).ToArray();
var sumOfDistances = Sum(distances);
var times = Enumerable.Range(1, 10).Select(i => new Time(i * i)).ToArray();
var velocities = distances.Zip(times).Select(pair => pair.First / pair.Second).ToArray();
static TUnit Sum<TUnit>(IEnumerable<TUnit> units)
where TUnit : IUnit<TUnit>
@MichalBrylka
MichalBrylka / Program.cs
Last active November 17, 2022 23:42
Static Interface Members
var parsedLines = Lines<CommaSeparatedWords>.Parse("""
Ala,has,a,cat
Cat,has,Ala
""");
var parsedNumbers = CsvFile<int>.Parse("""
11
22
33
""");
@MichalBrylka
MichalBrylka / Program.cs
Created October 18, 2022 21:36
GetAvgSentiment
string[] symbolsUniverse = new[] { "AAPL", "VOD", "ADBE", "GRPN", "META", "ACER", "GOOG", "BP" };
List<string> GenerateSymbols(int number)
{
var symbols = new List<string>();
for (int i = 0; i < symbolsUniverse.Length; i++)
{
var bit = 1 << i;
if ((number & bit) == bit)
symbols.Add(symbolsUniverse[i]);
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
interface Changeable
infix fun <TTarget : Changeable, TProperty> Changeable.withChanged(change: Pair<kotlin.reflect.KProperty1<TTarget, TProperty>, TProperty>): Changeable =
this.also {
val (property, newValue) = change
val field = it::class.java.getDeclaredField(property.name)
field.isAccessible = true
field.set(it, newValue)
}
[TestCase(0, 0, "")]
[TestCase(1, 1, "3")]
[TestCase(2, 2, "3|4")]
[TestCase(3, 3, "3|4|5")]
[TestCase(4, 3, "3|4|5|0")]
[TestCase(5, 3, "3|4|5|0|0")]
public void Read_ToBuffer_ShouldBeAbleToReadBytes(int bufferSize, int expectedCount, string expectedArray)
{
var sut = new SpanBinaryReader(new byte[] { 1, 2, 3, 4, 5 }, 2);
// ^
package kafkaStrongConfig
enum class Importance { Low, Medium, High }
@Target(AnnotationTarget.PROPERTY)
annotation class Config(val configName: String, val importance: Importance = Importance.Low)
@MichalBrylka
MichalBrylka / Main.cs
Last active February 9, 2022 10:53
Generated enum parser performance
[MemoryDiagnoser]
public class EnumParserBenchNonFlagGenerated
{
public enum DayOfWeek : byte
{
None ,
Monday,
Tuesday,
Wednesday,
Thursday,
@MichalBrylka
MichalBrylka / Main.java
Created December 1, 2021 21:38
Java Guice Ioc
package corp;
import com.google.inject.*;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new Module());