Skip to content

Instantly share code, notes, and snippets.

View fredeil's full-sized avatar
💤

Fredrik Eilertsen fredeil

💤
View GitHub Profile
@Thorium
Thorium / Client.fsx
Created September 29, 2025 10:45
ModelContextProtocol with FSharp (MCP with F#)
#r "nuget: ModelContextProtocol,0.4.0-preview.1"
open ModelContextProtocol.Client
open ModelContextProtocol.Protocol
open System
open System.Threading.Tasks
module McpClient =
let clientTransport =
StdioClientTransport(
StdioClientTransportOptions(
@AndrewDongminYoo
AndrewDongminYoo / email_validation_strategy.dart
Created April 12, 2025 11:15
Dart class that uses a strategy pattern to check the validity of an email
/// Written with “powerful” inspiration from the https://pub.dev/packages/email_validator.
/// An abstract strategy for validating objects of type [T].
///
/// Implementations of this class define specific validation rules
/// for a given type, allowing flexible and reusable validation logic.
abstract class ValidationStrategy<T, E extends Exception> {
/// Validates the given [value] of type [T].
///
/// If the validation fails, an exception of type [E] is thrown.
@davidfowl
davidfowl / Example.cs
Last active June 6, 2023 08:10
An implementation of MessagePipe. Something like a channel but with buffer management so you can peek and advance the message that was read.
using System.Buffers;
using System.Net.WebSockets;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/ws", async (HttpContext context) =>
{
const int MaxMessageSize = 1024 * 1024;
@jhewlett
jhewlett / HttpClient.FSharp.fs
Last active October 1, 2025 10:26
Functional wrapper around System.Net.Http.HttpClient. Inspired in part by Http.fs (https://github.com/haf/Http.fs) and FSharp.Data (https://fsharp.github.io/FSharp.Data/library/Http.html)
namespace HttpClient.FSharp
open System
open System.Net.Http
type HttpMethod =
| Post
| Put
| Delete
| Get
[StructLayout(LayoutKind.Sequential, Size = 256)]
public unsafe struct Bitset
{
public void Set(int bitIndex) => ((int*) Unsafe.AsPointer(ref Unsafe.AsRef(this)))[(bitIndex & ~7) >> 5] |= 1 << (bitIndex & 7);
public void Unset(int bitIndex) => ((int*)Unsafe.AsPointer(ref Unsafe.AsRef(this)))[(bitIndex & ~7) >> 5] ^= 1 << (bitIndex & 7);
public void SetAll() => Unsafe.InitBlock(Unsafe.AsPointer(ref Unsafe.AsRef(this)), 0xff, (uint) Unsafe.SizeOf<Bitset>());
public void UnsetAll() => Unsafe.InitBlock(Unsafe.AsPointer(ref Unsafe.AsRef(this)), 0x00, (uint) Unsafe.SizeOf<Bitset>());
}
@arthurrump
arthurrump / FakeGitVersioning.fsx
Last active August 14, 2019 10:35
How to use FAKE to automatically set version numbers based on your Git history. https://www.arthurrump.com/2019/07/19/git-based-versioning-using-fake
#r "paket:
nuget Fake.Core.SemVer
nuget Fake.Core.Target
nuget Fake.DotNet.Cli
nuget Fake.Tools.Git //"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.Tools
@swlaschin
swlaschin / effective-fsharp.md
Last active September 17, 2025 06:47
Effective F#, tips and tricks

Architecture

  • Use Onion architecture

    • Dependencies go inwards. That is, the Core domain doesn't know about outside layers
  • Use pipeline model to implement workflows/use-cases/stories

    • Business logic makes decisions
    • IO does storage with minimal logic
    • Keep Business logic and IO separate
  • Keep IO at edges

@unitycoder
unitycoder / teams-ux-notes.md
Last active October 28, 2025 10:50
Whats Wrong With Microsoft Teams - UX

Whats Wrong With Microsoft Teams

  • not in any order, and i know few of these have been fixed, like having conference in separate window
  • This first list is for Classic version, New Teams specific are in the gist below (but new Teams has most of the classic bugs still too)

Chat

  • If you typed message in some chat, then alt tab and go to another chat, that message is still in the chatbox (wrong room)
  • if there is many single messages, with link on each, tooltip emoji menu popups and blocks your view to previews item (and you can accidentally click it if tried to click the previous link)
  • if paste image to messagebox, messagebox stays very small 2 rows.. so cannot see anything (or wait, it expands after you alt tab away..)
  • channel mention doesnt show alerts for people by default
  • replies minimize automatically if leave chat open for a while (so context is lost where you left it)
@praeclarum
praeclarum / CSharpPredictor.fs
Created July 19, 2018 17:48
Predicts then next C# tokens given a history of previous tokens using CoreML on iOS with F#
// Given previous tokens, predict the next token (and runners up)
let predictNextToken (previousKinds : SyntaxKind[]) : Prediction[] =
if ios11 then
let model : MLModel = model.Value // Load the cached model
let mutable predictions : Prediction[] = [| |]
// RNNs require external memory
let mutable lstm_1_h : MLMultiArray = null
let mutable lstm_1_c : MLMultiArray = null