Skip to content

Instantly share code, notes, and snippets.

View ruxo's full-sized avatar

Ruxo ruxo

  • Bangkok
View GitHub Profile
@ruxo
ruxo / test_akka.fsx
Last active February 9, 2023 23:16
Summary: The target actor can still be used normally even the actor was crashed.
#r "nuget: Akka.FSharp"
open System
open Akka.FSharp
let system = Configuration.defaultConfig() |> System.create "test"
type Messages =
| Print of string
| Crash
using MongoDB.Bson; // MongoDB.Bson, MongoDB.Driver
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using RZ.Foundation.Extensions; // RZ.Foundation
using static LanguageExt.Prelude; // LanguageExt
namespace YourNameSpace
{
public class MongoOptionSerializer<T> : SerializerBase<Option<T>>
@ruxo
ruxo / Program.cs
Last active December 29, 2022 12:12
Note, MongoDB only serializes properties, no fields.
// reference MongoDB.Driver 2.11.0
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Driver;
void Main()
{
var client = new MongoClient("mongodb://connection");
var collection = client.GetDatabase("test").GetCollection<Test>("test");
@ruxo
ruxo / Program.cs
Last active December 29, 2022 12:12
Result: Calling `Dispose()` on the iterator can dispose the resource inside even the iterator's code seems never return.
void Main()
{
var itor = InfiniteOne();
var iter = itor.GetEnumerator();
iter.MoveNext();
Console.WriteLine("Value is {0}", iter.Current);
iter.Dispose();
}
static IEnumerable<int> InfiniteOne(){
@ruxo
ruxo / TiraxTech.Http.fs
Last active February 9, 2023 23:13
F# HTTP module
module TiraxTech.Http
open System
open System.Threading.Tasks
open System.Net
open System.Net.Http
open System.Net.Http.Json
open System.Text.Json
open System.IO
open System.Net.Http.Headers
@ruxo
ruxo / fix_uk_keyboard.fsx
Last active February 9, 2023 23:16
For Windows 10 & 11: Remove unwanted UK keyboard from Windows glitch!
open Microsoft.Win32
module Keyboard =
let ThaiKeyboard = ["0000041e"]
let USKeyboard = ["00000409"]
let UKKeyboards = ["00000809"; "d0010409" ]
let OurDesiredKeyboards = [ThaiKeyboard; USKeyboard] |> List.collect id
let WellknownKeyboards = [ThaiKeyboard; USKeyboard; UKKeyboards] |> List.collect id
let isUK v = UKKeyboards |> List.contains v
@ruxo
ruxo / LimitController.cs
Created November 19, 2021 10:48
Simple Rate Limit 1 call per 2 seconds.
using System.Net;
using Microsoft.AspNetCore.Mvc;
namespace SimpleSlidingWindow.Controllers;
[ApiController]
[Route("[controller]")]
public class LimitController : ControllerBase
{
@ruxo
ruxo / taskSeq.fs
Last active February 9, 2023 23:13
F# Task Sequence implementation attempt..
module rec TiraxTech.Foundation
open System
open System.Collections.Generic
open System.Threading.Tasks
open IdentityServer4.Models
open TiraxTech.Foundation
module AsyncEnumerator =
let Empty<'T>() = { new IAsyncEnumerator<'T> with
open System
open System.Text.RegularExpressions
let private encodingMatch (m: Match) =
match m.Value[0] with
| '+' -> "-"
| '/' -> "_"
| _ -> m.Value
let private decodingMatch (m: Match) =
var psi = new ProcessStartInfo
{
FileName = "mongo",
Arguments = $"{tlsSupport} --quiet --eval \"{query}\"",
CreateNoWindow = true,
RedirectStandardOutput = true
};
var procQuery = new Process
{