Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
hodzanassredin / TritsSer.fsx
Last active October 1, 2017 01:55
Attempt to implement size efficient serializer based on trits
open System.Collections
open System
open System.Text
open System.Diagnostics
module Trits =
type Trit = Bit of bool | Split
let isNullable (x:Type) = x.IsGenericType && x.GetGenericTypeDefinition() = typedefof<Nullable<_>>
@hodzanassredin
hodzanassredin / BclBash.fs
Created May 9, 2017 22:24
bash like interface for BCL(fast and dirty)
open System
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
module Consoler =
open System.Reflection
open NReadability
open ReadSharp
@hodzanassredin
hodzanassredin / GAReport.cs
Last active December 13, 2016 09:51
c# google analytics api v3 sample
//based on https://github.com/LindaLawton/Google-Dotnet-Samples/tree/master/Google-Analytics
using System;
using System.Threading.Tasks;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Analytics.v3;
using Google.Apis.Analytics.v3.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Util;
@hodzanassredin
hodzanassredin / expvars.fsx
Last active September 3, 2016 16:05
expvars prototype for suave.io
// Step 0. Boilerplate to get the paket.exe tool
open System
open System.IO
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if (File.Exists "paket.exe") then
File.Delete "paket.exe"
let url = "https://github.com/fsprojects/Paket/releases/download/3.18.2/paket.exe"
@hodzanassredin
hodzanassredin / ddd.fsx
Last active June 13, 2016 15:02
attempt to express erik evans ddd in fsharp with cqrs and other concepts like aggregate roots
open System
[<AutoOpen>]
module Common =
open System.Collections.Generic
type Result<'TSuccess,'TFailure> =
| Success of 'TSuccess
| Failure of 'TFailure
let isInvalidString min max str =
@hodzanassredin
hodzanassredin / Imperative.cs
Last active May 23, 2016 08:08
ackermann imperative vs functional
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace Ack
{
@hodzanassredin
hodzanassredin / caps.fsx
Last active April 14, 2016 12:00
attempt to express capabilities as a monad
type RequestUser =
| Authenticated of id : int
| Anonymouse
type UserEntity = {
name : string
isAdmin : bool
}
open System.Collections.Generic
type Db = Dictionary<int,UserEntity>
import json
import datetime
import pytz
from random import randint
import logging
import time
import redis
main_prefix = "bqueues:"
@hodzanassredin
hodzanassredin / images.fsx
Created March 28, 2016 06:36
image processing comonad
[<AutoOpen>]
module Helpers =
let time name f a =
let stopWatch = System.Diagnostics.Stopwatch.StartNew()
let r = f a
stopWatch.Stop()
printfn "%s %f" name stopWatch.Elapsed.TotalMilliseconds
r
let arraySize arr = Array2D.length1 arr, Array2D.length2 arr
let safeGet i' j' (arr:_[,]) = try arr.[i',j'] with | ex -> Unchecked.defaultof<'a>
@hodzanassredin
hodzanassredin / algebra.fsx
Created March 9, 2016 15:08
solving expression problem in fsharp with object algebras
type ExpAlg<'a> =
abstract member lit: int -> 'a
abstract member Add: 'a -> 'a -> 'a
type Algebra<'alg,'a> = 'alg -> 'a
let lit i (alg:ExpAlg<'a>) = alg.lit i
let add a b (alg:ExpAlg<'a>) = alg.Add a b
type AlgebraBuilder() =