Skip to content

Instantly share code, notes, and snippets.

View asimmon's full-sized avatar

Anthony Simmon asimmon

View GitHub Profile
@asimmon
asimmon / .env
Created February 15, 2024 04:32
Zipkin with OpenTelemetry collector
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4317
@asimmon
asimmon / BetterPasswordHasher.cs
Last active December 27, 2023 15:51
BetterPasswordHasher
using System.Security.Cryptography;
public static class BetterPasswordHasher
{
// Always use distinct version IDs for new versions, ideally by incrementing the highest version ID.
private const byte VersionId1 = 0x01;
private const byte VersionId2 = 0x02;
private const byte DefaultVersionId = VersionId2;
@asimmon
asimmon / ephemeral-mongo-example.cs
Created March 25, 2023 16:57
EphemeralMongo blog post example
var options = new MongoRunnerOptions
{
UseSingleNodeReplicaSet = true,
StandardOuputLogger = Console.WriteLine,
StandardErrorLogger = Console.WriteLine,
};
using (var runner = MongoRunner.Run(options))
{
var database = new MongoClient(runner.ConnectionString).GetDatabase("mydb");
@asimmon
asimmon / semgrep.yml
Created February 21, 2023 15:42
Azure DevOps Semgrep pipeline
# Create a branch policy in Azure Repos to protect your main branch
trigger: none
schedules:
- cron: "28 5 * * 6"
displayName: "Weekly run"
branches:
include: ["main", "master"]
always: true
@asimmon
asimmon / MongoRunnerProvider.cs
Created October 11, 2022 02:28
Efficiently reuse IMongoRunner from EphemeralMongo
using EphemeralMongo;
public static class MongoRunnerProvider
{
private static readonly object _lockObj = new object();
private static IMongoRunner? _runner;
private static int _useCounter;
public static IMongoRunner Get()
{
@asimmon
asimmon / Program.cs
Created July 14, 2022 19:19
Azure App Configuration with .NET console app
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.FeatureManagement;
@asimmon
asimmon / program.cs
Created October 8, 2021 14:31
Await benchmarks
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
var benchmarkOptions = DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend));
_ = BenchmarkRunner.Run<AwaitBenchmarks>(benchmarkOptions);
@asimmon
asimmon / program.cs
Last active October 4, 2021 14:15
CQRS Mediator handle query performance
using System;
using System.Collections.Concurrent;
using System.Reflection;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
@asimmon
asimmon / decorator.ts
Created September 7, 2021 13:57
Screeps profiler in TypeScript
import profiler from './screeps-profiler';
export function profile(target: Function): void;
export function profile(target: object, key: string | symbol, _descriptor: TypedPropertyDescriptor<Function>): void;
export default function profile(target: object | Function, key?: string | symbol, _descriptor?: TypedPropertyDescriptor<Function>): void {
if (typeof profiler === 'undefined') {
return;
}
if (key) {
@asimmon
asimmon / zendesk-comment-permalinks.user.js
Last active October 18, 2019 18:07
Zendesk Comment Permalinks UserScript