Skip to content

Instantly share code, notes, and snippets.

View dmitry-a-morozov's full-sized avatar

Dmitry Morozov dmitry-a-morozov

View GitHub Profile
@dmitry-a-morozov
dmitry-a-morozov / gist:4f41882c8e96876c6252
Created August 28, 2015 17:13
Specifying a Parameter Default Value
CREATE PROCEDURE [dbo].[spGetAutomobiles]
@Id int = 0,
@Make nvarchar(100) = ''
AS
BEGIN
SELECT *
FROM Automobiles a with (nolock)
WHERE (@Id = 0 OR a.Id = @Id)
AND (@Make = '' OR a.Make = @Make)
END
@dmitry-a-morozov
dmitry-a-morozov / gist:afd85a24579163bc0464
Last active August 29, 2015 14:03
F# attach interface
open System
let getComparableUri uri = {
new Uri( uri)
interface IComparable<string> with
member this.CompareTo other =
compare (string this) other
}
let url = "http://news.google.com/"
module Symbology
open System
let yahoo symbol =
use wc = new Net.WebClient()
let yahoo = "http://download.finance.yahoo.com/d"
let uri = sprintf "%s/quotes.csv?s&f=nl1" yahoo symbol
wc.DownloadString(uri)
.Split([| "\n\r" |], StringSplitOptions.RemoveEmptyEntries)
@dmitry-a-morozov
dmitry-a-morozov / gist:04db553a31b5cddf8849
Created February 26, 2015 19:23
SqlCommandProvider static factory
open FSharp.Data
type Get42 = SqlCommandProvider<"SELECT 42", "Data Source=.;Integrated Security=True;", SingleRow = true>
Get42.Create().Execute()
@dmitry-a-morozov
dmitry-a-morozov / gist:140e1e37d7998eadcece
Created April 1, 2015 23:10
McCaffrey’s column in MSD
open System
let sigmoid z = 1.0 / (1.0 + exp (- z))
let logistic (weights:float[]) (features:float[]) =
let sumProd = (weights, features) ||> Array.map2 (*) |> Array.sum
sigmoid sumProd
let makeAllData (numFeatures, numRows, seed) =
@dmitry-a-morozov
dmitry-a-morozov / gist:874d65a88d6bee6abaa7
Last active August 29, 2015 14:24
object expression with interface chain
type IOOP = abstract Mutate: unit -> unit
type IFunctional<'T> = abstract Reduce: 'T list * ('T -> 'T -> 'T) -> 'T
type ProgramThatMatters =
static member Run<'T, 'a when 'a :> IOOP and 'a :> IFunctional<'T>>(paradigm: 'a) = ()
let myCode = {
new IFunctional<int> with
member __.Reduce(xs, f) = List.reduce f xs
interface IOOP with
[ DateTime.Today.AddDays(-5.0) .. TimeSpan.FromDays(1.0) .. DateTime.Today ]
open System.IO
open System.Net
let wc = new WebClient()
let trainingSetFile = Path.Combine( __SOURCE_DIRECTORY__, "trainingSet.csv")
File.WriteAllText(trainingSetFile,
contents = wc.DownloadString("http://brandewinder.blob.core.windows.net/public/trainingsample.csv")
)
@dmitry-a-morozov
dmitry-a-morozov / gist:6370649
Created August 28, 2013 20:13
Euler project. Problem #54. F#. More Clarity Of Intent.
//TYPES
//In the card game poker...
type Card = Face * Suit
and Suit = Spades | Diamonds | Clubs | Hearts
//The cards are valued in the order:
@dmitry-a-morozov
dmitry-a-morozov / gist:6379684
Created August 29, 2013 15:36
SqlCommandTypeProvider usage example.
#r "bin/Debug/SqlCommandTypeProvider.dll"
open FSharp.NYC.Tutorial
[<Literal>]
let connectionString="Data Source=.\SQLExpress;Initial Catalog=AdventureWorks2012;Integrated Security=True"
type QueryPersonInfo = SqlCommand<"SELECT * FROM dbo.ufnGetContactInformation(@PersonId)", connectionString>