Skip to content

Instantly share code, notes, and snippets.

View waf's full-sized avatar

Will Fuqua waf

View GitHub Profile
@waf
waf / Troubleshooting.md
Created February 22, 2026 05:51
System Web Adapters + ASP.NET Areas + MapReverseProxy

If running into a problem where you have multiple areas registered in an MVC ASP.NET Framework app, and you're trying to port this to ASP.NET Core MVC (using System Web Adapters and/or YARP), you may find that while the application with a single area works, multiple areas do not work (only the first area registration works).

The fix is to update your MapReverseProxy line to the following:

app.MapReverseProxy()
   .Add(static builder => ((RouteEndpointBuilder)builder).Order = int.MaxValue);

Or, if you're using MapForwarder:

@waf
waf / Program.cs
Last active July 21, 2024 13:30
Complete program that plays MineSweeper in the terminal in 100 non-whitespace lines of code. Ported from https://radanskoric.com/experiments/minesweeper-100-lines-of-clean-ruby
if (args.Length == 3)
{
Play(args.Select(int.Parse).ToArray());
}
else
{
Console.WriteLine("Usage: Minesweeper width height mineCount (e.g. Minesweeper 12 6 6)");
}
static void Play(params int[] args)
@waf
waf / RedisGetAndUncompress.ps1
Last active February 7, 2024 03:44
Get gzip/deflate-compressed content from redis in powershell
# one time setup
Install-Module PsRedis
# connect
Import-Module PsRedis
Connect-Redis -ConnectionString "my-redis-server.example.com"
# create function, given a redis key, get the bytes, ungzip/deflate them and return the string.
function Get-RedisKeyAndUncompress($key) {
# get ambient connection
@waf
waf / Debugging Tips.md
Created July 6, 2022 07:15
Debugging Tips - the following is originally from https://www.debug.coach/ which is super useful but has since gone offline.

A collection of questions and mental models the pros use when debugging

  1. What question can you ask that will eliminate half the possible answers? Ask that first.
    • Ask broad questions before asking specific ones. For example ask “have you checked the logs?” Before asking “have you checked the dev tools console log?”
  2. Have you checked the logs?
    • Application Logs
    • System Logs
    • Web Server Logs
    • Database Logs
  • Browser Dev Tools Console/Network Tabs

MSBuild

  • MSBuild is a build system.
  • Given files and commands, it tries to do the "minimal amount of work"
  • You can execute csproj files by running msbuild (from your Developer terminal)

Three main parts to a csproj

  • PropertyGroup - Defines variables
@waf
waf / Program.cs
Created August 7, 2020 02:12
Testing threadpool behavior
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ThreadPoolLogger
{
class Program
{
const int ThreadChange = 40;
@waf
waf / Program.cs
Created June 25, 2020 04:53
Regex Memory Benchmarking
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnostics.Windows.Configs;
using BenchmarkDotNet.Running;
using System;
using System.Linq;
using System.Text.RegularExpressions;
// Benchmark Results:
//
// BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.329 (2004/?/20H1)
@waf
waf / Program.cs
Last active April 11, 2020 08:57
Various ways of using async/await and their end result
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace AsyncPatterns
{
public class Program
{
public static async Task Main(string[] args)
@waf
waf / Program.cs
Created March 20, 2020 10:16
AsyncLocal Demo
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsyncLocalPlayground
{
class Program
{
//private static string ThreadId; // too wide! per AppDomain
@waf
waf / CurlyBraces.cs
Last active October 26, 2019 17:31
C# 8 port of F# brace matching
//
// C# 8 port of F# brace matching.
//
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BraceMatching
{
using ParseState = Nullable<int>; // we get to cheat a bit because the C# compiler will "map" over nullable types implicitly