Skip to content

Instantly share code, notes, and snippets.

module FsTests.PartialApplication
let tupleAdd(a, b) =
//printf "test"
a + b
let curriedAdd a b =
a + b
let addOne = curriedAdd 1
module FsTests.PartialApplication
let tupleAdd(a, b) =
a + b
let curriedAdd a b =
a + b
let addOne = curriedAdd 1
var partitionNumber = CalculatePartition(key, data);
Producer.ProduceAsync(topicName, key, data, partitionNumber)
@dkholod
dkholod / KafkaPartitioner.cs
Last active March 4, 2019 14:22
KafkaPartitioner
var config = new ProducerConfig
{
Partitioner = Partitioner.Consistent
};
public enum Partitioner
{
Random, //random distribution
//CRC32 hash of key
@dkholod
dkholod / SDEvent.cs
Last active February 28, 2019 20:07
SDEvent
public class Event
{
public string Id { get; set; }
public string Type { get; set; }
public string EventName { get; set; }
public long TotalBets { get; set; }
@dkholod
dkholod / consumeWithKafkaBackPressure.fs
Last active March 1, 2019 11:21
consumeWithKafkaBackPressure
let consumeWithKafkaBackPressure(consumer: Consumer<byte[],byte[]>, lowPriorityPartitions, token: CancellationToken) =
let execOptions = ExecutionDataflowBlockOptions(MaxDegreeOfParallelism = 2,
BoundedCapacity = 100)
let flow = TransformBlock<_,_>(deserialize, execOptions)
let buffer = BufferBlock<string*Event>()
flow.LinkTo(buffer) |> ignore
while token.IsCancellationRequested do
@dkholod
dkholod / consumeWithBackPressure.fs
Last active March 1, 2019 11:16
consumeWithBackPressure
let consumeWithBackPressure(consumer: Consumer<byte[],byte[]>, token: CancellationToken) =
let execOptions = ExecutionDataflowBlockOptions(MaxDegreeOfParallelism = 2,
BoundedCapacity = 100)
let flow = TransformBlock<_,_>(deserialize, execOptions)
let buffer = BufferBlock<string*Event>()
flow.LinkTo(buffer) |> ignore
while token.IsCancellationRequested do
@dkholod
dkholod / loc.fsx
Last active June 12, 2017 07:53
Lines of code calculation F# script
// http://fsprojects.github.io/FSharp.Collections.ParallelSeq/
#r "FSharp.Collections.ParallelSeq.dll"
open FSharp.Collections.ParallelSeq
open System.IO
let linesOfCode path =
DirectoryInfo(System.IO.Path.GetDirectoryName path)
.GetFiles(Path.GetFileName path, SearchOption.AllDirectories)
|> PSeq.map (fun f -> File.ReadAllLines(f.FullName).Length)
|> PSeq.reduce (+)
@dkholod
dkholod / snakePrint.fsx
Last active April 5, 2017 10:47
Snake print
// Probably not the best ever solution but a) easy to understand b) do not create/mutate array(s)
type Direction =
| LeftRight
| TopBottom
| RightLeft
| BottomTop
let snakePrint (array: int[,]) =
let len = array |> Array2D.length1
@dkholod
dkholod / CapitalsQuiz_view_helper_func.elm
Created October 7, 2016 21:20
CapitalsQuiz the view helper function
status : Status -> Html a
status st =
let ( color, txt ) =
case st of
Right s -> ( "green", "Right. " ++ s )
Wrong s -> ( "red", "Wrong! " ++ s )
None -> ( "", "" )
in
div [ style [ ( "color", color ) ] ] [ text txt ]