Skip to content

Instantly share code, notes, and snippets.

View erhangundogan's full-sized avatar
👋

Erhan Gundogan erhangundogan

👋
View GitHub Profile

Aphorisms from Shaonian Ge Xing

  • Observe the galaxy above your head and the soil beneath your feet. Thus found the law of nature. - "I Ching, Xi Ci, Part 1"

  • Similar voices make an echo, similar souls make a strong bond. - "I Ching, Qian, Wenyan"

  • A noble one suppresses evil and promotes good, in harmony with the will of Heaven. - "Book of Changes, Great Possession"

  • Understanding the discussion of life and death. - "I Ching, Xi Ci, Part 1"

@erhangundogan
erhangundogan / guessing-game.rs
Last active February 11, 2023 15:25
Rust learning very first example
use std::io;
use rand::Rng;
fn guess_number() -> i32 {
let mut guess = String::new();
println!("What is your guess?");
io::stdin().read_line(&mut guess).expect("Could not read line");
return match guess.trim().parse() {
Ok(n) => n,
Err(_e) => {
@erhangundogan
erhangundogan / StorageClass.yml
Last active May 20, 2023 08:23
kubernetes bare metal setup for Debian 10 (buster)
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: openebs-lvmpv
allowVolumeExpansion: true
parameters:
storage: "lvm"
volgroup: "vg0"
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer

Graph Algorithms

  • Breadth First Search (BFS)
  • Depth First Search (DFS)
  • Shortest Path from source to all vertices Dijkstra
  • Shortest Path from every vertex to every other vertex Floyd Warshall
  • Minimum Spanning tree Prim
  • Minimum Spanning tree Kruskal
  • Topological Sort
(* http://alaska-kamtchatka.blogspot.com/2012/07/theorems-for-free-monad-edition.html *)
module type FUNCTOR = sig
type 'a t
val fmap : ('a -> 'b) -> ('a t -> 'b t)
end
module type APPLICATIVE = sig
type 'a t
val pure : 'a -> 'a t
@erhangundogan
erhangundogan / dune
Last active October 10, 2021 18:36
Reads current directory and sub directories based on the depth (default 0. 1..nth)
(executable
(name main)
(preprocess (pps ppx_deriving.show)))
@erhangundogan
erhangundogan / fast_search.ml
Created October 7, 2021 13:55
Search and index files blazing fast
let extract_words str =
let re = Re.Pcre.regexp "\\w+" in
let groups = Re.all re str in
List.map
(fun g ->
let word = Re.Group.get g 0 in
let pos = Re.Group.start g 0 in
(word, pos)
) groups
@erhangundogan
erhangundogan / rpn.ml
Created October 7, 2021 13:53
Reverse Polish Notation
type t = [ `Op of string | `V of int ]
let string_to_t (i: string) : t =
match i with
| "+"
| "-"
| "*"
| "/" as o -> `Op o
| v ->
try `V (int_of_string v)
(* https://ocaml.org/manual/expr.html#sss:expr-variants *)
type t =
| Var of string
| Not of t
| And of t * t
| Or of t * t
let test = And
(Var "x", Not (Or
(Var "y", Var "z")
@erhangundogan
erhangundogan / p.ml
Created October 4, 2021 16:33
Polymorphic sum
module P = struct
type t =
| Null
| Int of int
| Float of float
let sum expr1 expr2 : t =
match expr1, expr2 with
| Int a, Int b -> Int (a + b)
| Float a, Float b -> Float (a +. b)