hard sell intro key points we know clojure let's leverage that ie functions. ideally pure ones across the repos, we should follow conventions unless there's a good reason not to what problems are there? duplicated code every project has some about of setup boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns corr.core | |
(:require [medley.core :as m])) | |
(defn index-by [f coll] | |
(->> coll | |
(group-by f) | |
(m/map-vals (fn [xs] | |
(assert (= 1 (count (take 2 xs)))) | |
(first xs))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tidy-requires) | |
(defn tidy-requires [[ _ & requires]] | |
(cons :require (sort-by first requires))) | |
(comment | |
(tidy-requires '(:require [foo] | |
[bar] )) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;local date to native date (js/Date or java.util.Date.) | |
(-> d | |
(cljc.java-time.local-date/at-start-of-day (t/zone "UTC")) | |
(t/inst)) | |
; native date (js/Date or java.util.Date.) to local date | |
(-> (java.util.Date.) | |
t/instant | |
(cljc.java-time.zoned-date-time/of-instant (t/zone "UTC")) | |
t/date) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns transducers) | |
;;;;; simplified traditional impls | |
(defn mymap [f coll] | |
(reduce | |
(fn [acc n] | |
(conj acc (f n))) | |
[] | |
coll)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns deps | |
"use https://github.com/alexander-yakushev/ns-graph | |
to create a function that returns all transitive dependencies of a namespace. | |
handy if you're trying to pull a ns out of a project | |
" | |
(:require [ns-graph.core :as nsg] | |
[clojure.java.io :as io])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias commit='git commit -a -m ' | |
alias glog='git log --pretty=oneline' | |
alias glog='git log --pretty=format:"%h%x09%an%x09%ad%x09%s"' | |
alias gsoft='git reset --soft HEAD~1' | |
alias gshowf='git show --name-only' | |
alias gshow='git diff-tree --no-commit-id --name-only -r ' | |
alias gint='git rebase --interactive ' | |
alias ginto='git rebase --interactive origin/master' | |
alias rgc='git rebase --continue' | |
alias rga='git rebase --abort' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test-tick.weekdays | |
(:require [tick.alpha.api :as t])) | |
; calculate weekdays between 2 local dates with tick | |
; 2 methods, one is quite readable, the other is probably more environmentally friendly | |
; https://www.timeanddate.com/date/workdays.html | |
; java.time weekday ordinals | |
; 1 2 3 4 5 6 7 | |
; M T W T F S S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; stack dump | |
(require '[clojure.stacktrace :as stck]) | |
(defn jstack [n] | |
(let [threadMXBean (java.lang.management.ManagementFactory/getThreadMXBean) | |
info (.getThreadInfo threadMXBean (.getAllThreadIds threadMXBean) 100)] | |
(for [threadInfo info] | |
(str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; handy when working at repl. something in a let statement is not working and so you want to def the variables so you can try | |
bits one by one | |
(defmacro deflet [bindings & body] | |
`(let ~bindings | |
~@(for [v (map first (partition 2 (destructure bindings)))] | |
(list 'def v v)))) |