Skip to content

Instantly share code, notes, and snippets.

@panesofglass
panesofglass / python.fsx
Created April 26, 2020 13:55 — forked from nasser/python.fsx
Python from F#
// make sure codegen.py (https://github.com/CensoredUsername/codegen/blob/master/codegen.py) is in the same folder
// and you've added the IronPython package
open System.IO
open IronPython.Hosting
open IronPython.Runtime
open Microsoft.FSharp.Reflection
let engine = Python.CreateEngine()
@panesofglass
panesofglass / mixed-applicative-mondaic-result-ce.fsx
Created March 19, 2020 21:19 — forked from cartermp/mixed-applicative-mondaic-result-ce.fsx
Shows mixing of monadic and applicative CEs with a result builder
type ResultBuilder() =
member _.MergeSources(t1: Result<'T,'U>, t2: Result<'T1,'U>) = Result.zip t1 t2
member _.BindReturn(x: Result<'T,'U>, f) = Result.map f x
member _.Return (value: 'T) : Result<'T, 'TError> = Ok value
member _.ReturnFrom (result: Result<'T, 'TError>) : Result<'T, 'TError> = result
member this.Zero () : Result<unit, 'TError> = this.Return ()
@panesofglass
panesofglass / Thermometer.ts
Created February 5, 2020 16:18 — forked from spatney/Thermometer.ts
Custom Visual for Power BI: Thermometer
module powerbi.visuals {
export interface ViewModel {
value: number;
color?: string;
min?: number;
max?: number;
}
export class Thermometer implements IVisual {
public static capabilities: VisualCapabilities = {
@panesofglass
panesofglass / Fiber.fs
Created December 8, 2019 02:53 — forked from Horusiath/Fiber.fs
Custom fibers implementation in F#
open System
open System.Threading
type FiberResult<'a> = Result<'a, exn> option
[<Sealed;AllowNullLiteral>]
type Cancel(parent: Cancel) =
let mutable flag: int = 0
let mutable children: Cancel list = []
new() = Cancel(null)
@panesofglass
panesofglass / CircularBuffer.fsx
Created January 20, 2012 17:31
Circular Buffer in F#
#r "System.dll"
open System
open System.Diagnostics
// NOTE: A special version for primitives would increase
// performance for primitive types, especially for I/O,
// byte-based operations.
// [snippet: Circular Buffer]
type CircularBuffer<'a> (bufferSize: int) =
@panesofglass
panesofglass / TcpServer.fsx
Created January 4, 2011 17:43
Asynchronous TCP server in F#
// [snippet: Async socket server using F# async computations.]
open System
open System.IO
open System.Net
open System.Net.Sockets
open System.Threading
type Socket with
member socket.AsyncAccept() = Async.FromBeginEnd(socket.BeginAccept, socket.EndAccept)
@panesofglass
panesofglass / README.md
Created June 18, 2018 21:46 — forked from shawnbot/README.md
d3 voronoi interpolation!
@panesofglass
panesofglass / FetchData.fs
Created April 9, 2018 15:29
FetchData component using Trail
namespace BlazorApp1.Pages
open System
open System.Collections.Generic
open System.Linq
open System.Threading.Tasks
open System.Net.Http
open Microsoft.AspNetCore.Blazor
open Microsoft.AspNetCore.Blazor.Components
open Microsoft.AspNetCore.Blazor.Layouts
@panesofglass
panesofglass / fetch-tags.js
Created April 7, 2018 04:49
Fetch all tag urls on stackoverflow.com
fetch ('https://stackoverflow.com/').then(response => response.text()).then(html => {
let fragment = document.createRange().createContextualFragment(html);
let content = fragment.querySelectorAll('[rel=tag]');
for (let el of content) {
console.log(el.getAttribute('href'));
}
}).catch(error => console.error(error));
@panesofglass
panesofglass / free.fs
Created April 3, 2018 22:06 — forked from johnazariah/free.fs
Free Monad with Trampoline Infrastructure and Computation Builder
// F<'a> is any type with member 'map' of type ('a -> 'b) -> F<'a> -> F<'b>
type F<'a> = QIL<'a>
and S<'a> = F<Q<'a>>
and Q<'a> =
private
| Step of Step<'a>
| Bind of IBind<'a>
with
static member lift (k : F<'a>) : Q<'a> = Step (Suspend (fun () -> S<_>.map (Yield >> Step) k))