Skip to content

Instantly share code, notes, and snippets.

View pavly-gerges's full-sized avatar
🤖
Electrostat Lab.

Pavly Gerges (pavl_g) pavly-gerges

🤖
Electrostat Lab.
View GitHub Profile
@pavly-gerges
pavly-gerges / graph-algo.md
Last active January 21, 2025 17:41
Graph Algorithms I

Graph Algorithms I

Outline:

  • Prerequisite Terminology.
  • Mathematical Structures for representing graphs.
  • Graph traversal algorithms.

Terminology:

  • Directed graph (Or Digraph): a directed path that is composed of vertexes and edges; where edges are essentially represented by directed arcs from a vertex (known as initial vertex) to another vertex (known as terminating or end vertex).
  • Undirected graph (or Multigraph): a non-directed path that is composed of vertexes and edges; where edges are represented by non-directed arcs from a vertex to another vertex (i.e., orientation of arcs are ignored).
  • Adjacency Matrix Representation:
// The following code examines multiple routines of definining dynamic buffers in C.
// This file fires a runtime malloc() error due to a HEAP corruption error; because of buffer overflow.
// Two maneuvers are introduced to fix this
#include <stdio.h>
#include <stdlib.h>
int main() {
// buffers
@pavly-gerges
pavly-gerges / MATH-C.md
Created October 27, 2024 20:02
A mathematical approach to coding in the C programming language.

A Mathematical Approach to coding in the C programming language: Scientific Coding

Preface:

This document is devoted to showing another perspective into programming, which in its surface is the scientific programming, but in its heart and core is really intricate. The complexity is imparted due to of the incorporation of mathematical models and their implementation to the syntatics of the programming language, unlike the practical OOP and Functional paradigms, the FSA model (Finite-Automata Model) is a theoretical model. However, in this short document, I am willing to show some caveats of using the FSM models in both low-level and high-level engineering and delivering a reliable software based on a true science.

Science behind the FSA models

The scientific basis is all emerged from the scientific modelling which is now a forked entity from the scientific philosophy models.

The Finite-State-Automata Models

@pavly-gerges
pavly-gerges / switching-mux.md
Last active September 13, 2024 10:27
Elementary linear algebriac formula for MUX operations.

Preface:

This document is devoted to derive the filter gates applied on the select lines of a multiplexer before entering the main AND circuit to produce the proper truth table. The document starts first by introducing the preliminaries using a miniaturized model, the 4-to-1 Multiplexer Model, the prototypical model of a MUX circuitry.

English:

For a 4-to-1 Multiplexer case. Let, $γ$ and $φ$ be symbols designating the select lines of the multiplexer And, $i$ be the symbols designating the input lines to the multiplexer, and $q$ designate the single output line from the MUX.

Lemma.01:

$$

In file included from /media/pavl-x86-machine/pavl-g/Projects/Electrostatic-Sandbox/electrostatic-sandbox-framework/electrostatic4j/serial4j/serial4j-native/src/lib/jni/com_serial4j_core_terminal_NativeTerminalDevice.cpp:40:
/media/pavl-x86-machine/pavl-g/Projects/Electrostatic-Sandbox/electrostatic-sandbox-framework/electrostatic4j/serial4j/serial4j-native/dependencies/include/electrostatic/util/errno/errno.h:14:16: error: expected identifier before ‘(’ token
14 | typedef struct errno(errno);
| ^~~~~
/media/pavl-x86-machine/pavl-g/Projects/Electrostatic-Sandbox/electrostatic-sandbox-framework/electrostatic4j/serial4j/serial4j-native/dependencies/include/electrostatic/util/errno/errno.h:14:16: error: typedef ‘__errno_location’ is initialized (use ‘decltype’ instead)
14 | typedef struct errno(errno);
| ^~~~~
/media/pavl-x86-machine/pavl-g/Projects/Electrostatic-Sandbox/electrostatic-sandbox-framework/electrostatic4j/serial4j/serial4j-native/dependencies/include/e
digraph G { rankdir = LR; a -> b }
flowchart LR

A[] 
B[]
flowchart LR
@pavly-gerges
pavly-gerges / diagrams.md
Created August 22, 2024 04:12 — forked from blackcater/diagrams.md
Markdown Diagrams

Diagrams

Markdown Preview Enhanced supports rendering flow charts, sequence diagrams, mermaid, PlantUML, WaveDrom, GraphViz, Vega & Vega-lite, Ditaa diagrams. You can also render TikZ, Python Matplotlib, Plotly and all sorts of other graphs and diagrams by using Code Chunk.

Please note that some diagrams don't work well with file exports such as PDF, pandoc, etc.

Flow Charts

This feature is powered by flowchart.js.

@pavly-gerges
pavly-gerges / switching_xor.c
Created August 22, 2024 02:58
A function that operates on a list of propositions and returns a predicate of their XORing operation using the primitive AND and OR.
#include <electrostatic/algorithm/arithmos/algebra/switching.h>
#include <stdlib.h>
uint8_t switching_xor(SWITCHING_TYPE **inputs, SWITCHING_TYPE *output){
if (inputs == NULL || output == NULL) {
return 1;
}
for (int i = 0; inputs[i] != NULL; i++) {
SWITCHING_TYPE prop0 = *output;
SWITCHING_TYPE prop1 = *(inputs[i]);
@pavly-gerges
pavly-gerges / hello_contiguous_buffer.c
Last active August 19, 2024 15:28
This is an early-access demonstrative example for the `contiguous_buffer.c` library and the List ADT from Arithmos.
#include <electrostatic/util/errno/errno.h>
#include <alloca.h>
#include <stdio.h>
#include <stdlib.h>
#include <electrostatic/algorithm/arithmos/adt/list.h>
void iterator(list *buffer, list_element *element) {
uint64_t index = 0;
buffer->function_table->indexof(buffer, element, &index);
printf("Index at %llud = %d\n", index, *((int*) element->data));