Skip to content

Instantly share code, notes, and snippets.

View TheAngryByrd's full-sized avatar
👋
No more major OSS for the foreseeable future

Jimmy Byrd TheAngryByrd

👋
No more major OSS for the foreseeable future
View GitHub Profile
@TheAngryByrd
TheAngryByrd / JoinableValidationResult.fs
Created March 13, 2026 19:36
Use any IEnumerable type for Error concatenation
#nowarn "3535"
#nowarn "3536"
type Joinable<'e,'T> =
static abstract member Join: 'e * 'e -> 'e
static abstract member Singleton : 'T -> 'e
module Joinable =
let inline singleton<'e, 'T when 'e :> Joinable<'e, 'T>> (input) =
'e.Singleton input
<#
.SYNOPSIS
Continuously kills dotnet.exe processes.
.DESCRIPTION
Runs in a loop, checking every second for dotnet.exe processes and killing them.
Optionally filters processes by their command line arguments.
.PARAMETER ArgumentFilter
Optional filter to match against the command line arguments of dotnet.exe processes.
@TheAngryByrd
TheAngryByrd / DifferentTFMsAndRuntimeAssemblies.fs
Last active December 16, 2025 14:55
Showing different runtime values
let ifDefRuntime =
#if NET8_0
"This is .NET 8.0"
#endif
#if NET9_0
"This is .NET 9.0"
#endif
#if NET10_0
"This is .NET 10.0"
@TheAngryByrd
TheAngryByrd / Seq.fs
Last active August 7, 2025 15:49
F# TryGetNonEnumeratedCount helper
module Seq =
open System.Linq
/// Attempts to determine the number of elements in a sequence without forcing an enumeration.
let inline tryLength (xs : seq<_>) =
match Enumerable.TryGetNonEnumeratedCount xs with
| true, count -> ValueSome count
| _ ->
match xs with
// F# list implements IReadOnlyCollection/IReadOnlyList
@TheAngryByrd
TheAngryByrd / DotEnv.fs
Last active June 11, 2025 14:20
Basic .env file reader in F#
namespace FsToolkit.Build
module DotEnv =
open System
open System.IO
let private parseLine (line: string) =
match line.Split('=', StringSplitOptions.RemoveEmptyEntries) with
| args when args.Length = 2 -> Environment.SetEnvironmentVariable(args.[0], args.[1])
| _ -> ()
@TheAngryByrd
TheAngryByrd / Ignores.fs
Last active July 21, 2026 14:08
F# Ignore Explicity
/// RequiresExplicitTypeArguments forces each caller to name the type it discards,
/// as in `ignore<int> x`. The compiler then checks that the value has that exact type.
/// Plain `ignore` infers its type argument and silently accepts any value, so it hides
/// a common mistake: a caller can ignore a function value after forgetting an argument,
/// or ignore a Task or Async that the caller meant to await. The explicit type argument
/// turns each of these mistakes into a compile error.
[<AutoOpen>]
module Ignore =
open System.Threading.Tasks
@TheAngryByrd
TheAngryByrd / why-corecompile.fsx
Created March 6, 2025 14:53
Figure out why CoreCompile was run
// This is used to quickly diagnose why a rebuild happened in a large solution
// It reads a binlog file and finds all the CoreCompile targets that were triggered by a file being newer than the output file
// It then prints out the project and the messages that caused the rebuild
// to create a binlog you can refer to https://learn.microsoft.com/en-us/visualstudio/ide/msbuild-logs?view=vs-2022#provide-msbuild-binary-logs-for-investigation
// CLI: dotnet build -bl:mybinlog.binlog
// or in `.build/build.fs` add `BuildParameter.enableBinLog "mybinlog.binlog"` to the `build'` target.
// Use https://msbuildlog.com/ to diagnose further
#r "nuget: MSBuild.StructuredLogger"
@TheAngryByrd
TheAngryByrd / LogMetaData.fs
Last active August 21, 2025 14:17
F# Collecting logging metadata like namespace, function name, filepath, and line number
open System.Runtime.CompilerServices
type Log() =
static member inline GatherLogMetaStackFrame
(?name_space: string, [<CallerMemberName>] ?cmb: string, [<CallerLineNumber>] ?cln: int, [<CallerFilePath>] ?cfp: string)
=
let name_space =
match name_space with
| Some ns -> ns
| _ ->
@TheAngryByrd
TheAngryByrd / IWSAMsErrorApproach.fs
Last active May 4, 2026 16:22
Using IWSAMs to deal with Dynamic Error Trees
#r "nuget: FsToolkit.ErrorHandling"
open FsToolkit.ErrorHandling
open System
type SensorReadings = int
module RegularApproach =
@TheAngryByrd
TheAngryByrd / CyclomaticComplexity.fsx
Created January 8, 2025 13:52
CyclomaticComplexity.fsx
#r "nuget: FSharp.Compiler.Service, 43.8.300"
open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTrivia
open FSharp.Compiler.Xml
open FSharp.Compiler.CodeAnalysis
open System.IO
type Node =
{ Data : Data