Skip to content

Instantly share code, notes, and snippets.

View george-polevoy's full-sized avatar

George Polevoy george-polevoy

View GitHub Profile
@george-polevoy
george-polevoy / RESULT.md
Created April 5, 2023 15:37
Simple C# channel-based token bucket limiter

Timings

0.001096, 0.101212, 0.2020205, 0.3030929, 0.4042182, 0.5052511, 0.6066207, 0.7077272, 0.8092904, 0.9107451
@george-polevoy
george-polevoy / SimulatedAnnealing.cs
Created October 5, 2022 20:40
Simulated Annealing
namespace SimulatedAnnealing;
public class Tests
{
[TestCase(new[] { 6, 1, 9, 14, 19, 11, 0, 12, 8, 3, 5, 2, 4, 7, 10, 16, 15, 17, 18, 13, },
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, 300000)]
public void CanSort(int[] source, int[] expected, int kMax)
{
var random = new Random(123);
ISolver sa = new SimulatedAnnealing(kMax, random);
@george-polevoy
george-polevoy / DelegateCache.cs
Created September 19, 2022 17:51
compiled delegate cache
using System.Collections.Concurrent;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
namespace DelegateIdentifier;
public class Tests
{
private const int n = 3;
private const int nIter = 10_000_000;
<Project InitialTargets="EmbedFileAsStringResources">
<Target Name="EmbedFileAsStringResources"
BeforeTargets="Build">
<ItemGroup>
<EmbeddedResource Include="@(FileAsStringResource)">
<LogicalName>%(Identity)</LogicalName>
<ManifestResourceName>%(Identity)</ManifestResourceName>
</EmbeddedResource>
</ItemGroup>
</Target>
@george-polevoy
george-polevoy / FieldList.cs
Created September 7, 2022 17:00
SpanResultingFromStructRef
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Explicit)]
struct FieldList
{
[FieldOffset(0)] private int _item0;
[FieldOffset(4)] private int _item1;
[FieldOffset(8)] private int _item2;
[FieldOffset(12)] private int _item3;
@george-polevoy
george-polevoy / index.html
Created January 5, 2022 18:25
SVG Filters
<svg width="100%" height="100%"
xmlns="http://www.w3.org/2000/svg">
<filter id="reshape">
<feGaussianBlur stdDeviation="30"/>
<feComponentTransfer>
<feFuncA type="linear" slope="30.0" intercept="-10"/>
</feComponentTransfer>
</filter>
<g id="targetGroup" style="filter: url(#reshape);">
@george-polevoy
george-polevoy / Feed Forward basic routine
Created January 23, 2021 22:37
Simple Neural Network routine
public double[] FeedForward(double[] inputs)
{
for (int i = 0; i < inputs.Length; i++)
{
neurons[0][i] = inputs[i];
}
for (int i = 1; i < layers.Length; i++)
{
for (int j = 0; j < neurons[i].Length; j++)
@george-polevoy
george-polevoy / Fixed Thread Pool.cs
Last active June 3, 2016 18:13
Toy implementation of fixed thread pool
void Main()
{
long countDone = 0;
using (var pool = new FixedThreadPool(16))
{
pool.WaitForThreadInitialization();
var totalDepth = 9;
var total = (2L << totalDepth) - 1;
@george-polevoy
george-polevoy / FormattingInspections.proj
Created May 31, 2016 14:05
Code formatting inspections for line endings and unicode local alphabet for msbuild.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TasksDllPath Condition="'$(MSBuildToolsVersion)' == '14'">$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll</TasksDllPath>
<TasksDllPath Condition="'$(MSBuildToolsVersion)' != '14'">$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll</TasksDllPath>
</PropertyGroup>
<UsingTask TaskName="InspectSourceCode"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(TasksDllPath)">
<ParameterGroup>
<Import Project="$(SolutionDir)\CustomBuildTargets.proj" />
<Import Project="$(SolutionDir)\FormattingInspections.proj" />
<Target Name="BeforeBuild" DependsOnTargets="RunSourceCodeInspections;PerformVersioning">
</Target>