Skip to content

Instantly share code, notes, and snippets.

@dsevastianov
dsevastianov / gist:433e5344d282e824f465
Last active August 29, 2015 14:10
Uploading GZipped file to Azure storage
///Url returned by GET /api/files/uploadToken
var url = "https://imupload.blob.core.windows.net/merchant-files/b21611714c8d4734a7686e86f7a8080d?sv=2014-02-14&sr=b&sig=05ssdgrshow383JVEmqk%2BDwrTlHqfEO16gApw%2BgK6%2F2k%3D&se=2014-12-02T17%3A13%3A16Z&sp=w";
var request = WebRequest.CreateHttp(url);
request.Method = "PUT";
request.Headers.Add("x-ms-blob-type:BlockBlob");
using (var stream = File.OpenRead(@"C:\temp\test.json"))
using(var zipped = new GZipStream(request.GetRequestStream(), CompressionMode.Compress))
stream.CopyTo(zipped);
type Resource<'a> = | Validated of 'a | Error of string list
type Schema = Resource<JsonSchema> option
type Json = Resource<string> option
type Api = {
title : string
description : string
baseUrl : string
#r @"SampleProvider.dll"
type Birch = Sample.Sample<"birch">
type Elm = Sample.Sample<"elm">
let birch = Birch.birch()
let elm = Elm.elm()
elm.Branches <- ([|Elm.elm()|])
#load "ProvidedTypes-head.fs"
open Samples.FSharp.ProvidedTypes
open Microsoft.FSharp.Quotations
type A private() = static member Foo(bar : obj[]->'T) = bar ([||])
let usualWay = typeof<A>.GetMethod("Foo").MakeGenericMethod([| typeof<string> |])
Expr.Call(usualWay, [ <@@fun (_:obj[]) -> ""@@> ])
let byBuilder = ProvidedTypeBuilder.MakeGenericMethod(typeof<A>.GetMethod("Foo"), [ typeof<string> ])
//Utility methods
static member internal ToSqlParam(p : Parameter) =
let name = p.Name
let dbType = p.TypeInfo.SqlDbTypeId
<@@
let r =SqlParameter(
name,
enum dbType,
Direction = %%Expr.Value p.Direction,
TypeName = %%Expr.Value p.TypeInfo.UdttName
@dsevastianov
dsevastianov / gist:8922164
Last active August 29, 2015 13:56
Calculating optimal buy and sell points in stock timeseries
[19;2;4;3;12;18;16;8;5;17]
|> Seq.fold (fun (start,newStart,profit) i ->
let start = defaultArg start i
let newStart = defaultArg newStart i
let newProfit = i - newStart
if profit < newProfit then Some newStart, Some newStart,newProfit
else if start > i then Some start, Some i, profit
else Some start,Some newStart,profit) (None,None,0)
@dsevastianov
dsevastianov / Fuzzy in F#
Last active December 30, 2015 19:59
Simple implementation of interval and fuzzy calculus
open System
type Interval =
{ a:double; b:double }
static member (*) (x : Interval, y : Interval) = { a = x.a * y.a; b = x.b * y.b}
static member (/) (x : Interval, y : Interval) = { a = x.a / y.b; b = x.b / y.a}
static member (+) (x : Interval, y : Interval) = { a = x.a + y.a; b = x.b + y.b}
static member (-) (x : Interval, y : Interval) = { a = x.a - y.b; b = x.b - y.a}
static member (*) (x : Interval, y : double) = { a = x.a * y; b = x.b * y}
static member (/) (x : Interval, y : double) = { a = x.a / y; b = x.b / y}