Skip to content

Instantly share code, notes, and snippets.

@panesofglass
panesofglass / winforms-mvu.fsx
Last active November 22, 2023 15:30
Sample WinForms F# Script
#r "mscorlib.dll"
#r "System.dll"
open System
open System.Windows.Forms
type Update<'Msg, 'Model> = 'Msg -> 'Model -> 'Model
type Dispatch<'Msg> = 'Msg -> obj -> EventArgs -> unit
type View<'Model, 'Msg> = 'Model -> Dispatch<'Msg> -> Control
@panesofglass
panesofglass / Program.cs
Created March 21, 2013 11:49
Example of using end-to-end dynamic in a C# Web API project using Dapper for data access.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlServerCe;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
@panesofglass
panesofglass / AsyncCallableHandler.fs
Last active April 24, 2023 17:53
How to use base.SendAsync in F# DelegatingHandler
type internal AsyncCallableHandler(messageHandler) =
inherit DelegatingHandler(messageHandler)
member internal x.CallSendAsync(request, cancellationToken) =
base.SendAsync(request, cancellationToken)
@panesofglass
panesofglass / ApiControllerSandbox.fsx
Created June 21, 2012 16:43
ApiController in F# Interactive
#I @"..\packages\Microsoft.Net.Http.2.0.20505.0\lib\net40"
#I @"..\packages\Microsoft.AspNet.WebApi.Core.4.0.20505.0\lib\net40"
#I @"..\packages\Microsoft.AspNet.WebApi.Client.4.0.20505.0\lib\net40"
#I @"..\packages\ImpromptuInterface.5.6.7\lib\net40"
#I @"..\packages\ImpromptuInterface.FSharp.1.1.0\lib\net40"
#I @"..\packages\Newtonsoft.Json.4.5.6\lib\net40"
#I @"..\packages\Unquote.2.2.1\lib\net40"
#r "System.Net.Http.dll"
#r "System.Net.Http.Formatting.dll"
namespace WebSocket
// Appache 2.0 license
// References:
// [1] Proposed WebSockets Spec December 2011 http://tools.ietf.org/html/rfc6455
// [2] John McCutchan (Google Dart Team Member) http://www.altdevblogaday.com/2012/01/23/writing-your-own-websocket-server/
// [3] A pretty good Python implemenation by mrrrgn https://github.com/mrrrgn/websocket-data-frame-encoder-decoder/blob/master/frame.py
// [4] WebSockets Organising body http://www.websocket.org/echo.html
// [5] AndrewNewcomb's Gist (starting point) https://gist.github.com/AndrewNewcomb/711664
@panesofglass
panesofglass / AsyncEx.fs
Created September 13, 2010 00:30
Create an Observable from an F# Async.
module AsyncEx
open System
type Async<'a> with
member this.ToObservable() =
{ new IObservable<_> with
member x.Subscribe(o) =
if o = null then nullArg "observer"
let cts = new System.Threading.CancellationTokenSource()
let invoked = ref 0
@panesofglass
panesofglass / Actor.fs
Created September 21, 2020 16:47 — forked from bent-rasmussen/Actor.fs
Experimental high performance actor implementation for F# using channel and task computation expression.
// NOTE: import this Nuget package: TaskBuilder.fs (written using 2.1.0)
//
// Tested in LINQPad (hence Dump method usage).
open System
open System.Collections
open System.Collections.Generic
open System.Diagnostics
open System.Linq
open System.Threading
@panesofglass
panesofglass / machine.js
Last active June 17, 2020 23:07
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@panesofglass
panesofglass / azure-static-web-apps.yml
Last active June 4, 2020 05:22
Simple Static Page Generator
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- master
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- master