Skip to content

Instantly share code, notes, and snippets.

View ruxo's full-sized avatar

Ruxo ruxo

  • Bangkok
View GitHub Profile
@ruxo
ruxo / fp.py
Created June 16, 2016 17:07
FP lib
def identity(x): return x
def side_effect(f):
def _from(x):
f(x)
return x
return _from
@ruxo
ruxo / all_path.fsx
Last active February 9, 2023 23:17
Show all possible paths in a directional graph with each vertex can be visited once.
type TravelMode =
| Walk
| Bus
| MRT
| BTS
| Motorbike
| Taxi
[<Measure>] type baht
[<Measure>] type minute
@ruxo
ruxo / testquote.fsx
Last active February 9, 2023 23:16
F# quote extraction example.
open System
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.DerivedPatterns
let rec testQuote (tab: int) (expr: Expr) =
let p = printfn "%s%s" (String(' ',tab*2))
match expr with
| Int32 i -> p <| sprintf "Int %d" i
@ruxo
ruxo / data.task.d.ts
Last active May 27, 2017 07:30
FP prelude for TypeScript
declare module "data.task" {
type Func<A,B> = (_:A) => B
class Task<TFail,TOk> {
constructor(f: (reject: Func<TFail,any>, resolve: Func<TOk,any>) => void)
static of<TFail,TOk>(v: TOk): Task<TFail,TOk>
static rejected<TFail,TOk>(v: TFail): Task<TFail,TOk>
map<C>(f: Func<TOk,C>) :Task<TFail,C>
@ruxo
ruxo / backup.ps1
Created April 24, 2017 07:27
Powershell
cd W3SVC1
$now = Get-Date
$today = $now.Date
$date_groups = Get-ChildItem *.log | where { $_.Length -gt 0 -and $_.LastWriteTime.Date -lt $today } | group { $_.LastWriteTime.Date }
cd ..
foreach($g in $date_groups){
$date = $g.Values[0]
$name = "iis_logs-$($date.Year)$($date.Month.ToString("D2"))$($date.Day.ToString("D2"))"
$files = $g.Group
$cmd = "7z a -t7z -mx=9 -mmt=4 -sdel $($name) $($files)"
@ruxo
ruxo / parse.fsx
Last active February 9, 2023 23:16
Parse IIS Log
open System
open System.Net
open System.IO
type LogLine =
{ Timestamp: DateTime
Method: string
Path: string
Query: string
HttpVersion: string
@ruxo
ruxo / Program.cs
Created August 22, 2020 08:37
Sample of C# MongoDB with Immutable classes
// 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 / FsApi.Extensions.fs
Last active February 9, 2023 23:13
Akka.NET extension for F# with runAsync function
namespace Akka.FSharp.Extensions
open Akka.Dispatch
open System.Threading.Tasks
// source: https://github.com/tjaskula/akka.net-fsharp.extensions/blob/master/src/Akka.FSharp.Extensions/FsApi.Extensions.fs
module Actor =
open Akka.Actor
@ruxo
ruxo / AkkaExtension.fs
Last active February 9, 2023 23:13
(temp) F# Akka extension
module RZ.FSharp.Akka.Extension
open System.Threading.Tasks
open Akka.Actor
open Akka.FSharp
open System.Runtime.CompilerServices
type ReceiveActorFs() =
inherit ReceiveActor()
@ruxo
ruxo / test_akka.fsx
Last active February 9, 2023 23:16
Test ActorRef validity of Akka.NET after the target actor is crashed
#r "nuget: Akka.FSharp"
open System
open Akka.FSharp
let system = Configuration.defaultConfig() |> System.create "test"
type Messages =
| Print of string
| Crash