Skip to content

Instantly share code, notes, and snippets.

View haf's full-sized avatar
💹
currently succeeding...

Henrik Feldt haf

💹
currently succeeding...
View GitHub Profile
@haf
haf / 1 - Versions.md
Last active January 10, 2018 14:27
F# versions

Deps

[Suave.Testing][st] for net461:

  • [FSharp.Core][fs] >= 4.0.0.1

Suave.Testing for netstandard2.0:

  • FSharp.Core >= 4.2.3
function unfoldWith(fn) {
return value => {
let a = [],
{ next, element, done } = fn(value);
while (!done) {
a.push(element);
({ next, element, done } = fn(next));
}
return a;
}
@haf
haf / A vision for F#.md
Last active March 27, 2018 00:46
A vision for F#

What should F# as a language contain?

  • A default test framework like Expecto
  • A default HTTP client like HTTP.fs
  • A default web framework like Suave
  • A default JS framework like Fable
  • A default logging framework like Logary
  • A default character parser combinator library like FParsec
  • A default binary parser combinator library like FsAttoparsec
  • A default concurrent programming framework like Hopac
@haf
haf / index.html
Created May 20, 2017 12:14
Say whhhhaat? (With command-injection vulnerability included! But still awesome!)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Say something</title>
</head>
<body>
<form action="/" method="POST">
<fieldset for="to-say">
To say:
@haf
haf / LoggerEx.fs
Created April 28, 2017 20:12
Extensions for Logary's Facade logger for Hopac
module LoggerExtensions
open Hopac
/// Extensions to the Expecto logger for Hopac.
type Expecto.Logging.Logger with
/// Log Verbose with backpressure as a job
member x.verboseWithBPJ factory =
x.verboseWithBP factory |> Job.fromAsync
/// Log Debug with backpressure as a job
@haf
haf / DU-name.fs
Last active April 25, 2017 16:43
Question about finding the name of the case?
type DU =
| ACaseName
| BThereCake
let magic (q: Quotation<_>): string =
// smallest F# code in here?
open Expecto
let subject = magic <@ ACaseName @>
Expect.equal subject "ACaseName" "Should extract the NAME of the DU case"
@haf
haf / ThreadSafeDictionary.fs
Last active April 3, 2018 20:11
ThreadSafeDictionary with selective choice in Hopac
open Hopac
open Hopac.Infixes
/// A thread safe dictionary supports multiple-readers', multiple-writers'
/// access to a normal .Net dictionary.
type ThreadSafeDictionary<'K, 'V> =
private {
tryAddCh: Ch<'K * (unit -> 'V) * Ch<'V> * Promise<unit>>
tryAddSelectCh: Ch<'K * (unit -> 'V) * ('V -> obj) * Ch<obj> * Promise<unit>>
tryRemoveCh: Ch<'K * Ch<'V option> * Promise<unit>>
@haf
haf / Start.fs
Created March 11, 2017 20:40
Async start of Suave w/ Logary and Hopac
let startPublicWebApi s (logary : LogManager) esConn : Job<IAsyncDisposable> =
let webApi = createPublicWebApi s esConn
let cts = new CancellationTokenSource()
let webConfig =
{ defaultConfig with
cancellationToken = cts.Token
bindings = [ HttpBinding.createSimple HTTP "0.0.0.0" s.listenPort ]
}
LogaryFacadeAdapter.initialise<Suave.Logging.Logger> logary
@haf
haf / gist:ef50a926eb7506115b70ba7a7c10c3c6
Created February 17, 2017 23:09
PDFSharp OS X font resolver
module PDFSharp.OSX
open PdfSharp
open PdfSharp.Fonts
open PdfSharp.Pdf
open PdfSharp.Drawing
open System
open System.Drawing
open System.Drawing.Text
open System.Globalization