Skip to content

Instantly share code, notes, and snippets.

View dominem's full-sized avatar
🏡
home, sweet home

Dominik Magdaleński dominem

🏡
home, sweet home
View GitHub Profile
(defn fib
([n]
(take n (fib 0 1)))
([a-2 a-1]
(cons a-1 (lazy-seq (fib a-1 (+ a-2 a-1))))))
(comment
(fib 3)
;; => (1 1 2)
(fib 6)
;; => (1 1 2 3 5 8)
(defn my-update-in
[m ks f & args]
(assoc-in m ks (apply f (cons (get-in m ks) args))))
(comment
(my-update-in {:author {:name "Dominik"}} [:author] vec)
;; => {:author [[:name "Dominik"]]}
(my-update-in {:author {:name "Dominik"}} [:author :name] str " Magdalenski")
;; => {:author {:name "Dominik Magdalenski"}}
(my-update-in {} [:author :name] str " Magdalenski")
(defn my-assoc-in
[m [k & ks] v]
(assoc m k
(reduce (fn [v-in k-in] (assoc {} k-in v-in))
v
(reverse ks))))
(comment
(my-assoc-in {} [:a] 1)
;; => {:a 1}
(defn my-comp
([f g]
(fn [& args]
(f (apply g args))))
([f g & fns]
(fn [& args]
(f (g (reduce (fn [result next-f] (next-f result))
(apply (last fns) args)
(reverse (butlast fns))))))))
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="counter"></div>
<button id="start">Start</button>
<script>
from math import e
import numpy as np
import matplotlib.pyplot as plot
a_arr = np.array([1, 1 / 4])
c_arr = np.array([1, 1 / 4])
t_arr = np.linspace(0, 8, 200)
# Example:
x_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)]
y_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)]
colors = ['black', 'white', 'red']
types = ['-', '*', '+']
for index, value in enumerate(values):
plot(x_values[index], y_values[index], colors[index], types[index])
# You can do it better by using just a single array
args = [((1, 2, 3), (1, 2, 3), 'black', '-'), ((2, 3, 4), (2, 3, 4), 'white', '*'), ((5, 6, 7), (5, 6, 7), 'red', '+')]
@dominem
dominem / my-map.clj
Last active March 19, 2020 22:28
Clojure's custom map implementation using reduce
(defn my-map
([f coll]
(reverse
(reduce (fn [result x]
(cons (f x) result))
()
coll)))
([f coll & colls]
(let [colls (cons coll colls)
n (apply min (my-map count colls))]