Skip to content

Instantly share code, notes, and snippets.

@OnurGumus
OnurGumus / freemonad.fs
Last active September 15, 2024 01:13
async result free monad
// Define the types for the inputs and outputs
type AccountID = AccountID of int
type Balance = Balance of decimal
type Deposit = Deposit of AccountID * decimal
type NewBalance = NewBalance of decimal
type LogMessage = string
// Define an error type for your operations
type BankError =
| AccountNotFound of int
@OnurGumus
OnurGumus / AkkaTimeProvider.fs
Last active September 14, 2024 20:04
AkkaTimeProvider
type ExecuteCallback = ExecuteCallback
// Actor that executes the timer callback
type CallbackActor(callback: TimerCallback, state: obj) =
inherit UntypedActor()
override x.OnReceive(message: obj) =
match message with
| :? ExecuteCallback ->
try
@OnurGumus
OnurGumus / AutoReturnArrayPool.cs
Last active September 12, 2024 19:17
AutoReturnArrayPool
using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Threading;
var allocatedArrays = new HashSet<int>(); // To track allocated arrays
int i = 0;
while (true)
{
@OnurGumus
OnurGumus / User.fs
Last active September 12, 2024 15:29
CQRS example
module AlarmsGlobal.Command.Domain.User
open CQRS
open Akkling
open Akkling.Persistence
open AkklingHelpers
open Akka
open Common
open Serilog
open System
@OnurGumus
OnurGumus / fable.fs
Created July 24, 2024 08:59
Fable Async
open System.Threading
let taskGrandchild(order: int) : Async<unit> =
async {
printfn $"Starting Grandchild({order})"
let! ct = Async.CancellationToken
printfn $"Cancellation token GrandChild({order}): {ct.GetHashCode()}"
// use! c = Async.OnCancel(fun () -> printfn $"Cancelled Task Grandchild: {order}")
@OnurGumus
OnurGumus / FreeMonad.fs
Last active September 15, 2024 01:18
free monad
// Define the types for the inputs and outputs
type AccountID = AccountID of int
type Balance = Balance of decimal
type Deposit = Deposit of AccountID * decimal
type LogMessage = string
// Define an error type for your operations
type BankError =
| AccountNotFound of int
| InsufficientFunds of decimal
import { useRef, useState } from "react";
import ReactDOM from "react-dom";
import { createRoot } from 'react-dom/client'
import { Canvas, MeshProps, useFrame } from '@react-three/fiber'
import { Mesh } from "three";
import React from "react";
function Box(props) {
// This reference will give us direct access to the mesh
const mesh = useRef<Mesh>(null!)
namespace Lit
open System
open Fable.Core
open Fable.Core.JsInterop
open Fable.React
open Browser.Types
open Lit
/// <summary>
module Fable.Elmish.Nile
open Elmish
open FSharp.Control
open FSharp.Control.Core
[<RequireQualifiedAccess>]
module Program =
/// Uses `stream` to transform a stream of messages dispatched from the view
/// and a stream of updates to a stream of messages dispatched to `update`.
/// `stream` is only called once.
@OnurGumus
OnurGumus / serialzier.fs
Created April 30, 2023 08:32
custom thoth decoder
module Command.Serialization
open Command
open System
open Akkling
open Akkling.Persistence
open Akka.Cluster.Tools.PublishSubscribe
open Akka
open Akka.Cluster.Sharding
open Akkling.Cluster.Sharding