Skip to content

Instantly share code, notes, and snippets.

View ninjarobot's full-sized avatar

Dave Curylo ninjarobot

  • Microsoft @Azure
  • Atlanta, GA
View GitHub Profile
@ninjarobot
ninjarobot / Program.fs
Last active May 23, 2016 17:46
Simple kestrel-based ASP.NET server in FSharp on dotnet core RC2
(*
* To get started, `dotnet new --lang f#`
* Add these to the 'dependencies' section in project.json:
"System.Threading.Tasks": "4.0.11-rc2-*",
"Microsoft.AspNetCore.Hosting":"1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console":"1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel":"1.0.0-rc2-final"
* And then edit Program.fs with reqHandler for the RequestDelegate,
* wrapping an async workflow.
*)
@ninjarobot
ninjarobot / git-hash-object.fs
Last active May 16, 2016 20:55
Git object hash in FSharp
let calcObjHash (objData:byte array) =
use sha1 = new System.Security.Cryptography.SHA1Managed ()
let pre =
sprintf "blob %d\000" objData.Length
|> System.Text.Encoding.UTF8.GetBytes
use ms = new System.IO.MemoryStream ()
ms.Write (pre, 0, pre.Length)
ms.Write (objData, 0, objData.Length)
ms.Position <- 0L
sha1.ComputeHash (ms)
@ninjarobot
ninjarobot / TextToImage.fs
Created January 27, 2016 19:01
Image from text in fsharp
open System.Drawing
[<EntryPoint>]
let main argv =
let text = argv.[0]
use font = new Font("Courier New", 72.0f * 5.0f, FontStyle.Bold)
let getTextSize str =
use b = new Bitmap (1, 1)
use g = b |> Graphics.FromImage
g.MeasureString (str, font)