Skip to content

Instantly share code, notes, and snippets.

View tjaskula's full-sized avatar
🎸
C++

Tomasz Jaskula tjaskula

🎸
C++
View GitHub Profile
@tjaskula
tjaskula / PollingService.fs
Last active August 29, 2015 13:56
Trying to set up an Azure worker role with an asynchronous workflow for a polling service. The problem is that the role starts well and after some time becomes unresponsive. I don't know exactly what's the issue as in intellitrace there's no explicit exception. Do you see any problem here which may lead to this unstable situation ? After Mark an…
module PollingService
open System.Diagnostics
let poll interval work =
let sw = Stopwatch()
let rec loop() =
async {
sw.Restart()
work()
@tjaskula
tjaskula / Application.fs
Last active August 29, 2015 13:56
Is this considered a bad practice, using a hard dependency inside a function. Something like ServiceLocator anti pattern in OOP ?
// And here is how both of them are composed in a higher level module so I can pass in another function without hard dependency for testing
let keys = [| "SOclient_id"; "SOscope"; "SOredirect_uri"|]
let queryParameters = readConfigApi keys readConfigurationValue
@tjaskula
tjaskula / cqs samples
Last active August 29, 2015 14:05
I tend to avoid breaking CQS principe in OOP. But there are sometimes cases that it would be possible to do it for a simpler code.
//1. breaking CQS
var sor = new SimpleOrderRouting();
var orderConfirmation = sor.Route(new OrderRequest(..));
bool isOrderExecuted = orderConfirmation.ExecutionCompleted;
//2. adhering to CQS not blocking
var sor = new SimpleOrderRouting();
@tjaskula
tjaskula / StepScript.fs
Last active February 4, 2018 19:20
Fsharp coding dojo
// 1. Define order types
type OrderRef = string // placeholder for a more complicated typ
type OrderItem = OrderItem of string
type PaymentReceipt = {OrderRef : OrderRef; PaidAmount : decimal}
// 2. define states
type EmptyState = NoItems of OrderRef
// Udi style w Static Domain Events
var dispatcher = new RecordingDomainEventsDispatcher();
DomainEvents.Dispatcher = dispatcher;
var customer = new Customer(new Address());
customer.Move(new Address());
Console.WriteLine("Customer moved: " + dispatcher.RecordedDomainEvent(new CustomerMoved()));
@tjaskula
tjaskula / Steps2.fsx
Last active August 29, 2015 14:14
F# DAP
// 1 step.
type Order with
static member NewOrder = fun orderRef -> Order.Empty (NoItems orderRef)
// 2 step replace "=" with "with" in the first step
type Order =
| Empty of EmptyState
| PaymentExpected
| Payed
| Cancelled
@tjaskula
tjaskula / euler.fs
Last active August 29, 2015 14:16
Euler
let rec split<'T> (input: 'T array) size =
let rec loopOn (tail : 'T array) grouped =
let lastIndex = Array.length tail - 1
let endindx = min (size - 1) lastIndex
let arrWrapper = (fun e -> [|e|])
let newGroup = tail.[0..endindx]
|> List.ofArray
|> arrWrapper
|> Array.append grouped
@tjaskula
tjaskula / Parsers.cs
Last active August 29, 2015 14:21
Defining SelectMany method's signature for Parser type
var p1 = startSriper.ToParser();
var p2 = endSriper.ToParser();
var composite = p1.Compose(p2);
var result2 = composite(content);
var parsers = from a in p1
from b in p2
select b;
@tjaskula
tjaskula / PriorityQueue.fs
Created December 9, 2016 00:07
mutable priority queue in F#
open System
open Microsoft.FSharp.Core
// maybe there is a better way to simplify this
let private (|Greater|_|) descendent compareResult =
match compareResult with
| n when n < 0 && descendent -> None
| n when n < 0 && not descendent -> Some()
| 0 -> None
| n when n > 0 && descendent -> Some()
@tjaskula
tjaskula / NesGateway.fs
Created May 7, 2017 13:42 — forked from bartelink/NesGateway.fs
Dump of ProtoBuf serialization spike for http://github.com/bartelink/FunDomain
module FunDomain.Persistence.NEventStore.NesGateway
open FunDomain.Persistence.Serialization
open NEventStore
open NEventStore.Persistence
open NEventStore.Persistence.Sql.SqlDialects
open Microsoft.FSharp.Reflection
open System