Skip to content

Instantly share code, notes, and snippets.

View grishace's full-sized avatar
🏍️

Grigoriy Belenkiy grishace

🏍️
View GitHub Profile
@grishace
grishace / Configuration.fs
Last active March 5, 2019 20:44
Reading linq2db configuration from json
module Configuration
open System
open System.IO
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.Configuration.Binder
open Microsoft.Extensions.Configuration.Json
open LinqToDB.Configuration
let [<Literal>] private SqlServer = "SqlServer"
@grishace
grishace / benchmark.md
Last active February 25, 2019 22:54
Benchmark compiled expression
BenchmarkDotNet=v0.11.4, OS=Windows 10.0.17134.590 (1803/April2018Update/Redstone4)
Intel Core i7-4790K CPU 4.00GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=2.2.100
  [Host]     : .NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT DEBUG
  DefaultJob : .NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT

@grishace
grishace / Program.fs
Created February 20, 2019 19:47
Extracting 7za archive with SharpCompress without using native dependencies
open System
open System.Diagnostics
open System.IO
open FSharp.Control
open SharpCompress.Common
open SharpCompress.Readers
open SharpCompress.Archives
[<EntryPoint>]
let main argv =
open System
open Microsoft.FSharp.Quotations
open FSharp.Quotations.Evaluator
type A (str: string) =
member val Prop: string = str with get, set
let inline safeGet (f: Expr<'T>): 'T option =
try Some(f.Evaluate())
with :? NullReferenceException -> None
@grishace
grishace / App.fs
Last active August 8, 2018 18:08
Moving to Fable 2
// Client project
// This piece of code follows the pattern from SAFE-Dojo for loading data from API endpoints
open Thoth.Json
type Dto = int list
let dtoDecoder = Decode.Auto.generateDecoder<Dto> ()
let init () =
@grishace
grishace / Program.cs
Last active September 10, 2017 17:21
JSON deserialization with unknown properties accumulated in the dictionary
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
namespace JsonProperties
{
open System
open System.IO
open System.Text.RegularExpressions
let parse s =
let m = Regex(@"^(?<bug>[^:]+)\s*:\s*(?:(?<area>[^,]+)\s*,?\s*)+$").Match(s)
(m.Groups.["bug"].Value, seq { for c in m.Groups.["area"].Captures -> c.Value })
[<EntryPoint>]
let main _ =
@grishace
grishace / splitters.fsx
Last active August 29, 2019 09:42
Functional Friday with @dstcruz
let reqs = [| 0 .. 6 |]
let chunks = [| 4; 1; 2 |]
let splitter rq ch =
let rec splitter' r (c:seq<int>) = seq {
if not(Seq.isEmpty c) then
let cx = c |> Seq.take 1 |> Seq.exactlyOne
yield r |> Seq.take cx
yield! splitter' (Seq.skip cx r) (Seq.skip 1 c)
}
@grishace
grishace / ants.fsx
Last active October 17, 2015 21:22
Сентябрьский конкурс по ФП: Необыкновенные приключения муравьёв (http://haskell98.blogspot.com/2015/09/blog-post.html)
open System
open System.IO
let rec seq2 s = seq {
match s with
| (s1 :: s2 :: rest) -> yield (s1, s2); yield! seq2 rest
| (s1 :: nil) -> yield (s1, 'Х')
| _ -> ()
}