Instantly share code, notes, and snippets.

Ertuğrul Çetin ertugrulcetin

View GitHub Profile
View find-indexes.clj
(defn find-index-route
[x form]
(letfn [(get-nodes [form]
(tree-seq coll? identity form))
(get-tree [form]
(rest (get-nodes form)))
(get-level [form]
(if (or (not (coll? form)) (not (seq form)))
View smooth-scroll-clojurescript.cljs
(def speed 750)
(def moving-frequency 15)
(defn scroll-to-id
[elem target-id]
(let [target (.getElementById js/document target-id)
elem-scroll-top (-> elem .-scrollTop)
hop-count (/ speed moving-frequency)
gap (/ (- (-> target .-offsetTop) elem-scroll-top) hop-count)]
(doseq [i (range 1 (inc hop-count))]
View multi-comp.clj
(def data [{:v 12, :a 10} {:v 21, :a 113} {:v 1, :a 2} {:v 12, :a 223} {:v 100, :a 23} {:v 1, :a 113}])
(defn multi-comp
([fns a b]
(multi-comp fns < a b))
([[f & others :as fns] order a b]
(if (seq fns)
(let [result (compare (f a) (f b))
f-result (if (= order >) (* -1 result) result)]
(if (= 0 f-result)
View if-let-multi-and-when-let-multi.clj
(defmacro assert-all
[& pairs]
`(do (when-not ~(first pairs)
(throw (IllegalArgumentException.
(str (first ~'&form) " requires " ~(second pairs) " in " ~'*ns* ":" (:line (meta ~'&form))))))
~(let [more (nnext pairs)]
(when more
(list* `assert-all more)))))
(defmacro when-let*
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View if-let-multi.clj
(defmacro if-let*
([bindings then]
`(if-let* ~bindings ~then nil))
([bindings then else]
(if (seq bindings)
`(if-let [~(first bindings) ~(second bindings)]
(if-let* ~(drop 2 bindings) ~then ~else)
~(if-not (second bindings) else))
View when-let-multi.clj
(defmacro when-let*
([bindings & body]
(if (seq bindings)
`(when-let [~(first bindings) ~(second bindings)]
(when-let* ~(drop 2 bindings) ~@body))
`(do ~@body))))
View ColEx.clj
(def any?
(complement not-any?))