Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Sergey Tihon sergey-tihon

🏠
Working from home
View GitHub Profile
View staticProp.fs
type BaseProvidedType() =
static let mutable _host = ""
static member Host
with get() = _host
and set(value) = _host <- value
type ProvidedType() = inherit BaseProvidedType()
ProvidedType.Host <- "1"
BaseProvidedType.Host // = "1"
View tailoptimized.fs
//--------- Sample 1 -------------
/// Factorial
let rec fact n =
if n = 1 then 1
else n*fact(n-1)
/// Tail optimized Factorial
let fact n =
let rec factImpl n acc = // acc = accumulator
View gist:419589f96f8de1193010
// include Fake libs
#r @"c:\Project\FAKE.Deploy\bin\FAKE\tools\FakeLib.dll"
open Fake
open System
open System.IO
let targetDirectory = @"c:\Project\Service.MSO"
let runScript file =
if File.Exists file then
View nuget-dependency-visualizer.fsx
#r @"packages\Streams.0.2.5\lib\Streams.Core.dll"
open System
open System.IO
open System.Collections.Generic
open Nessos.Streams
// make Visual Studio use the script directory
Directory.SetCurrentDirectory(__SOURCE_DIRECTORY__)
@sergey-tihon
sergey-tihon / gist:51e21e328454567594f4
Created Nov 13, 2014
Joke radio powered by COM Type Provider
View gist:51e21e328454567594f4
#r "../packages/FSharp.ComProvider.1.0.0-pre1/lib/net40/FSharp.ComProvider.dll"
#r @"../packages/FSharp.Data.2.1.0/lib/net40/FSharp.Data.dll"
open FSharp.Data
type SpeechService = TypeLib.``Microsoft Speech Object Library``.``5.4``
let speech = SpeechService.SpVoiceClass()
type js = JsonProvider<"""{ "type": "success", "value": { "id": 42, "joke": "Joke here." } }""" >
let getJoke num =
View gist:ceaf835ef2df2d9bcf8f
#I @"packages\Nuget.Core.2.8.3\lib\net40-Client"
#r "NuGet.Core.dll"
#r "System.Xml.Linq.dll"
let repository =
NuGet.PackageRepositoryFactory.Default.CreateRepository
"https://nuget.org/api/v2"
type NuGetStat =
{ Id: string; DownloadCount:int}
View gist:7d0ca6fdb9d2703d0b36
public List<Dependency> GetDependency(Tree tree)
{
var tlp = new PennTreebankLanguagePack();
var gsf = tlp.grammaticalStructureFactory();
var gs = gsf.newGrammaticalStructure(tree);
var dependencies = gs.typedDependenciesCollapsedTree();
return (from TypedDependency dependency in dependencies.toArray()
select new Dependency
{
@sergey-tihon
sergey-tihon / gist:8325391
Created Jan 8, 2014
F# MongoDB sample (C# Driver)
View gist:8325391
#I @"..\packages\mongocsharpdriver.1.8.3\lib\net35\"
#r "MongoDB.Driver.dll"
#r "MongoDB.Bson.dll"
open System
open MongoDB.Bson
open MongoDB.Bson.Serialization.Attributes
open MongoDB.Driver
open MongoDB.Driver.Builders
open MongoDB.Driver.Linq
View gist:8180076
let shift (s:string) (k:int) =
System.String(
s.ToCharArray()
|> Array.map (function
| x when 'a' <= x && x <='z' ->
let code = int(x)-int('a')
char(int('a') + (code + k + 26) % 26)
| x -> x )
)
View gist:7239881
*** Assembly Binder Log Entry (10/30/2013 @ 11:29:27 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
--- A detailed error log follows.
=== Pre-bind state information ===