Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
@debasishg
debasishg / dod.md
Last active November 4, 2024 12:49
Data oriented design, hardware awareness, cache awareness in data structures & algorithms
@debasishg
debasishg / fix.md
Created September 30, 2024 16:10
fix for error in cargo build with rdkafka

The error you're encountering seems to occur during the build process for librdkafka, which is being built and linked statically as part of your Rust project that uses the rdkafka crate. Here's a breakdown of possible causes and solutions:

1. Resource temporarily unavailable (make[1]: *** read jobs pipe: Resource temporarily unavailable.)

This error suggests that the build process is hitting some system resource limits, possibly related to the number of parallel jobs make is trying to run. The default behavior of make is to run jobs in parallel, which can sometimes overwhelm system resources.

Solution: Try limiting the number of jobs make runs in parallel by setting the MAKEFLAGS environment variable:

export MAKEFLAGS="-j1"
#[derive(Debug)]
enum MyError {
Io(std::io::Error),
Parse(pest::error::Error<Rule>),
}
#[derive(Debug)]
struct StoreError(MyError);
impl std::fmt::Display for StoreError {
@debasishg
debasishg / trait_bound.md
Last active January 23, 2024 05:51
Rust Idiom (Trait Bounds)

Trait Bounds

Trait bounds in Rust are really powerful and also offers lots of idiomatic ways to constrain your model. Bounds are for enforcing constraints even in other languages like Scala, but Rust offers them at a different level.

Here's one example from the book Rust for Rustaceans (a great book BTW).

Suppose you want to construct a HashMap<K, V, S>, whose keys are some generic type T, value is a usize, you can write bounds like T: Hash + Eq, S: BuildHasher + Default.

pub fn doit<T>(value: T)
@debasishg
debasishg / ocaml-domain-modeling.md
Last active November 16, 2023 14:07
OCaml domain modeling

Abstraction and Parametricity implementing domain models in OCaml

One of my favorite comments on abstraction and parametricity ..

Parametricity can be thought of as the dual to abstraction. Where abstraction hides details about an implementation from the outside world, parametricity hides details about the outside world from an implementation.

When using OCaml as the implementation language, you abstract using ADTs (Abstract Data Types) and make your abstraction parametric using functors. And bind all of the algebras together using Modules.

Abstraction

(* Modules - the signature of functions and types with no
implementation whatsoever. Pure interfaces. *)
module type OrderedType = sig
type t
val compare : t -> t -> int
end
(* Note we don't specify any representation for the implementation of a
[heap]. Just the facts that define a heap - an ordered element, an
abstract type and a bunch of functions *)
@debasishg
debasishg / exists.ml
Created October 12, 2023 16:47 — forked from jonsterling/exists.ml
existential quantifier in OCaml
(* an abstract signature for instantiations of the existential quantifier *)
module type EXISTS =
sig
(* the predicate *)
type 'a phi
(* the existential type *)
type t
(* the introduction rule *)
@debasishg
debasishg / algebraic.md
Last active October 26, 2023 23:11
a brief intro to algebraic domain modeling

Algebraic Domain Modeling

When we talk about the algebra of an operation, we talk about the signature of the operation, and how, starting from the input, we can just "follow the types" to lead to the implementation of that operation.

Consider the following operation generateTrades as part of a domain service TradingService. The idea is to generate all trades that happened on the day (input to the operation) and executed by the user (input to the operation) in the back-office of a securities trading organization.

In the example below, note the following 2 principles that form the core of the algebraic modeling:

  1. The sequence of steps mentioned in the specification of the method as comments and correspond one-to-one to the types of the operations used in implementing generateTrades. I have annotated the steps in the implementation below.
  2. The implementation of generateTrades is completely decoupled from the implementation of the operations like queryExecutionsForDate, `getAccountNoF
@debasishg
debasishg / cache-oblivious.md
Last active September 2, 2024 07:20
Papers related to cache oblivious data structures

Cache Oblivious and Cache Aware Data Structure and Algorithms

  1. Cache-Oblivious Algorithms and Data Structures - Erik Demaine (One of the earliest papers in cache oblivious data structures and algorithms that introduces the cache oblivious model in detail and examines static and dynamic cache oblivious data structures built between 2000-2003)

  2. Cache Oblivious B-Trees - Bender, Demaine, Farch-Colton (This paper presents two dynamic search trees attaining near-optimal performance on any hierarchical memory. One of the fundamental papers in the field where both search trees discussed match the optimal search bound of Θ(1+log (B+1)N) memory transfers)

  3. Cache Oblivious Search Trees via Binary Trees of Small Height - Brodal, Fagerberg, Jacob (The data structure discussed in this paper works on the version of [2] but avoids the use o