Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
hodzanassredin / uploadBigToBlob.cs
Created March 19, 2021 08:05
console tool to upload big file to blob
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.Threading.Tasks;
namespace CopyToBlob
{
open System
type Number = uint
let radixPointBits = 8
let minusOne = UInt32.MaxValue
let negateSlow (n:Number) : Number =
let mutable res = 0u
for i in 0u..n do
@hodzanassredin
hodzanassredin / math.fsx
Created January 8, 2021 22:41
Basick arithmetic opearations in fsharp
type Number = Zero | Succ of Lazy<Number>
let swap f a b = f b a
let toOption = function
| Zero -> None
| r -> Some(r)
let rec fold (f:('State -> 'State)) (state: 'State) (n: Number) : 'State =
match n with
@hodzanassredin
hodzanassredin / clickhouse.cs
Created December 18, 2020 14:01
simple clickhouse https connector
//dont forget to sudo update-ca-certificates after certificate download from yandex cloud
public class ClickHouseConnection
{
public string Host { get; }
public string User { get; }
public string Password { get; }
public string Db { get; }
public ClickHouseConnection(string host, string user, string password, string db)
@hodzanassredin
hodzanassredin / process_networks.fsx
Last active May 28, 2019 23:51
process networks from Field Harrison
//networks
let rec from x = Seq.unfold (fun x -> Some(x,x+1)) x
let rec filter n xs = Seq.filter (fun m -> (m % n) <> 0) xs
let rec sieve (xs:seq<int>) =
let m = Seq.head xs
seq{yield m; yield! sieve <| filter m (Seq.tail xs) }
@hodzanassredin
hodzanassredin / prolog.fs
Last active May 20, 2019 15:59
simple implementation of prolog in f#
let rec findSentence (matcher:'e->'a-> 'a-> bool * 'e) (matcherEnv:'e) (sentences:'a list list) (target:'a) =
printfn "searching target %A in %A" target sentences
match sentences with
| [] -> None
| (name::subTargets)::sentences ->
let matched, resMatcherEnv = matcher matcherEnv name target
if matched then Some(subTargets,sentences, resMatcherEnv)
else findSentence matcher matcherEnv sentences target
| _::t -> findSentence matcher matcherEnv t target
@hodzanassredin
hodzanassredin / fixed.fsx
Created April 15, 2019 13:22
fixed point arithmetic in fsharp
open System
let scale (n3: int16) (n2: int16) (n1: int16) : int16 = (int n1) * (int n2) / (int n3) |> int16
let percent = scale 100s
let percent20 = percent 20s
let r = percent20 50s//10s
@hodzanassredin
hodzanassredin / GuidToSN.fs
Created March 9, 2019 18:20
GuidToSN prototype
open System
open System.Collections.Generic
open Force.Crc32
open System.Text
open Murmur
open HashLib
let check keys e name =
let hsahes = new HashSet<string>()
let stopWatch = System.Diagnostics.Stopwatch.StartNew()
@hodzanassredin
hodzanassredin / Dijkstra.cs
Created June 8, 2018 14:46
Dijkstra task solution
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dkstra
{
class Program
@hodzanassredin
hodzanassredin / linTransform.fsx
Created October 4, 2017 10:43
image linear trnsformations
#r "System.Drawing.dll"
module Bitmap =
open System
open System.IO
open System.Drawing
open System.Drawing.Imaging
let toArray (image:Bitmap) =
Array2D.init image.Width image.Height (fun i j -> image.GetPixel(i,j))