Skip to content

Instantly share code, notes, and snippets.

using System.Collections.Concurrent;
using System.Text.RegularExpressions;
using System.Threading.Channels;
string file = await new HttpClient().GetStringAsync(
"https://devblogs.microsoft.com/dotnet/performance_improvements_in_net_7/");
MatchCollection pullRequestUrls =
Regex.Matches(file, @"https:\/\/github.com\/[a-zA-Z-]+\/[a-zA-Z-]+\/pull\/[0-9]+");
let (|MessageTextAsEmoji|_|) (text: string) =
let isEmojiString (str:string) =
let mutable idx = 0
let mutable res = true
while(idx<str.Length) do
if(Char.IsHighSurrogate(str,idx) || Char.IsLowSurrogate(str,idx)) then
idx <- idx + 1
else
idx <- str.Length
res <- false
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
open System
open System.Threading
// Define a function to construct a message to print
type Msg =
| Print of string
[<EntryPoint>]
type Option = {Text:string;Limit:int}
type Poll={Title:string;Options:PollOption [];Answers: Map<int,string[]>}
[<RequireQualifiedAccess>]
module Poll=
let create title options = {Title=title;Options=options;Answers=Map.empty}
let toggle poll = create poll.Title Array.empty
[<Struct>]
type TlVector< ^T when ^T:(static member decodeFrom: BytesReader -> ^T) > =
{ Data: ^T array }
static member inline decodeBodyFrom (reader: BytesReader): TlVector< ^T> =
let data =
[| 1..reader.ReadVectorSize() |]
|> Array.map (fun _ -> readFrom reader)
{ Data = data }
type EventStream<'T> ()=
let evt=Channel.CreateUnbounded<'T>()
let writer = evt.Writer
let reader = evt.Reader
let mutable key = 0
let mutable subscriptions = Map.empty : Map<int, IObserver<'T>>
let thisLock = new obj()
let obs =
|Shape.Enum s->
s.Accept {
new IEnumVisitor<Convert<'T>> with
member __.Visit<'t ,'u when 't : enum<'u>
and 't : struct
and 't :> ValueType
and 't : (new : unit -> 't)>() =
let printer=
fun x->
let ts:'u = unbox<'t> x|>LanguagePrimitives.EnumToValue
module Shaper=
open LiteDB
open System
open TypeShape.Core
open TypeShape.Core.Utils
open LiteDB.FSharp
type Convert<'t> = {To:'t->BsonValue;From:BsonValue->'t}
let typeface=loadFont font
let lowerOrigin=new SKPoint(float32 (info.Width / 2),float32 (info.Height- info.Width / 2))
let upperOrigin=new SKPoint (float32 (info.Width / 2), float32 (info.Width/3))
let upperTextSize=float32 (info.Width/3)
let lowerTextSize=float32 (info.Width/2)
use textPaint = new SKPaint(Style = SKPaintStyle.Fill, Color = textColor.ToSKColor(), IsStroke=false,TextAlign=SKTextAlign.Center,TextSize=lowerTextSize,Typeface=typeface)
use unreadPaint = new SKPaint(Style = SKPaintStyle.Fill, Color = Color.Black.ToSKColor(), IsStroke=false,TextAlign=SKTextAlign.Center,TextSize=upperTextSize)
canvas.DrawCircle(lowerOrigin.X,lowerOrigin.Y,(float32 info.Width)/2.0f-1.0f, paint)
// canvas.DrawCircle(upperOrigin.X,upperOrigin.Y,float32(info.Width/3), wp)
canvas.DrawText(string txt,lowerOrigin.X,lowerOrigin.Y+lowerTextSize/2.0f ,textPaint)
namespace LiteDB.FSharp
open System.Reflection
open Newtonsoft.Json
open TypeShape.Core.Core
module Shaper=
open LiteDB
open System