Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
hodzanassredin / azure_cli.py
Last active November 12, 2015 10:47
python wrapper for azure cli
# -*- coding: utf-8 -*-
import subprocess
import logging
import tempfile
import json
import datetime
azure_cli = "\"C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI\\wbin\\azure.cmd\""
def exec_azure_cli_cmd(cmd, skip_start_lines, input = ""):
// C#
// public class Test {
// public FSharpSet<int> SetNull { get; set; }
// }
let s : Set<int> = (new Test()).SetNull
//or let s : Set<int> = Unchecked.defaultof<Set<int>>
//The type 'Set<int>' does not have 'null' as a proper value
@hodzanassredin
hodzanassredin / three.fs
Created June 10, 2015 09:00
funscript three.js test
[<ReflectedDefinition>]
module Program
open FunScript
open FunScript.TypeScript
let main() =
let scene : THREE.Scene = THREE.Scene.Create()
let camera = THREE.PerspectiveCamera.Create( 75., Globals.window.innerWidth / Globals.window.innerHeight, 0.1, 1000. );
@hodzanassredin
hodzanassredin / fun3d.fsx
Last active August 29, 2015 14:22
Tower of Hanoi
let countOfDisks = 10
let initialState = [for x in 1..countOfDisks do yield x], List.empty, List.empty
let bottDiskSize = 4.
let cylHeight = 4.0
let diskSize size = size * bottDiskSize / float(countOfDisks)
let diskHeight = cylHeight / float(countOfDisks)
let diskPosition pos = pos * diskHeight
let cyl =
open System.Net
open System
type System.Net.Sockets.UdpClient with
member x.AsyncSend (bytes: byte[]) =
Async.FromBeginEnd((fun (ar, s) -> x.BeginSend(bytes, bytes.Length, ar, s)), x.EndSend)
member x.AsyncReceive (endPoint: IPEndPoint ref) =
Async.FromBeginEnd(x.BeginReceive, fun ar -> x.EndReceive(ar, endPoint))
module Udp =
@hodzanassredin
hodzanassredin / TransAlt2.fs
Last active August 29, 2015 14:22
transalt on crdts
module Transaction =
open System
type CommitReciever = bool -> Async<unit>
let emptyReciever : CommitReciever= fun _ -> async.Return ()
let mergeRecievers (xs: CommitReciever seq) =
fun res -> async{
for x in xs do
do! x(res)
}
@hodzanassredin
hodzanassredin / ring-async.fs
Created June 8, 2015 09:04
ring threads benchmark async vs hopac job
open System
open System.Diagnostics
let ringLength = 503
let cells = Array.zeroCreate ringLength
let threads = Array.zeroCreate ringLength
let answer = ref -1
let createWorker i =
@hodzanassredin
hodzanassredin / inline.fs
Created May 28, 2015 16:23
inline shadows
open System
type Pure = Pure of unit
type Impure = Impure of unit
type M<'a,'p> = M of 'a
let purev x : M<_,Pure>= M(x)
let purev x : M<_,Impure>= M(x)
type ThingThatShows =
static member show(x: Option<Pure> ) = sprintf "pure"
static member show(x: Option<Impure>) = sprintf "impure"
@hodzanassredin
hodzanassredin / JoinDeadlock.fs
Created May 25, 2015 15:32
joinads deadlock
open FSharp.Joinads.Joins
open System
[<EntryPoint>]
let main argv =
// Construct channels implementing the buffer
let put = Channel<string>("put")
let put2 = Channel<string>("put2")
let get = SyncChannel<string>("get")
let get2 = SyncChannel<string>("get2")
@hodzanassredin
hodzanassredin / TransAlt.fs
Last active August 29, 2015 14:21
immutable alts
module Promise =
open System.Threading.Tasks
type Promise<'a> = {signal: 'a -> bool;
future : Async<'a>;
cancel : unit -> bool}
let create<'a> () =
let tcs = new TaskCompletionSource<'a>()
let ta: Async<'a> = Async.AwaitTask tcs.Task
{signal = tcs.TrySetResult;
future = ta;