Skip to content

Instantly share code, notes, and snippets.

@panesofglass
panesofglass / Formatting.fs
Created February 28, 2016 21:01
Server MVC OWIN Formatting
open Newtonsoft.Json
let serializerSettings = JsonSerializerSettings(ContractResolver = Serialization.CamelCasePropertyNamesContractResolver())
serializerSettings.Converters.Add(OptionConverter())
let serialize data =
JsonConvert.SerializeObject(data, serializerSettings)
|> Text.Encoding.UTF8.GetBytes
let deserialize<'T> (stream: Stream) =
@panesofglass
panesofglass / Handlers.fs
Created February 9, 2016 16:15
Server MVC OWIN Handlers
(**
* Handlers
*)
let notFound (env: OwinEnv) =
env.[Constants.responseStatusCode] <- 404
env.[Constants.responseReasonPhrase] <- "Not Found"
async.Return()
let methodNotAllowed (env: OwinEnv) =
@panesofglass
panesofglass / Routing.fs
Last active February 9, 2016 16:04
Server MVC OWIN Routing
(**
* Routing
*)
let matchUri template env =
let environ = Environment.toEnvironment env
let basePath = environ.RequestPathBase
let template' = if String.IsNullOrEmpty basePath then template else basePath + template
let uriTemplate = UriTemplate(template', ignoreTrailingSlash = true)
let baseUri =
@panesofglass
panesofglass / 01_folds.fs
Created January 12, 2016 04:12 — forked from cloudRoutine/01_folds.fs
F# Transducers - they work for the most part
open System.Collections.Generic
open Microsoft.FSharp.Collections
[<RequireQualifiedAccess>]
module Folds =
// These are the fast implementations we actually want to use
@panesofglass
panesofglass / structs.fsx
Last active January 1, 2016 18:01
Experiments with F#
// F# equivalent of ML signatures?
type MSIG =
interface
// Cannot embed type signatures.
//type key
abstract x : int
end
// F# equivalent of ML structures?
type M =
@panesofglass
panesofglass / Example.cs
Last active November 18, 2015 16:18
Nancy ResourceModule
using NancyFx.Resource;
public class MyResource : ResourceModule
{
public MyResource("/", {
Get = () => ...
})
}
type SampleResourceMethod =
| Create of AsyncReplyChannel<unit>
| SetTimestamp of DateTimeOffset * AsyncReplyChannel<unit>
type SampleResource() =
let agent = MailboxProcessor<_>.Start(fun inbox ->
let rec loop () = async {
let! msg = inbox.Receive()
match msg with
| Create ch ->
@panesofglass
panesofglass / MVC-with-RxJS-and-D3-(inheritance).markdown
Created January 19, 2015 21:55
MVC with RxJS and D3 (inheritance)

MVC with RxJS and D3 (inheritance)

Prototype MVC (or MVI) client-side with RxJS and D3 to show use with various component libraries.

At present, RxJS Subjects are used as part of an inheritance hierarchy.

A Pen by Ryan Riley on CodePen.

License.

MVC with RxJS and D3

Prototype MVC (or MVI) client-side with RxJS and D3 to show use with various component libraries.

At present, RxJS Subjects are used like channels and not as part of an inheritance hierarchy.

A Pen by Ryan Riley on CodePen.

License.

@panesofglass
panesofglass / app.js
Last active August 29, 2015 14:13
d3.js - rendering a navigation tree
(function (global, Data, Nav, f) {
f(global, Data, Nav);
})(window, window.Data, window.Nav,
function app(global, data, Nav) {
"use strict";
var nav = Nav("nav.nav");
nav(data);
global.setTimeout(function () {