Skip to content

Instantly share code, notes, and snippets.

@JordanMarr
JordanMarr / CurrentFile.fs
Created August 9, 2022 15:45
CurrentFile.fs Utility
namespace Utils
open System.IO
open System.Runtime.CompilerServices
type CurrentFile =
static member Path([<CallerFilePath>] ?file: string) =
file |> Option.defaultValue ""
@JordanMarr
JordanMarr / 01 Cache.fs
Last active January 15, 2022 08:56
F# Cache utility for ASP.NET
module Cache
open System
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Caching.Memory
type CacheExpiration =
| Absolute of DateTimeOffset
| AbsoluteRelativeToNow of TimeSpan
| Sliding of TimeSpan
namespace Sample
type MetadataResult<'value> =
{
Value: 'value
Metadata: (string * string) list
}
module MetadataResult =
let init (value: 'a) =
@JordanMarr
JordanMarr / SCU.fs
Created May 15, 2021 22:52
JSON.NET SCU Converter
// Single case union
[<Struct>] type MHPI = MHPI of double
// An entity that contains SCU
type Entity = {
Foo: string
Bar: MHPI
}
// JSON.NET Converter
@JordanMarr
JordanMarr / TodoPage.xaml
Created May 12, 2021 23:45
Xamarin TODO C# MVU
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
Shell.NavBarIsVisible="False"
Shell.TabBarIsVisible="False"
x:Name="xTodoPage"
x:Class="XamarinStore.Views.TodoPage">
<ContentPage.Resources>
<ResourceDictionary>
@JordanMarr
JordanMarr / 01 - HookRouter.fs
Last active July 12, 2020 00:41
HookRouter - Prevent Navigating Away from Component
/// Bindings for hookrouter.js
module HookRouter
// https://pastebin.com/dRsnyx4U
open Fable.Core
open Fable.Core.JsInterop
open Fable.React
open Fable.React.Props
open System.Text.RegularExpressions
open Feliz
open Fable.Core.JsInterop
/// Uses the onbeforeunload event from a component via the useEffect hook.
/// Returning a value of true will notify the user that they may have unsaved changes.
let useUnload (promptOnExit: unit -> bool) =
let promptOnExitRef = React.useRef promptOnExit
React.useEffect(fun () ->
let handler (e: Browser.Types.Event) =
let prompt = promptOnExitRef.current()
@JordanMarr
JordanMarr / 01 - Contexts.fs
Created June 25, 2020 18:15
Fable.React: Updating a parent context from a child component
module Contexts
open Feliz
open Elmish.Toastr
open Elmish
open Domain.Auth
type ToastMessage =
| InfoMsg of string
| SuccessMsg of string
@JordanMarr
JordanMarr / App.fs
Last active June 18, 2020 07:39
Fable React Context
module App
open Feliz
open Fable.React
open Fable.React.Props
open Fable.UIFabric
open Auth
open HookRouter
open Contexts
@JordanMarr
JordanMarr / 01 - SqlProvider.fs
Last active May 27, 2020 15:26
SQLProvider - Clearing the schema cache
module MyApp.Database.SqlProvider =
open FSharp.Data.Sql
open System.Data
#if DEBUG
// Print generated SQL to console
FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %O")
#endif
[<Literal>]