Skip to content

Instantly share code, notes, and snippets.

Avatar

Loïc Denuzière Tarmil

View GitHub Profile
View Connection.fsx
// A reply to: https://twitter.com/davidfowl/status/1282445306261471232
// This implements a connection of some kind that can be started and stopped asynchronously.
// We must ensure that we don't try to start it while it is stopping or vice-versa.
// A few internal types first...
/// Contains whatever state needs to be held on to while connected.
type private ConnectedState = { Id: int }
/// The state of the internal agent. Describes the current status of the connection,
View UnitTaskBuilder.fsx
open System.IO
open System.Threading.Tasks
open FSharp.Control.Tasks.TaskBuilder
open FSharp.Control.Tasks.V2
type UnitTaskBuilder() =
inherit TaskBuilderV2()
member _.Run(x) = base.Run(x) :> Task
let utask = UnitTaskBuilder()
View BenchmarkUnion.fs
open System.Text.Json
open System.Text.Json.Serialization
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
type MyUnion =
| Foo
| Bar of int * string
type Unions() =
View Benchmark.fs
open System.Text.Json
open System.Text.Json.Serialization
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
type MyRecord =
{
x: int
y: string
}
View Avalonia.fs
namespace Avalonia.Media.TextFormatting.Unicode
open Avalonia.Utility
[<Struct; IsByRefLike>]
type CodepointEnumerator =
val mutable text : ReadOnlySlice<char>
val mutable current : Codepoint
View Avalonia.fs
namespace Avalonia.Media.TextFormatting.Unicode
open Avalonia.Utility
[<Struct; IsByRefLike>]
type CodepointEnumerator(text: ReadOnlySlice<char>) =
let mutable text = text
let mutable current = Codepoint.ReplacementCodepoint
@Tarmil
Tarmil / Directory.Build.targets
Last active Nov 20, 2019
Override NuGet/Paket package references with local projects
View Directory.Build.targets
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!--
Override NuGet (or Paket) references with a set of local projects.
Usage:
* Add this file at the root above all your projects, so that they all gain the capability to override a package.
* In a solution where you want to override a package, add a file Directory.Build.props like the following:
<?xml version="1.0" encoding="utf-8"?>
<Project>
View Endpoint_Gadt.fsx
type User = { name: string; (* ... *) }
type UserId = int
type EndPoint<_> =
| [<EndPoint "GET /user/{id}">]
GetUser : id: UserId -> EndPoint<Json<User>>
| [<EndPoint "POST /user"; Json "userData">]
CreateUser : userData: User -> EndPoint<Json<UserId>>
View Client.fs
namespace Sample
open WebSharper
open WebSharper.JavaScript
open WebSharper.UI
open WebSharper.UI.Client
open WebSharper.UI.Html
open WebSharper.Highcharts
open WebSharper.JQuery
View ClientSide.fs
open WebSharper
open WebSharper.JavaScript
open WebSharper.UI.Next
open WebSharper.UI.Next.Client
open WebSharper.UI.Next.Html
open WebSharper.UI.Next.Notation
[<JavaScript>]
module Client =