Skip to content

Instantly share code, notes, and snippets.

View OmanF's full-sized avatar
😎
Dude, do you even do Functional Programming?!

O.F.K. OmanF

😎
Dude, do you even do Functional Programming?!
View GitHub Profile
@OmanF
OmanF / psqlProvider.fs
Last active May 18, 2025 10:08
Example using F#'s SQL type provider `SQLProvider`, specifically with PSQL/CockroachDB connection and `query` computation expression
// Don't forget `FSharp.Data`, `Npgsql`, and `SQLProvider` packages in your project references (e.g. via `paket add` or `dotnet add`)
open FSharp.Data.Sql
[<Literal>]
let connString =
"Host=<host URL>;Port=26257;Database=vavm;Username=root"
type sql = SqlDataProvider<Common.DatabaseProviderTypes.POSTGRESQL, connString, "Common.NullableColumnType.OPTION">
let ctx = sql.GetDataContext()
@OmanF
OmanF / paginatedApiResponse.fsx
Last active September 21, 2025 10:28
Iterative, stack-safe, handling of paginated API response
(*
Handling a paginated REST API endpoint response in an optimized, iterative (i.e., stack-safe), tail-recursive, manner.
While the approach is general, the implementation details are concrete, but easily swapable.
Specifically, for each page of the response, and given the response conforms to the types defined, find any item, in this case CVE(s), that appears in both groups, `activeCves` and `closedCves` - that would indicate an issue with the logic of handling closed, and reopened, CVE(s).
Accumulate responses from every page, until finished, and display a summary of the finding.
Lastly, robust error handling is in place, handling possible failure to query the (remote) endpoint in a graceful way.
*)
@OmanF
OmanF / graphDbsContainerStartup.md
Last active August 1, 2025 04:05
ArangoDB and SurrealDB container startup examples

Example CLI commands to start containerized (via Docker/Podman) instances of ArangoDB and SurrealDB

ArangoDB

  • This will set up an ArangoDB instance with default port forwarding, i.e., port 8529 on the container (default ArangoDB port) will be mapped to port 8529 on the host.
  • Make sure the volume (e.g. arangoDbData) exists on the host prior to trying to mount it (and do not change the destination path on the container unless you know what you're doing!)
  • To make sure a fresh image is always used, add --pull always anywhere in the parameter-defintion section of the command (i.e., before declaring which image to use, e.g., the very last arangodb).
  • Set your ARANGO_ROOT_PASSWORD in the environment variable, or use ARANGO_NO_AUTH=1 for a non-authenticated ArangoDB instance (not recommended even for testing!), or use ARANGO_RANDOM_ROOT_PASSWORD=1 and check the container logs for the generated password.
  • Example: always pull the default ArangoDB image, and run it with a user-
@OmanF
OmanF / createCollectionsWithFsCheck.fsx
Last active February 25, 2025 21:41
Using FsCheck's statistical generators to create collections
#r "nuget: FsCheck"
// module CreateStatisticalCollectionsWithFsCheck
open FsCheck
// FsCheck has a built-in function to choose random elements out of a collection with uniform distribution, i.e., equal chance of pulling any element of the collection: Gen.oneof.
let createUniformDistributedList n aSeq =
aSeq
|> Seq.map (fun elem -> gen { return elem })
@OmanF
OmanF / assertionLibraries.fsx
Last active February 25, 2025 21:41
Incorporating different assertion libraries with `Expecto`
#r "nuget: Expecto"
#r "nuget: Swensen.Unquote"
#r "nuget: Shouldly"
// module AssertionLibrariesExpectoIntegration
open Expecto
open Swensen.Unquote
open Shouldly
@OmanF
OmanF / ucCasesNamesToStringAndBack.fsx
Last active February 24, 2025 08:27
Convert between UC's case(s) name(s) to string(s), and string(s) to UC case(s)
module ConvertUnionCasesToStringAndBack
open FSharp.Reflection
// **Important**
// All reflective function in this module will succeed only for union cases that have no fields, e.g., type Blah = A | B
// In case of a union case that does have a field, e.g., type Blah = | A of int, an attempt to convert to, or from, that case will fail!
// See https://stackoverflow.com/questions/46334181/how-do-i-get-a-discriminated-union-case-from-a-string for an initial idea on how to solve this.
// Turn a union case to its string representation.