Skip to content

Instantly share code, notes, and snippets.

View baltermia's full-sized avatar
🌐
learning new stuff

Balte baltermia

🌐
learning new stuff
View GitHub Profile
@baltermia
baltermia / ConnectionManager.cs
Last active June 3, 2025 13:18
.NET TCP Debug Console
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
@baltermia
baltermia / Dataflow.cs
Created April 1, 2025 09:28
Dequeue .NET Dataflow BatchBlock with Timeout
// This code can be edited and used to retrieve items from a local dataflow BatchBlock<T>
// either when _timeout has hit, or the batch-size given to the BatchBlock constructor was reached
public async Task<T[]> DequeueAsync(CancellationToken token = default)
{
// create a linked token source to cancel the timeout task
// this triggers either when we cancel or the provided token is cancelled
using CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(token);
// the first task is a regular tasks waiting for the batch to be triggered
@baltermia
baltermia / ConcurrentExecutor.cs
Last active April 2, 2025 13:09
C# generic concurrency Execution Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace Utils;
/// <summary>
@baltermia
baltermia / SimpleMarkdown.cs
Last active January 20, 2025 14:59
Simple Markdown Sketch
using System.Collections.Generic;
namespace SimpleMarkdown;
class Testing
{
public static void Test()
{
// either use .With or set MarkdownBuilder.DefaultParseMode to globally set it once
string nice = "Hey!".Bold().Link("https://google.com/").With(ParseMode.Markdown);