Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
hodzanassredin / constraints.fsx
Created April 29, 2023 15:09
constraints framework
type Message = | IHaveAValue
| ILostMyValue
[<ReferenceEquality>]
type Constraint = Constraint of (Message -> unit)
let forEachExcept (except:obj) (procedure: Constraint -> unit) (list: Constraint list) =
let rec loop (items: Constraint list) =
match items with
| [] -> ()
| h::t when System.Object.ReferenceEquals(h,except) -> loop t
@hodzanassredin
hodzanassredin / circuit.fsx
Created April 29, 2023 09:51
cicuits in fsharp
type Action = unit->unit
type Wire = (bool ref) * (Action list ref)
let getSignal ((s,_):Wire) : bool = s.Value
let setSignal ((s,fs):Wire) (signal:bool) =
if s.Value <> signal
then s.Value <- signal
List.iter (fun f->f()) fs.Value
@hodzanassredin
hodzanassredin / prolog.fsx
Last active April 28, 2023 07:38
sicp prolog reimplemented in fsharp
type Stream<'a> = | Nil | Cons of 'a * Lazy<Stream<'a>>
module Stream =
let cons a b = Cons(a,b)
let singleton a = cons a (Lazy.CreateFromValue(Nil))
let empty = Nil
let isEmpty = function
| Nil -> true
| Cons(a,_) -> false
@hodzanassredin
hodzanassredin / constrainedUKanren.fsx
Last active April 20, 2023 18:41
uKanren implementation in fsharp as cloase as possible to original http://webyrd.net/scheme-2013/papers/HemannMuKanren2013.pdf. You can find more f#-y version here https://github.com/palladin/logic
type Var = VarC of int
type ObjT =
| Int of int
| Str of string
| Bool of bool
| Null
type Term =
| Var of Var
@hodzanassredin
hodzanassredin / scipy.py
Created January 16, 2023 08:11
game of life and other scipy stuff
# %%
from skimage import io
import numpy as np
import matplotlib.pyplot as plt
url_astronaut = ('https://raw.githubusercontent.com/scikit-image/scikit-image/'
'master/skimage/data/astronaut.png')
astro = io.imread(url_astronaut)
print("Type:", type(astro), "Shape:", astro.shape, "Data type:", astro.dtype)
@hodzanassredin
hodzanassredin / Complex.cps
Last active January 4, 2023 22:07
Complex number in component pascal
MODULE QuantumComplex;
IMPORT Log, Math;
TYPE
Complex = RECORD
r,i:REAL
END;
PROCEDURE (VAR c: Complex) Init*(r,i:REAL), NEW;
namespace ConsoleApp7
{
public class AsyncMonitor
{
private readonly SemaphoreSlim signal = new SemaphoreSlim(1, 1);
public void Exit()
{
try
@hodzanassredin
hodzanassredin / blobMd5.cs
Created April 8, 2021 07:48
calc md5 sum for a files in a blob storage (azure data lake gen2)
using Azure.Storage;
using Azure.Storage.Files.DataLake;
using Azure.Storage.Files.DataLake.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
namespace CopyToBlob
@hodzanassredin
hodzanassredin / airMaster2.fsx
Created April 5, 2021 08:05
reading sensor data from air master 2 air quality monitor
#r "nuget: FSharp.Charting, 2.1.0"
#r "nuget: System.Windows.Forms, 4.0.0"
#r "System.Windows.Forms.DataVisualization"
#r "nuget: FSharp.Control.Reactive, 5.0.2"
open System
open FSharp.Control.Reactive
open FSharp.Charting
open System.IO.Ports
@hodzanassredin
hodzanassredin / package.json
Created March 19, 2021 08:59
sanddance react example
{
"name": "project1",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.1.3",
"jquery": "^3.4.1",
"merge": "^1.2.1",
"oidc-client": "^1.9.0",
"react": "^16.0.0",