Skip to content

Instantly share code, notes, and snippets.

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
namespace Tsunami.Server
open System
open System.IO
open System.Linq
open System.Net
open System.Net.Sockets
open System.Text
open System.Threading
open System.Runtime.Serialization
open System.Net
open Microsoft.FSharp.Control.WebExtensions
open System.Diagnostics
open System
let fetch name (url:string) =
printfn "fetching %s" name
let uri = new System.Uri(url)
use webClient = new WebClient()
let stopwatch = Stopwatch()
#if run_with_bin_sh
# See why this works at http://stackoverflow.com/a/21948918/637783
exec fsharpi --define:mono_posix --exec $0 $*
#endif
(*
* Crossplatform FSharp Makefile Bootstrapper
* Apache licensed - Copyright 2014 Jay Tuley <[email protected]>
* v 2.0 https://gist.github.com/jbtule/9243729
*
#r @"packages\FAKE.2.1.309-alpha\tools\FakeLib.dll"
#r @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Client.dll"
#r @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"
open Fake
open Microsoft.TeamFoundation.Client
open Microsoft.TeamFoundation.Build.Client
open System
type MyType() =
member x.Stuff = 1
member x.DoStuff() = x.Stuff
type IListLike<'T> =
abstract Enumerate : unit -> seq<'T>
type MyType with
member x.DoMore() = x.DoStuff() + 1 // this works
interface IListLike<int> with // this doesn't: All implemented interfaces should be declared on the initial declaration of the type
@panesofglass
panesofglass / AsyncSockets.fs
Created June 25, 2012 21:52 — forked from t0yv0/AsyncSockets.fs
Asynchronous socket programming with F# async.
open System.Net.Sockets
type A = System.Net.Sockets.SocketAsyncEventArgs
type B = System.ArraySegment<byte>
exception SocketIssue of SocketError with
override this.ToString() =
string this.Data0
/// Wraps the Socket.xxxAsync logic into F# async logic.
@panesofglass
panesofglass / option-b.cs
Created June 21, 2012 03:08 — forked from loudej/option-a.cs
Unify Request and Response representation
namespace Owin
{
public delegate void AppDelegate(
IDictionary<string, object> env,
IDictionary<string, string[]> headers,
Stream body,
ResultDelegate result,
Action<Exception> fault);
public delegate void ResultDelegate(
@panesofglass
panesofglass / NuGet.targets.xml
Created June 14, 2012 23:07 — forked from motowilliams/NuGet.targets.xml
Inline MSBuild task to download NuGet.exe - NuGet.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
@panesofglass
panesofglass / Setup.fsx
Created June 12, 2012 03:49 — forked from ovatsus/Setup.fsx
Script to setup F# Interactive session, loading everything in the current solution
#r "System.Xml.Linq"
open System
open System.IO
open System.Xml.Linq
let script = seq {
//TODO: this currently loads fsproj's in alphabeticall order, we should instead
//build the dependencies graph of the fsproj's and load them in topological sort order