Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Thomas 7sharp9

  • Moirae Software Engineering Ltd
  • UK
  • Twitter @7sharp9_
View GitHub Profile
View main.fs
module compilertesting.Main
open System
open System.IO
open System.Text
open Microsoft.FSharp.Compiler.SimpleSourceCodeServices
[<EntryPoint>]
let main args =
View barometer.fs
[<Activity (Label = "HelloBarometer", MainLauncher = true)>]
type MainActivity () =
inherit Activity ()
let calculateAltitudeInFeet hPAs =
let pstd = 1013.25
(1.0 - Math.Pow((hPAs/pstd), 0.190284)) * 145366.45
let mainLabel = ref Unchecked.defaultof<_>
@7sharp9
7sharp9 / XsThemeHelp.fs
Created Mar 29, 2013
A few helpers around Colours in Xamarin Studio, these will become extensions of the Types eventually: let myGdkColour = myCairoColour |> CairoColor.toGdk
View XsThemeHelp.fs
let colourStyles = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle(MonoDevelop.Ide.IdeApp.Preferences.ColorScheme)
let keywordColour = colourStyle.GetForeground (colourStyle.KeywordProperty)
let cairoToHsl (c:Cairo.Color) = HslColor.op_Implicit(c)
let gdkToHsl (c:Gdk.Color) = HslColor.op_Implicit(c)
let hslToCairo (c:HslColor) : Cairo.Color = HslColor.op_Implicit(c)
let hslToGdk (c:HslColor) : Gdk.Color = HslColor.op_Implicit(c)
let cairoToGdk = cairoToHsl >> hslToGdk
@7sharp9
7sharp9 / CsBs.cs
Created Mar 11, 2012
F# Black-Scholes
View CsBs.cs
public class Options
{
public enum Style
{
Call,
Put
}
public static double BlackScholes(Style callPut, double s, double x, double t, double r, double v)
{
View async_catch.fs
let mailbox = MailboxProcessor.Start(fun inbox ->
let rec loop routes = async {
let! msg = inbox.Receive()
match msg with
| Payload(data) ->
ss.Release() |> ignore
let result = async{data |> transform |> router <| routes}
|> Async.Catch
|> Async.RunSynchronously
match result with
View pipelets loop option2.fs
let mailbox = MailboxProcessor.Start(fun inbox ->
let rec loop routes = async {
let! msg = inbox.Receive()
match msg with
| Payload(data) ->
ss.Release() |> ignore
let result = compute data routes |> Async.Catch |> Async.RunSynchronously
match result with
| Choice1Of2 _ -> ()
| Choice2Of2 exn -> errors exn
View pipelets_loop.fs
let computeAndRoute data routes = async{data |> transform |> router <| routes}
let mailbox = MailboxProcessor.Start(fun inbox ->
let rec loop routes = async {
let! msg = inbox.Receive()
match msg with
| Payload(data) ->
ss.Release() |> ignore
Async.StartWithContinuations(computeAndRoute data routes, ignore, errors, ignore)
return! loop routes
@7sharp9
7sharp9 / test.fs
Created Nov 15, 2011
simple hhtp
View test.fs
let server = new HttpServer(OnHeaders = respondHelloWorld ) )
View Fsharp_web_server.fs
let server = HttpServer((fun(headers, close, svr, sd) ->
let header = sprintf "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 20\r\nConnection: close\r\nServer: Fracture\r\nDate: %s\r\n\r\n" (DateTime.UtcNow.ToShortDateString())
let body = "Hello world.\r\nHello."
let encoded = System.Text.Encoding.ASCII.GetBytes(header + body)
do svr.Send(sd.RemoteEndPoint, encoded, true)), body = fun(body, svr, sd) ->
Debug.WriteLine( sprintf "%s" (Text.Encoding.ASCII.GetString(body.Array)) ) )
server.Listen(6667)
printfn "Http Server started"
Console.ReadKey() |> ignore
View snap-benchmark's pong implementation in node.js
http.createServer(function (request, response) {
var uri = url.parse(request.url).pathname;
if(uri=='/pong') {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('PONG');
} else if ((match = uri.match(/^\/echo\/(.*)$/)) != null) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end(match[1]);