Skip to content

Instantly share code, notes, and snippets.

View Szer's full-sized avatar

Ayrat Hudaygulov Szer

View GitHub Profile
@Szer
Szer / effect.fs
Last active July 5, 2021 11:56
This is a joke
type Effect<'env, 'out> = Effect of ('env -> 'out)
module Effect =
let value x = Effect (fun _ -> x)
let apply f = Effect f
let run env (Effect f) = f env
let run' (Effect f) env = f env
let map f (Effect g) = Effect(f << g)
let local f (Effect g) = Effect(f >> g)
let inline bind f effect =
Effect (fun env ->
@Szer
Szer / sameCaseCheck.fs
Last active April 10, 2020 15:25
Concise check if cases of DU are the same
open System
open System.Collections.Concurrent
open Microsoft.FSharp.Reflection
open Microsoft.FSharp.Quotations.Patterns
type UnionUtils =
static member private isTypeUnionCache = ConcurrentDictionary<Type, bool>()
static member private tagGetterCache = ConcurrentDictionary<Type, obj -> int>()
@Szer
Szer / stepfulBuilder.fs
Last active July 27, 2020 21:05
Computational expression with state being passed through steps
type StepfulBuilder() =
member _.Zero() = ()
member _.Yield x = x
[<CustomOperation("toInt")>]
member inline _.ToInt(_, value) =
int value
[<CustomOperation("transform")>]
member _.Transform(x, f) =
open FSharp.Data
open XPlot.Plotly
let url = sprintf "https://bank.gov.ua/markets/exchangerates?date=%s&period=daily"
type Currency = HtmlProvider<"https://bank.gov.ua/markets/exchangerates?date=03.05.2020&period=daily", Culture = "ru-RU">
let dates =
[|1..30|]
|> Array.map (sprintf "%02d.04.2020")
@Szer
Szer / actor_bench.fs
Created May 23, 2020 10:17
Benchmark of memory footproing on sending myriad of messages to myriad of actors
module Bench
open System
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open Hopac
open Hopac.Infixes
open Akka.FSharp
[<SimpleJob(launchCount = 3, warmupCount = 3, targetCount = 5)>]
module AsyncResultModule
type AsyncResult<'a> = Async<Result<'a, exn>>
[<RequireQualifiedAccess>]
module AsyncResult =
// Few basic functions
let bind (f: 'a -> AsyncResult<'b>) (a: AsyncResult<'a>): AsyncResult<'b> =
@Szer
Szer / advent1.fs
Last active December 1, 2020 17:17
let data = set [| 1962; 1577; 1750; 1836; 1762; 1691; 1726; 1588; 1370; 1043; 1307; 1552; 1813; 1804; 1765; 1893; 1610; 764; 1512; 1404; 1711; 1000; 1694; 1546; 1880; 1721; 2006; 1787; 1510; 1850; 1420; 1712; 1926; 1707; 1983; 1680; 1436; 389; 1448; 1875; 1333; 1733; 1935; 1794; 1337; 1863; 1769; 1635; 1499; 1807; 1326; 1989; 1705; 1673; 1829; 1684; 1716; 456; 1696; 1398; 1942; 1851; 1690; 1328; 1356; 1775; 1564; 1466; 1273; 1896; 766; 1814; 1810; 1537; 1463; 1755; 1341; 1665; 1520; 1366; 1387; 1976; 1717; 1737; 1551; 1760; 1496; 1664; 1450; 1319; 1674; 1630; 1301; 1330; 1658; 1637; 1655; 1439; 1832; 1948; 1339; 1656; 1449; 1296; 1489; 1758; 1939; 1857; 1402; 1394; 1882; 1446; 1412; 1430; 1212; 1377; 1501; 1873; 1812; 1667; 1560; 1654; 1575; 1999; 1581; 1792; 1299; 1843; 1383; 1351; 1297; 1822; 1801; 1977; 1316; 1477; 1980; 1693; 1220; 1554; 1607; 1903; 1669; 1593; 1955; 1286; 1909; 1280; 1854; 2005; 1820; 1803; 1763; 1660; 1410; 1974; 1808; 1816; 1723; 1936; 1423; 1818; 1800; 1294; 857; 496; 1248; 1670; 1993
@Szer
Szer / kestrel_check.fs
Last active December 10, 2020 18:27
Checking Kestrel header parsing
open System
open System.Net
open System.Net.Http
open System.Net.Sockets
open System.Text
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
let writeResponse (ctx: HttpContext) =
@Szer
Szer / vahter_farmer.fs
Created December 15, 2020 15:03
Vahter Farmer Deployment
open System
open System.IO
open Farmer
open Farmer.Builders
open Medallion.Shell
let resourceGroup = "vahter-rg"
let acrName = "vahterregistry"
let logName = "vahter-log"
let appName = "vahter-app"
@Szer
Szer / encoding_bench.cs
Created January 4, 2021 17:00
Custom Base64 encoding benches
using System;
using System.Buffers;
using System.Globalization;
using System.Text;
using BenchmarkDotNet;
using BenchmarkDotNet.Attributes;
namespace BenchmarkSuite1
{