Skip to content

Instantly share code, notes, and snippets.

public class PartitionedNamingStrategy
{
private static readonly Dictionary<string, Func<string, string>> NamingStrategies = new Dictionary<string, Func<string, string>>
{
{"none", s => s},
{"bymachine", s => $"{Environment.MachineName}_{s}"}
};
private readonly string _strategy;
@hyrmn
hyrmn / main.cs
Created October 29, 2019 00:35
Two simple local functions
static decimal CalculateBalance(AccountId accountId)
{
//assume these things come in externally
var charges = new[] {new Charge(100M)};
var payments = new[] {new Payment(20M)};
var chargeBalance = Σ(charges.Select(c => c.Amount));
var paymentCredit = Σ(payments.Select(p => p.Amount));
return chargeBalance - paymentCredit;
@hyrmn
hyrmn / dbmigrator.csproj
Created October 18, 2019 01:16
refuses to pick up new files unless I clean or delete bin/obj first
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DbUp-SqlServer" Version="4.2.0" />
<PackageReference Include="OctoPack" Version="3.0.31" />
</ItemGroup>
@hyrmn
hyrmn / capslockwarning.js
Created October 4, 2019 17:46
Show a little capslock warning if the user tries to log in while their capslock key is on.
<script>
(function() {
var capsLockEnabled = false;
document.onkeypress = function (e) {
e = e || window.event;
var s = String.fromCharCode(e.keyCode || e.which);
if (s.toLowerCase() === s.toUpperCase()) {
return;
}
@hyrmn
hyrmn / oldway.cs
Last active August 1, 2023 09:07
Polly.Contrib.WaitAndRetry examples
var transientErrors = new HashSet<WebExceptionStatus>(new[]
{
WebExceptionStatus.ConnectFailure,
WebExceptionStatus.ConnectionClosed,
WebExceptionStatus.KeepAliveFailure,
WebExceptionStatus.Pending,
WebExceptionStatus.PipelineFailure,
WebExceptionStatus.ProtocolError,
WebExceptionStatus.ReceiveFailure,
WebExceptionStatus.RequestCanceled,
@hyrmn
hyrmn / DapperExtensions.cs
Last active December 18, 2023 09:16
Extension methods for calling Dapper asynchronously with a Polly retry
public static class DapperExtensions
{
private static readonly IEnumerable<TimeSpan> RetryTimes = new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3)
};
private static readonly AsyncRetryPolicy RetryPolicy = Policy
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
[CoreJob]
//[MemoryDiagnoser]
//[InProcess()]
@hyrmn
hyrmn / richhickey.md
Created April 18, 2018 08:35 — forked from prakhar1989/richhickey.md
richhickey.md

Rich Hickey on becoming a better developer

Rich Hickey • 3 years ago

Sorry, I have to disagree with the entire premise here.

A wide variety of experiences might lead to well-roundedness, but not to greatness, nor even goodness. By constantly switching from one thing to another you are always reaching above your comfort zone, yes, but doing so by resetting your skill and knowledge level to zero.

Mastery comes from a combination of at least several of the following:

[user]
name = Ben Hyrman
email = ben.hyrman@gmail.com
[core]
autocrlf = true
editor = vim
excludesfile = C:\\Users\\B.Hyrman\\Documents\\gitignore_global.txt
[credential]
helper = manager
[merge]
using System;
using System.Collections.Concurrent;
using Anotar.Serilog;
using Microsoft.ServiceBus.Messaging;
using RezStream.Infrastructure;
namespace RezCloud.Infrastructure.AzureBus
{
public class Queues : Enumeration<Queues, string>
{