Skip to content

Instantly share code, notes, and snippets.

@atsapura
atsapura / appEnv.fs
Created September 1, 2023 16:31
App Env example with test env
type IAppEnv =
abstract member Now: Instant
abstract member OrderDiffStorage: IOrderDiffStorage
abstract member DomainOrderStorage: IOrderStorage
abstract member OrderEventSender: IOrderEventSender
abstract member CatalogClient: ICatalogClient
abstract member ErpOrderListener: IErpOrderListener
abstract member Config: Config
type AppEnv(diffStorage: IOrderDiffStorage,
@atsapura
atsapura / CleanSolution.fs
Created October 1, 2021 09:36
proper clean of .net solution
open System.IO
let deleteBinAndObj (dirInfo: DirectoryInfo) =
let bin = dirInfo.GetDirectories("bin")
for dir in bin do
if dir.Name.ToLower() = "bin" then
dir.Delete(true)
let objDirs = dirInfo.GetDirectories("obj")
for dir in objDirs do
if dir.Name.ToLower() = "obj" then
dir.Delete(true)

Programming for a non programmer

A while ago I was thinking about how to explain what it feels like to do programming to a non-programmer. So, this is what I came up with, and hopefully you’ll find it entertaining.


Essentially, programming is automating things using computer. The greatest power and the greatest weakness of computer is that it does exactly what you told it to, no more, no less. Which means, that on the one hand, it doesn’t get tired, doesn’t lose focus and doesn’t complain. On the other hand, you have to give it very detailed and specific instructions. Because of that even if the task in real life appears to be quite simple and strait forward, programming it can become a bit tricky. Consider an example: let’s say I ask you – a human – to buy groceries for spaghetti carbonara. Now, you probably don’t keep the recipe at the top of your head, so you ask me what products exactly do I need. Then you go to the grocery store and you find out that there’s no spaghetti left, but there’s some l

[<RequireQualifiedAccess>]
module Array =
let private swap (arr: _[]) i j =
let buf = arr.[i]
arr.[i] <- arr.[j]
arr.[j] <- buf
let permutations arr =
match arr with
@atsapura
atsapura / Floc.fs
Created September 20, 2020 15:50
Count fsharp lines of code in your project!
open System
open System.IO
type FSharpCodeLine =
| NamespaceDeclaration
| Open
| Comment
| Source
| Brace
@atsapura
atsapura / GuaranteedDeliveryActor.fs
Created September 9, 2020 16:40 — forked from object/GuaranteedDeliveryActor.fs
Guaranteed delivery actor in Akka.NET/F#
module GuaranteedDelivery =
open Akka.Actor
open Akka.Persistence
open Akkling
open Akkling.Persistence
type Payload = string
type DeliveryEnvelope = { Payload: Payload; DeliveryId: int64 }
@atsapura
atsapura / AppEnvExample.fs
Created August 4, 2020 13:23
An example of managing application dependencies with `IAppEnv` interface from a real application.
type CosmosDbConfig =
{
Endpoint: string
AuthKey: string
}
type ProductBlobConfig =
{
ConnectionString: string
ContainerName: string
namespace Fsion
open System.Threading
[<Struct;NoEquality;NoComparison>]
type Cancel =
private
| Cancel of bool ref * children: Cancel list ref
module internal Cancel =
let (|CosmosException|_|) (ex:exn) =
match ex with
| :? DocumentClientException as ex -> Some ex
| :? AggregateException as ex when (ex.InnerException :? DocumentClientException) ->
ex.InnerException :?> DocumentClientException |> Some
| _ -> None
let (|NotFoundInCosmos|_|) ex =
match ex with
| CosmosException ex when (ex.StatusCode = Nullable HttpStatusCode.NotFound) -> Some ex
@atsapura
atsapura / HexGrid.fs
Created April 14, 2020 11:27
Hex grid using cubical coordinates.
module HexGrid =
[<Struct>]
type HexId =
{
X: int
Y: int
Z: int
}
with