Skip to content

Instantly share code, notes, and snippets.

View Szer's full-sized avatar

Ayrat Hudaygulov Szer

  • Thrive Global
  • Dublin, Ireland
  • X @omgszer
View GitHub Profile
@Szer
Szer / exn.fs
Created April 23, 2018 07:39
exn
exception StringMsgs of string list
exception IntMsgs of int list
try
raise <| StringMsgs [""]
with
| StringMsgs strList -> "strList"
| IntMsgs intList -> "intList"
| e -> "Everything else"
@Szer
Szer / perf.fs
Last active April 26, 2018 16:07
perf
#I @"C:\Repos\Hopac.IO\packages\Hopac\lib\net45"
#r "Hopac.dll"
#r "Hopac.Core.dll"
open System
open Hopac
open Hopac.Infixes
open Hopac.Stream
let rnd = Random()
@Szer
Szer / paket.dependencies
Created April 28, 2018 07:09
Azure Function Host dependencies
framework: netstandard2.0
source https://www.nuget.org/api/v2
source https://www.myget.org/F/azure-appservice/api/v2
source https://www.myget.org/F/30de4ee06dd54956a82013fa17a3accb/
source https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json
storage: none
nuget FSharp.Compiler.Service 13.0.0
nuget FSharp.Core 4.2.2
"debug.allowBreakpointsEverywhere": true,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "variable.other.binding.fsharp",
"name": "binding names",
"settings": {
"fontStyle": "bold",
"foreground": "#DCDCAA"
}
open FSharpx.Option
module String20 =
open System.Text.RegularExpressions
type T = String20 of string
let createWithCont success failure (s: string) =
if Regex.IsMatch(s,@"^\w{1,20}$")
then success (String20 s)
else failure "string length is more than 20"
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Print()
{
@Szer
Szer / CSharpBench.cs
Last active September 26, 2018 12:29
CSharpBench
private static async Task<T> Reduce<T>(Func<T, T, T> f, T[] ie, int start, int finish)
{
var len = finish - start + 1;
if (len == 0)
{
throw new Exception("Sequence contains no elements");
}
else if (len == 1)
{
return ie[start];
@Szer
Szer / FSharpBench.fs
Created September 26, 2018 12:29
FSharpBench
let reduceParallelAsync<'a> f (ie: 'a array) =
let rec reduceRec f (start, finish) =
let reduce = reduceRec f
async {
match (finish - start + 1) with
| 1 -> return ie.[start]
| 2 -> return f ie.[start] ie.[start+1]
| len ->
let h = len / 2 + start
let! o1a = reduce(start, h-1) |> Async.StartChild
@Szer
Szer / result.fold.fs
Last active October 3, 2018 14:52
Result fold
module Result =
let foldish xs =
let resFolder state curResult =
match state, curResult with
| Error err, _
| _ , Error err -> Error err
| Ok rs , Ok r -> Ok (r::rs)
Seq.fold resFolder (Result.Ok []) xs
|> Result.map List.rev
@Szer
Szer / single-du-converter.fs
Created November 11, 2018 18:06
Single DU converter
[<AutoOpen>]
module SingleDuConverter
open Newtonsoft.Json
open Microsoft.FSharp.Reflection
open System
open System.Collections.Generic
open Newtonsoft.Json.Linq
type SingleDuConverter() =