Skip to content

Instantly share code, notes, and snippets.

View mastoj's full-sized avatar

Tomas Jansson mastoj

View GitHub Profile
@mastoj
mastoj / Cart.cs
Created December 28, 2022 22:34
Marten exception
namespace NextCart.Api.Cart;
public interface CartEvent { }
public record CreateCart(Guid CartId);
public record CartCreated(Guid CartId) : CartEvent;
public record Cart(Guid Id, int Version = 1)
{
@mastoj
mastoj / solver.fsx
Created January 11, 2022 21:04
Naive wordle solver in F#
let candidates = """ACRID AIDER AIRED ARDRI AROID BIDER BIRDS BRAID BREID BRIDE CAIRD CARDI CIDER CRIED DAIRY DARIC DARIS DARZI DEAIR DERIG DIARY DICER DIKER DIMER DINAR DINER DIRAM DIRER DIRGE DIRKE DIRKS DIRLS DIRTS DIRTY DIVER DORIC DORIS DRAIL DRAIN DRIBS DRICE DRIED DRIER DRIES DRIFT DRILL DRILY DRINK DRIPS DRIPT DRIVE DROID DROIL DROIT DRUID DURZI EIDER FIORD FIRED FRIED GIRDS GRIDE GRIDS GRIND HIDER HIRED IDLER INDRI IRADE IRIDS IRKED IZARD JERID JIRDS LAIRD LIARD LIDAR LURID MARID MIRED MUDIR MURID NADIR NIDOR PADRI PARDI PRIDE PRIED RABID RADII RADIO RADIX RAIDS RAIRD RANID RAPID REBID REDIA REDID REDIP REIRD RESID RICED RIDER RIDES RIDGE RIDGY RIGID RILED RIMED RINDS RINDY RIPED RIVED RORID RUDIE SIDER SIRED THIRD THRID TIRED TRIAD TRIDE TRIED TRILD UNRID URSID VIRED VIRID WEIRD WIDER WIRED WRIED YAIRD YIRDS YRIVD"""
let wordList = candidates.Split(" ") |> List.ofArray
let fixedLetters = [(2, 'I')] |> Map.ofList
let excludedCharacters = "WE"
let includeLetters = [('R', [3]);('D',[4])] |> List.map
@mastoj
mastoj / day19.fsx
Created December 20, 2021 23:36
Day 19 part 10 not working
open System.IO
type Beacon = {
X: int
Y: int
Z: int
}
type Scanner = {
Id: int
Beacons: Beacon Set
@mastoj
mastoj / day05.fsx
Created December 5, 2021 20:52
Day 05
open System.IO
let path = "05-input.data"
let sample = """0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
@mastoj
mastoj / CatchAllController.cs
Created November 12, 2021 08:45
Catch all sample controller
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace catchall.Controllers
{
@mastoj
mastoj / Kubernetes.fs
Created December 23, 2020 23:13
Sample pulumi F# helpers
[<RequireQualifiedAccess>]
module Secret =
open Pulumi.Kubernetes.Core.V1
open Pulumi.Kubernetes.Types.Inputs.Core.V1
let base64Encode (str: string) =
let bytes = System.Text.Encoding.UTF8.GetBytes(str)
System.Convert.ToBase64String(bytes)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MinimalDispatcher
{
public interface IHandle<TRequest, TResponse> {
Task<TResponse> Handle(TRequest request);
type Connection = {
Start: unit -> unit
Stop: unit -> unit
}
type ActiveConnection = {
Stop: unit -> ConnectionWrapper
}
and InActiveConnection = {
Start: unit -> ConnectionWrapper
}
@mastoj
mastoj / Program.cs
Last active May 21, 2020 18:35
Some plinq examples
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace ParallelTest
{
class Program
{
static void Main(string[] args)
@mastoj
mastoj / Program.fs
Created October 17, 2017 21:32
Proto.actor and F#
open System
open Proto
open System.Threading.Tasks
type Message = {Text: string}
type Message2 =
| Text of string
module Proto =
let createActor<'T> f =