Skip to content

Instantly share code, notes, and snippets.

@yelluw
yelluw / suaveExample.fs
Created April 3, 2017 00:14
Default Suave example for Visual Studio. Note that it doesn't work as is.
let cts = new CancellationTokenSource()
let conf = { defaultConfig with cancellationToken = cts.Token }
let listening, server = startWebServerAsync conf (OK "Hello World")
Async.Start(server, cts.Token)
printfn "Make requests now"
Console.ReadKey true |> ignore
cts.Cancel()
@yelluw
yelluw / SuaveIOPart1.fs
Last active April 11, 2017 17:32
Suave.IO tutorial part one. Getting started and running with VS 2015.
(*
Suave.IO Tutorial #1
How to setup and run on Visual Studio 2015.
Was confirmed as working on Visual Studio 2017.
Dependencies:
<package id="FSharp.Core" version="4.0.0.1" targetFramework="net452" />
<package id="Suave" version="2.0.5" targetFramework="net452" />
class Settings(Enum):
def show(self):
"""
returns the key, value of an enum member
"""
return self.name, self.value
class CISettings(Settings):
DEBUG = False
@unique
class ProductionSettings(Enum):
DEBUG = False
DB = "production"
DOMAIN = "foo.com"
def show(self):
"""
returns the key, value of an enum member
"""
This will not work because it uses the @unique decorator.
"""
from enum import Enum, unique
@unique
class StagingSettings(Enum):
DEBUG = False
DB = "staging"
for setting in DevelopmentSettings:
print(repr(setting))
for setting in DevelopmentSettings:
print(setting)
print(type(DevelopmentSettings.DEBUG)) # <enum 'DevelopmentSettings'>
print(isinstance(DevelopmentSettings.DEBUG, DevelopmentSettings)) # True
print(repr(DevelopmentSettings.DEBUG)) # <DevelopmentSettings.DEBUG: True>
DevelopmentSettings.DEBUG