Skip to content

Instantly share code, notes, and snippets.

@cowlike
cowlike / continuation-recursion.fsx
Created November 10, 2023 16:49
continuation-based recursion
let rec reduce' (f: 'a -> 'a -> 'a) init xs cont =
match xs with
| [] -> cont init
| x :: xs -> reduce' f init xs (fun y' -> cont <| f x y')
reduce' (+) 0 [1..5] id
reduce' (+) 0UL [1UL..1000000UL] id
reduce' (+) 0UL [1UL..999999UL] id
reduce' (+) 0UL [1UL..100_000_000UL] id
@cowlike
cowlike / obsync.sh
Created February 12, 2023 17:34
obsidian sync
#!/usr/bin/env sh
OB_PATH="~/Documents/obsidian"
cd "$OB_PATH"
echo "$(date): updating folder: $(pwd)"
git pull
//tail recursive
let part xs =
let rec f acc =
function
| [] -> List.rev acc
| x :: xs -> f ((x, 1 + List.length (List.takeWhile ((=) x) xs)) :: acc) (List.skipWhile ((=) x) xs)
f [] <| List.ofSeq xs
@cowlike
cowlike / tmux-settings.md
Last active October 14, 2022 19:12
tmux settings

tmux terminal multiplexer

tmux home

Install

brew install tmux

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
{"lastUpload":"2022-05-15T13:35:34.344Z","extensionVersion":"v3.4.3"}
@cowlike
cowlike / createServiceDotnetCore.sh
Last active December 21, 2019 18:37
Steps for creating a Windows service using .NET Core 3
$ dotnet new sln -o WindowsService
The template "Solution File" was created successfully.
$ cd WindowsService/
$ dotnet new worker -n Main -o Main
The template "Worker Service" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on Main\Main.csproj...
@cowlike
cowlike / FSharpPlusTransformer.fs
Last active September 1, 2019 15:05
Monad transformer example using FSharpPlus
#r "/Users/cowlike/.nuget/packages/fsharpplus/1.1.0-ci00271/lib/netstandard2.0/FSharpPlus.dll"
open FSharpPlus
open FSharpPlus.Data
let doAsyncThing = async {return System.DateTime.Now}
let doNextAsyncThing (x:System.DateTime) = async {
let m = x.Millisecond
return (if m < 500 then Some m else None)
}
@cowlike
cowlike / Ldap.fs
Created March 21, 2019 18:03
wrap Novell.Directory.Ldap
module Ldap
open System
open TMon
open Novell.Directory.Ldap
open Novell.Directory.Ldap.Utilclass
type AttrValue =
String of string
| StringArray of string []
export APP=MyApp
dotnet new sln -o $APP
cd $APP
dotnet new console -n Main -o Main -lang f#
dotnet new xunit -n Tests -o Tests -lang f#
dotnet sln add Tests/Tests.fsproj Main/Main.fsproj
dotnet add Tests/Tests.fsproj reference Main/Main.fsproj
dotnet add Tests/Tests.fsproj package unquote
@cowlike
cowlike / RuntimeMillisVal.fs
Created July 13, 2018 21:07
F# timer function
let inline runtimeMillisVal (test: unit -> ^a): ^a * int64 =
let watch = System.Diagnostics.Stopwatch.StartNew()
let result = test()
watch.Stop()
result, watch.ElapsedMilliseconds