Skip to content

Instantly share code, notes, and snippets.

hyrmn / DapperExtensions.cs
Last active Oct 18, 2021
Extension methods for calling Dapper asynchronously with a Polly retry
View DapperExtensions.cs
public static class DapperExtensions
private static readonly IEnumerable<TimeSpan> RetryTimes = new[]
private static readonly AsyncRetryPolicy RetryPolicy = Policy
hyrmn / 00_OldReliable.cs
Last active Oct 10, 2021
Ways to swap numbers (.NET 6.0)
View 00_OldReliable.cs
using System.Diagnostics;
int x = 10;
int y = 20;
var tmp = x;
x = y;
y = tmp;
Debug.Assert(x == 20);
hyrmn / 0_ColorBoxes.cs
Created Sep 22, 2021
Some algos to draw things from things. For all of these, Install-Package SixLabors.ImageSharp.Drawing -Version 1.0.0-beta11
View 0_ColorBoxes.cs
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
var destWidth = 1920;
var destHeight = 1080;
using var image = new Image<Rgba32>(destWidth, destHeight);
hyrmn / LineCounter.cs
Last active Sep 10, 2021
Surprisingly slower
View LineCounter.cs
using System.Numerics;
namespace nlc;
public class LineCounter
public const int BufferSize = 128 * 1024;
private const byte rune = (byte)'\n';
private static readonly Vector<byte> mask = new(rune);
hyrmn / why.cs
Created Sep 1, 2021
RSS + media thumbnail with XLinq and I don't know why
View why.cs
record Pan(string Style, decimal Price, string ProductUrl, string ThumbnailUrl)
public XElement ToRss(XNamespace mediaNs)
return new XElement("item",
new XElement("title", Style),
new XElement("description", $"Buy now for {Price}"),
new XElement("link", ProductUrl),
new XElement(mediaNs + "thumbnail", new XAttribute("url", ThumbnailUrl))
hyrmn / oldway.cs
Last active Mar 24, 2021
Polly.Contrib.WaitAndRetry examples
View oldway.cs
var transientErrors = new HashSet<WebExceptionStatus>(new[]
hyrmn / program.cs
Created Mar 5, 2021
File manipulation with ImageSharp
View program.cs
import the following nuget package:
> Install-Package SixLabors.ImageSharp.Drawing -Version 1.0.0-beta11
View gist:3429595
[AttributeUsage(System.AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public class ಠ_ಠAttribute : Attribute
public ILog Log { get; set; }
public ಠ_ಠAttribute()
Log.Info("This code is bad and you should feel bad");
hyrmn /
Created Jul 1, 2020
Method groups are slower!!!!!!!!1
public void MapUserWithStaticMapper2()
    var users = new[]
        new User(1, "Bob Almighty", "Green", DateTimeOffset.Now),
        new User(2, "Alice Wunder", "Orange", DateTimeOffset.Now)

    var view = users.Select(u => UserSummary.MapFrom(u));
View the file when you run "notepad $PROFILE"
set-alias -name npp -value "${env:ProgramFiles}\Notepad++\notepad++.exe"
set-alias -name ed -value "code"
remove-item alias:curl -EA SilentlyContinue
$DefaultUser = 'hyrma'
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"