Skip to content

Instantly share code, notes, and snippets.

View neon-sunset's full-sized avatar
💭
So ARM64 has FJCVTZS for JS but nothing to count UTF-8 code point length :(

neon-sunset

💭
So ARM64 has FJCVTZS for JS but nothing to count UTF-8 code point length :(
View GitHub Profile
@neon-sunset
neon-sunset / HttpBenchmarkTemplate.cs
Last active September 5, 2022 23:59
Lightweight HTTP throughput benchmark template for high-load scenarios. Run dotnet new console, dotnet add package RangeExtensions, copy template to Program.cs and then run with dotnet run -c release.
using System.Diagnostics;
// Set your own execution time here.
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
// dotnet add package RangeExtensions
// Feel free to spawn an arbitrary (within reason) count of workers to simulate desired concurrency.
// Keep in mind that HttpClient might reuse HttpMessageHandler's, feel free to tune to your taste.
var workers = (..64) // ..Environment.ProcessorCount is also a good idea for simpler cases.
.AsEnumerable()
@neon-sunset
neon-sunset / TieredBufferAllocExample.cs
Last active January 22, 2024 11:05
Tiered buffer allocation example: stackalloc -> array pool -> native memory alloc
using Cysharp.Collections; // dotnet add package NativeMemoryArray
namespace BufferAllocExample;
public static class ExampleBufferedBytesProcessor
{
public static int ProcessBytes(IUtf8Processor processor, ReadOnlySpan<char> source, Span<byte> destination)
{
const int StackAllocLimit = 1024; // 1KB
const int ArrayPoolLimit = 1024 * 1024 * 10; // 10MB
using System.Runtime.InteropServices;
var writeable = MemoryMarshal
.AsMemory(false.ToString().AsMemory())
.Span;
"True\0".CopyTo(writeable);
Console.WriteLine((object)false); // Prints 'True'
dotnet publish -c release -f net7.0 -r {RID} -p:PublishSingleFile=true --self-contained true
public static class AsyncEnumerableExtensions
{
/// <summary>
/// Will skip faulted tasks by default
/// </summary>
public static async IAsyncEnumerable<TResult?> ParallelSelectAsync<T, TResult>(
this IEnumerable<T> items,
Func<T, Task<TResult>> operation,
int parallelism = -1,
bool throwOnError = false)
@neon-sunset
neon-sunset / cn.p2p
Last active April 8, 2022 17:45
China IP ranges blocklist for qBittorrent (.p2p format)
# List distributed by iblocklist.com
China:1.0.1.0-1.0.1.255
China:1.0.2.0-1.0.3.255
China:1.0.8.0-1.0.15.255
China:1.0.32.0-1.0.63.255
China:1.1.0.0-1.1.0.255
China:1.1.2.0-1.1.3.255
China:1.1.4.0-1.1.7.255
China:1.1.8.0-1.1.8.255