#clojure

// Add new codez here:

b2f723f3d8bc "test"

(+ 1 4)

(comment 
 "just testin")

c261dc60cc07 "Reitit db middleware"

(def db
  {:name    ::db
   :compile (fn [router-data router-opts]
              (fn [handler]
                (fn [request]
                  (handler (assoc request :db (:db router-data))))))})

17dcdf3450a2 ":test"

(def foo :foo)

3339bd6fc30f "dawran6/emoji 0.1.4 released"

;; clojure -Sdeps '{:deps {dawran6/emoji {:mvn/version "0.1.4"}}}'
(require '[emoji.core :as e])

(e/emojify "Clojure is awesome :thumbsup:")
;; => "Clojure is awesome 👍"

(e/demojify "Clojure is awesome 👍")
;; => "Clojure is awesome :thumbsup:"


;; Emojify everything
(e/emojify-all "pen pineapple apple pen")
;; => "pen 🍍 🍎 pen"

09d5fe7017f9 "dawran6/emoji 0.1.2"

;; clojure -Sdeps '{:deps {dawran6/emoji {:mvn/version "0.1.2"}}}'
(require '[emoji.core :as e])

(e/->emoji "smile")
;; => "😄"

8f81a0f09ac5 "Newton method"

(defn newton
   [f fprime tol max-iteration x]
   (if (<= max-iteration 0)
     nil
     (let [y (f x)
           yprime (fprime x)
           x-new (- x (/ y yprime))]
       (if (<= (Math/abs(- x-new x)) (* tol (Math/abs x-new)))
         x-new
         (newton f fprime tol (dec max-iteration) x-new)))))

(newton #(- (* % %) 2) #(* 2 %) 0.00000001 20 100)
;; => 1.4142135623730951

bcb1e75038a8 "Time-ago function"

;; https://stackoverflow.com/questions/32511405/how-would-time-ago-function-implementation-look-like-in-clojure
(defn time-ago [epoch-second]
  (let [units [{:name "second" :limit 60 :in-second 1}
               {:name "minute" :limit 3600 :in-second 60}
               {:name "hour" :limit 86400 :in-second 3600}
               {:name "day" :limit 604800 :in-second 86400}
               {:name "week" :limit 2629743 :in-second 604800}
               {:name "month" :limit 31556926 :in-second 2629743}
               {:name "year" :limit Long/MAX_VALUE :in-second 31556926}]
        diff  (t/in-seconds (t/interval (c/from-epoch epoch-second) (t/now)))]
    (if (< diff 5)
      "just now"
      (let [unit (first (drop-while #(or (>= diff (:limit %))
                                         (not (:limit %)))
                                    units))]
        (-> (/ diff (:in-second unit))
            Math/floor
            int
            (#(str % " " (:name unit) (when (> % 1) "s") " ago")))))))

f13455592a36 "Coast server"

(ns server
  (:require [coast]))

(defn home [request]
  (coast/ok "You're coasting on clojure"))

(def routes (coast/routes [:get "/" ::home]))

(def app (coast/app {:routes routes}))

(coast/server app {:port 1337})

1f541de3bd7e "Hello World"

(println "Hello World!")