Skip to content

Instantly share code, notes, and snippets.

View ertugrulcetin's full-sized avatar

Ertuğrul Çetin ertugrulcetin

View GitHub Profile
@ertugrulcetin
ertugrulcetin / ColEx.clj
Created February 19, 2016 13:47
Clojure any? function
(def any?
(complement not-any?))
(defmacro when-let*
([bindings & body]
(if (seq bindings)
`(when-let [~(first bindings) ~(second bindings)]
(when-let* ~(drop 2 bindings) ~@body))
`(do ~@body))))
(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))
then)))
@ertugrulcetin
ertugrulcetin / 0_reuse_code.js
Last active April 22, 2016 14:35
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
(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*
@ertugrulcetin
ertugrulcetin / multi-comp.clj
Last active April 7, 2017 23:35
with multi-comp you can combine comp fns -> [:age :count :size :weight]
(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)
@ertugrulcetin
ertugrulcetin / smooth-scroll-clojurescript.cljs
Created May 26, 2017 17:59
Smooth scroll Clojurescript example
(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))]
@ertugrulcetin
ertugrulcetin / find-indexes.clj
Last active August 20, 2017 09:09
Finding indexes in nested data structure
(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)))
@ertugrulcetin
ertugrulcetin / clojure-clojurescript-shadow-cljs-aws-elasticbeanstalk-circleci.md
Last active February 22, 2024 04:54
Clojure, ClojureScript and Shadow-cljs - Deploying to Elastic Beanstalk using CircleCi 2
@ertugrulcetin
ertugrulcetin / soyisimler.sql
Created December 4, 2019 10:49 — forked from BedirYilmaz/soyisimler.sql
Türkçe Soyisim Listesi - Sqlleştirildi
CREATE TABLE soyisimler (
id int IDENTITY(1,1) NOT NULL,
soyisim varchar(255) NOT NULL,
PRIMARY KEY (id)
)
INSERT INTO soyisimler VALUES ('ABAT');
INSERT INTO soyisimler VALUES ('ABSEYİ');
INSERT INTO soyisimler VALUES ('ABACIOĞLU');
INSERT INTO soyisimler VALUES ('ACAR');