Skip to content

Instantly share code, notes, and snippets.

@smoothdeveloper
Created December 7, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoothdeveloper/66ffb0be6d5d374d69aa2f219a09c1a8 to your computer and use it in GitHub Desktop.
Save smoothdeveloper/66ffb0be6d5d374d69aa2f219a09c1a8 to your computer and use it in GitHub Desktop.
IronFunctions help Seif Lotfy
// code converted for http://seif.codes/playing-with-net-dotnet-and-ironfunctions/
// https://twitter.com/SeifLotfy/status/805901527659540480
open System
open System.IO
open System.Security.Cryptography
open System.Text
let downloadRemoteImageFile (url: string) =
let request = url |> System.Net.WebRequest.CreateHttp
use response = request.GetResponseAsync().Result
use stream = response.GetResponseStream()
use memoryStream = new MemoryStream(Capacity = int response.ContentLength)
stream.CopyTo memoryStream
memoryStream.ToArray()
let isPipedInput () =
try
let _ = Console.KeyAvailable
false
with
| _ -> true
let createCheckSum (data: byte array) =
use md5 = MD5.Create()
let hash = md5.ComputeHash data
let builder = StringBuilder()
for b in hash do
sprintf "%x" b |> (builder.Append >> ignore)
builder.ToString()
[<EntryPoint>]
let main args =
if not (isPipedInput()) then
1
else
Console.In.ReadToEnd()
|> downloadRemoteImageFile
|> createCheckSum
|> Console.WriteLine
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment