Skip to content

Instantly share code, notes, and snippets.

View altbodhi's full-sized avatar
🏠
Working from home

altbodhi

🏠
Working from home
View GitHub Profile
@altbodhi
altbodhi / diskStatusChecker.fsx
Created September 3, 2020 02:58
Прототип новой функциональности на F# глазами C#-программиста
open System
open System.Threading
let rnd = Random(Environment.TickCount)
let disks = [ 1; 2; 3; 4 ]
type Status =
| Fail of int
| Normal of int
public sealed class ValidateResult : Result<bool, string>
{
}
public abstract class Result<TValue, TError>
{
public bool IsOk => this is Ok;
public sealed class Ok : Result<TValue, TError>
{
public TValue Value { get; }
@altbodhi
altbodhi / simple-macros.lisp
Created January 11, 2021 06:51
macro for generete same writeln as in pascal
(defmacro writeln (&rest args)
`(progn
(loop for e in '(,@args)
do
(format t "~A" e))
(format t "~%")))
(defstruct person name)
(defgeneric hello (obj)
@altbodhi
altbodhi / rollup.config.js
Created February 15, 2021 09:02
svelte rolling config for multi pages (for example for mixin to asp.net core webapp)
const page = "syncSystems";
// "index";
export default {
input: `src/${page}.ts`,
output: {
sourcemap: true,
exports : 'named',
format: 'iife',
@altbodhi
altbodhi / CSharpMailBoxProcessor.cs
Created March 12, 2021 06:43
CSharp MailBoxProcessor inspired F#
using System;
using static System.Console;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using System.Threading;
using System.Collections.Generic;
namespace CSharpMailBoxProcessor
{
public class Reply
type State =
| Ping
| Pong
type Command = | Send
type Event = | Received
let apply item =
function
@altbodhi
altbodhi / ConsoleUtils.fsx
Created February 9, 2022 03:53
Модульный подход к разработке на примере программы на языке F#
let color col =
let old = System.Console.ForegroundColor
System.Console.ForegroundColor <- col
{ new System.IDisposable with
member it.Dispose() = System.Console.ForegroundColor <- old }
let red () = color System.ConsoleColor.Red
let cyan () = color System.ConsoleColor.Cyan
let green () = color System.ConsoleColor.Green
@altbodhi
altbodhi / app.nproj
Created July 6, 2022 07:08
minimal proj file for nemerle under dotnet core
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoStdLib>True</NoStdLib>
<OutputType>exe</OutputType>
<OutputPath>bin</OutputPath>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>6.0</TargetFrameworkVersion>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
@altbodhi
altbodhi / skip_loop.n
Created July 13, 2022 13:07
The skip loop with Nemerle.
using System.Console;
def skip_loop(counter, skip, max, idx, lst) {
if (idx >= max) lst
else
if ( counter >= skip )
skip_loop(1, skip, max, idx + 1, idx :: lst)
else
skip_loop(counter + 1, skip, max, idx + 1, lst)
}
@altbodhi
altbodhi / micro_bench.n
Created July 14, 2022 02:39
Compare two equivalent of skip loop function with different paradigm: imperative and functional
using System;
using System.Console;
using System.Collections.Generic;
using System.Diagnostics;
def skip_loop(counter, skip, max, idx, lst) {
if (idx > max) lst
else
if ( counter >= skip )
skip_loop(1, skip, max, idx + 1, idx :: lst)