#26 - Tweaked formatting for mobile experience. And scrollY positioning code.

--- src/biblecli/commands/staticpages.cljs
+++ src/biblecli/commands/staticpages.cljs
@@ -30,6 +30,9 @@
   padding: 0;
   font-family: \"Times New Roman\", TimesNewRoman, Times, Baskerville, Georgia, serif;
 }
+h1, h2 {
+  margin: 0.45em 0 0.3em 0;
+}
 a:link, a:visited {
   text-decoration: none;
   color: #33f;
@@ -40,8 +43,7 @@
 }
 .content {
   font-size: 125%;
-  padding: 25px;
-  background-color: #FFFFFF;
+  background-color: white;
 }
 .ref {
   display: none;
@@ -81,6 +83,11 @@

 .book, .main {
   display: none;
+}
+.book a.back {
+  font-size: 0.67em;
+  font-weight: normal;
+  margin-left: 1em;
 }
 .books a, .chapters a {
   display: inline-block;
@@ -141,6 +148,7 @@
     width: 600px;
     margin: 25px auto 15px auto;
     border: 1px solid #BBB;
+    padding: 25px;
     -webkit-box-shadow: 0px 0px 23px 3px rgba(135,135,135,0.77);
     -moz-box-shadow: 0px 0px 23px 3px rgba(135,135,135,0.77);
     box-shadow: 0px 0px 23px 3px rgba(135,135,135,0.77);
@@ -168,8 +176,11 @@

 @media (max-width: 680px) {
   .content {
-    min-width: 280px;
     margin: 25px auto 15px auto;
+    padding: 0 12px 12px 12px;
+  }
+  .content.verses {
+    padding-top: 12px;
   }
   .menu {
     position: fixed;
@@ -201,6 +212,8 @@
 !function(e,t){typeof module!=\"undefined\"?module.exports=t():typeof define==\"function\"&&typeof define.amd==\"object\"?define(t):this[e]=t()}(\"domready\",function(e){function p(e){h=1;while(e=t.shift())e()}var t=[],n,r=!1,i=document,s=i.documentElement,o=s.doScroll,u=\"DOMContentLoaded\",a=\"addEventListener\",f=\"onreadystatechange\",l=\"readyState\",c=o?/^loaded|^c/:/^loaded|c/,h=c.test(i[l]);return i[a]&&i[a](u,n=function(){i.removeEventListener(u,n,r),p()},r),o&&i.attachEvent(f,n=function(){/^c/.test(i[l])&&(i.detachEvent(f,n),p())}),e=o?function(n){self!=top?h?n():t.push(n):function(){try{s.doScroll(\"left\")}catch(t){return setTimeout(function(){e(n)},50)}n()}()}:function(e){h?e():t.push(e)}});

 (function (document, window) {
+
+document.kj = document.kj || {};

 var activeId = '_main';

@@ -237,7 +250,6 @@
   return ret;
 }

-
 function SetActive()
 {
     var raw = window.location.hash.substr(1);
@@ -245,6 +257,13 @@
     if(!SetActiveElem(id)) {
       SetActiveElem('_main');
     }
+}
+
+function ScrollToY(y)
+{
+  if(window.scrollY !== y) {
+    window.scrollTo(window.scrollX, y);
+  }
 }

 function CenterElem(el)
@@ -256,17 +275,34 @@
             newY = window.scrollY +
                    elRect.top -
                    (docEl.clientHeight - elHeight) / 2;
-        window.scrollTo(window.scrollX, newY);
+        ScrollToY(newY);
     }
 }
+
+function DoScroll()
+{
+  window.setTimeout(
+    function() {
+      if(document.kj.centeractive) {
+        CenterElem(FindElem(activeId));
+      }
+      if(document.kj.scrolltop) {
+        ScrollToY(0);
+      }
+    }, 0);
+}
+
+SetActive();
+DoScroll();

 window.addEventListener('hashchange', function(e) {
   SetActive();
+  DoScroll();
 });

 domready(function() {
   SetActive();
-  window.setTimeout(function() { CenterElem(FindElem(activeId)); }, 0);
+  DoScroll();
 });

 })(document, window);
@@ -394,8 +430,8 @@
         id (:id b)
         bookid (book-elem-id id)]
     [:div.book {:id (str "_" bookid)}
-      [:h2.chapter (book-name-nbsp id)]
-      [:div.back [:a {:href "#"} "Back to Book Lists"]]
+      [:h2.chapter (book-name-nbsp id) " "
+       [:a.back {:href "#"} "Table of Contents"]]
       [:div.chapters
         (->> chapters
              (map (fn [ch]
@@ -436,7 +472,9 @@
                 (map toc-book-details))

             [:div.about [:a {:href "https://github.com/pstephens/kingjames.bible/blob/master/README.md"} "About " baseurl ]]]
-          [:script {:type "text/javascript" :src "hiliter.js"}]]])))
+          [:script {:type "text/javascript" :src "hiliter.js"}]
+          [:script {:type "text/javascript"}
+           "document.kj = document.kj || {}; document.kj.scrolltop = true;"]]])))

 (defn chapters [m]
   (->> m
@@ -564,7 +602,9 @@
               (chapter-name ch)]
             (map-indexed #(verse %1 ch %2) verses)
             [:div.about [:a {:href "https://github.com/pstephens/kingjames.bible/blob/master/README.md"} "About " baseurl]]
-            [:script {:type "text/javascript" :src "hiliter.js"}]]]])))
+            [:script {:type "text/javascript" :src "hiliter.js"}]
+            [:script {:type "text/javascript"}
+             "document.kj = document.kj || {}; document.kj.centeractive = true;"]]]])))

 (defn next-chapter [all-chapters i]
   (get all-chapters (inc i)))


Show cursor over buttons

Show cursor over buttons

--- src/braid/client/ui/styles/mixins.cljs
+++ src/braid/client/ui/styles/mixins.cljs
@@ -57,7 +57,8 @@
     :text-decoration "none"
     :color "#aaa"
     :padding [[(em 0.1) (em 0.25)]]
-    :white-space "nowrap"}
+    :white-space "nowrap"
+    :cursor "pointer"}
    [:&:hover
     {:color "#999"
      :border-color "#aaa"}]])


Alphabetize and comment c-extensions

Alphabetize and comment c-extensions

--- src/atom_finder/util/30_fs_util.clj
+++ src/atom_finder/util/30_fs_util.clj
@@ -16,7 +16,11 @@

 (defmulti c-file? class)
 (defmethod c-file? String [filename]
-  (->> filename file-ext #{"c" "cc" "cpp" "cxx" "C" "c++" "h" "hh" "hpp" "h++" "H" "ipp"}))
+  ;; All extensions that are
+  ;; * Known to be C/C++ code - e.g. .c++/.h++, and not .vert/.frag
+  ;; * Are common - having more than 100k nodes in this corpus
+  ;; * Are parsable - having an average problem rate of <0.1
+  (->> filename file-ext #{"c" "cc" "cpp" "cxx" "c++" "C" "h" "hh" "hpp" "h++" "H" "ipp"}))
 (defmethod c-file? java.io.File [file]
   (and (.isFile file)
        (c-file? (.getName file))))


ongoing islands impl

ongoing islands impl

--- src/tenbytenbot/tactics.clj
+++ src/tenbytenbot/tactics.clj
@@ -43,9 +43,27 @@
 ;(empty-spots (m/mcreate [3 3] '([0 0] [1 0])))

-(defn number-of-islands [board]
-  "TODO http://prismoskills.appspot.com/lessons/Arrays/Count_blobs_in_matrix.jsp"
-  0)
+
+(defn- neighbours-4 [pos relevant-positions]
+  (let [[x y] pos
+        potentials set([[(dec x) y]
+                        [(inc x) y]
+                        [x (dec y)]
+                        [x (inc y)]])]
+    (intersection potentials relevant-positions)))
+
+
+
+;; (defn number-of-islands [board]
+;;   "TODO http://prismoskills.appspot.com/lessons/Arrays/Count_blobs_in_matrix.jsp"
+;;   (loop [left-to-visit (set (m/filled-positions board))
+;;          result 0]
+
+
+
+;;       (if (and (m/mget board [x y])
+;;                (not (m/get [
+;;   0)


Code cleaning and improvements on catacumba.impl.helpers.

--- src/clojure/catacumba/impl/helpers.clj
+++ src/clojure/catacumba/impl/helpers.clj
@@ -29,10 +29,13 @@
            ratpack.func.Function
            ratpack.func.Block
            ratpack.exec.Promise
+           ratpack.exec.Upstream
+           ratpack.exec.Downstream
            ratpack.handling.Context
+           java.util.concurrent.CompletableFuture
            io.netty.buffer.Unpooled))

-(defn action
+(defn ^Action fn->action
   "Coerce a plain clojure function into
   ratpacks's Action interface."
   [callable]
@@ -40,15 +43,7 @@
     (^void execute [_ x]
       (callable x))))

-(defn function
-  "Coerce a plain clojure function into
-  ratpacks's Function interface."
-  [callable]
-  (reify Function
-    (apply [_ x]
-      (callable x))))
-
-(defn ^Block block
+(defn ^Block fn->block
   "Coerce a plain clojure function into
   ratpacks's Block interface."
   [callable]
@@ -56,11 +51,60 @@
     (execute [_]
       (callable))))

+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Promise & Async blocks
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defprotocol IPromiseAcceptor
+  (-accept [v ds]))
+
+(extend-protocol IPromiseAcceptor
+  CompletableFuture
+  (-accept [f ^Downstream ds]
+    (.accept ds f))
+
+  Throwable
+  (-accept [e ^Downstream ds]
+    (.error ds e))
+
+  Object
+  (-accept [o ^Downstream ds]
+    (.success ds o)))
+
 (defn promise
-  "A convenience function for create ratpack
-  promises from context instance."
-  [^Context ctx callback]
-  (.promise ctx (action callback)))
+  "A convenience function for create ratpack promises."
+  [callback]
+  (Promise/of (reify Upstream
+                (^void connect [_ ^Downstream ds]
+                  (let [continuation #(-accept % ds)]
+                    (callback continuation))))))
+
+(defmacro blocking
+  "Performs a blocking operation on a separate thread,
+  returning a promise for its value."
+  [& body]
+  `(Blocking/get
+    (reify ratpack.func.Factory
+      (create [_]
+        ~@body))))
+
+(defmacro async
+  "Perform a async operation and return a promise.
+
+  Warning: this function does not launch any additional
+  thread, so is the user responsability does not
+  call any blocking call inside the async block."
+  [name & body]
+  `(promise (fn [~name]
+              ~@body)))
+
+(defn then
+  [^Promise promise callback]
+  (.then promise (fn->action callback)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Bytebuffer coersions.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 (defprotocol IByteBuffer
   (bytebuffer [_] "Coerce to byte buffer."))
@@ -70,13 +114,19 @@
   (bytebuffer [s]
     (Unpooled/wrappedBuffer (.getBytes s "UTF-8"))))

+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Promissum IFuture protocol implementation
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; TODO: deprecate this because the implementation is wrong.
+
 (extend-protocol pt/IFuture
   ratpack.exec.Promise
   (map [this callback]
-    (.then ^Promise this (action callback))
+    (.then ^Promise this (fn->action callback))
     this)
   (flatmap [this callback]
     (throw (UnsupportedOperationException. "Not implemented")))
   (error [this callback]
-    (.onError ^Promise this (action callback))
+    (.onError ^Promise this (fn->action callback))
     this))


Move delete checkbox for clarity

Move delete checkbox for clarity

--- src/clojure/nightcode/file_browser.clj
+++ src/clojure/nightcode/file_browser.clj
@@ -147,12 +147,12 @@
              (.isFile file)
              (not (protect-file? (.getCanonicalPath file))))
       (doto (s/border-panel :class :edit
-                            :north (s/checkbox :class :delete
-                                               :text (utils/get-string :delete)
-                                               :halign :center)
-                            :center (some-> (get-icon-path file)
-                                            icon/icon
-                                            JLabel.)
+                            :north (some-> (get-icon-path file)
+                                           icon/icon
+                                           JLabel.)
+                            :center (s/checkbox :class :delete
+                                                :text (utils/get-string :delete)
+                                                :halign :center)
                             :south (s/text :class :name
                                            :text name
                                            :editable? true)


switched name from collect- to telescoping-long-trends

--- src/clj/forma/hadoop/jobs/forma.clj
+++ src/clj/forma/hadoop/jobs/forma.clj
@@ -18,7 +18,7 @@
         new-start   (date/datetime->period t-res est-start)
         [start end] (date/relative-period t-res ts-start [est-start est-end])]
     [(->> (:series ts-series)
-          (a/collect-short-trend start end long-block window)
+          (a/telescoping-short-trend start end long-block window)
           (schema/timeseries-value new-start))]))

 ;; We're mapping across two sequences at the end, there; the
@@ -34,7 +34,7 @@
         [start end] (date/relative-period t-res ts-start [est-start est-end])]
     (apply map (comp (partial schema/timeseries-value new-start)
                      vector)
-           (a/collect-long-trend start end
+           (a/telescoping-long-trend start end
                                  (:series ts-series)
                                  (map :series cofactors)))))


helper fn for filtering and plucking values from DataPoints

--- src/clj/marceline/storm/metrics.clj
+++ src/clj/marceline/storm/metrics.clj
@@ -103,3 +103,8 @@
   "Sets a consumer's state to be the conf map."
   [this-consumer conf]
   (reset! (. this-consumer state) conf))
+
+(defn metric-vals
+  [metric-name data-points]
+  (doseq [metric-point (filter #(= metric-vals (.name %)) data-points)]
+    (.value metric-point)))


Removing some cruft from the protocols

Removing some cruft from the protocols

--- src/clj_bots/pin_ctrl/protocols.clj
+++ src/clj_bots/pin_ctrl/protocols.clj
@@ -10,9 +10,7 @@

 (defprotocol PBoard
   "Basic board protocol, shared by any board, whether on board or over wire."
-  (map-pin [this pinspec]
-    "Some devices, such as the Beaglebone black, have non-trivial mappings between convenient
-    `[header, pin-number]` pairs to the underlying fs-gpio pins.")
+  ; XXX Not sure we need this actually; just let the implementation take care of it on it's own
   (pin-modes [this])
   (create-pin [this pin-n])
   (get-config [this])
@@ -24,9 +22,7 @@
 (defprotocol POverwireBoard
   "Overwire boards are boards that run over the wire, like Arduino boards over Firmata. This
   protocol is for functions specific to these boards."
-  (reset-board! [this] "Overwire boards, such as arduino boards over firmata, can be reset!")
-  ; Not sure we really need this one to be separate from above
-  (get-config! [this] "Load the configuratino settings of the board over the wire directly from the device and cache."))
+  (reset-board! [this] "Overwire boards, such as arduino boards over firmata, can be reset!"))

 (defprotocol PPinConfigure
   (set-mode! [this mode] "Set the mode of the pin, as long as it's supported by the pin's board."))


Remove unnecessary "in this section"

Remove unnecessary "in this section"

--- src/cljs/onyx_cheat_sheet/core.cljs
+++ src/cljs/onyx_cheat_sheet/core.cljs
@@ -298,7 +298,7 @@
                                              :type :function
                                              :optional? false}}}
    :trigger-entry
-   {:summary "In this section, we talk about Triggers. Triggers are a feature that interact with Windows. Windows capture and bucket data over time. Triggers let you release the captured data over a variety stimuli."
+   {:summary "Triggers are a feature that interact with Windows. Windows capture and bucket data over time. Triggers let you release the captured data over a variety stimuli."
     :link nil
     :model {:trigger/window-id
             {:doc "The name of a `:window/id` window to fire the trigger against."


added debug

added debug

--- src/meta/server.cljs
+++ src/meta/server.cljs
@@ -41,25 +41,19 @@
     chan/join-anonymous))

 (defn using
-  ([path svc]
-   (using app path svc))
-  ([app path svc]
-   (debug "Passing app.use call to feathers")
-   (.use app path svc)))
+  [app path svc]
+  (debug "Passing app.use call to feathers")
+  (.use app path svc))

 (defn api
-  ([path svc hooks]
-   (api app path svc hooks))
-  ([app path svc hooks]
-   (debug "Passing app.api call to feathers")
-   (feathers/api app path svc hooks)))
+  [app path svc hooks]
+  (debug "Passing app.api call to feathers")
+  (feathers/api app path svc hooks))

 (defn listen
-  ([port]
-   (listen app port))
-  ([app port]
-   (debug "Passing app.listen call to feathers")
-   (.listen app port)))
+  [app port]
+  (debug "Passing app.listen call to feathers")
+  (.listen app port))

 (defn init! [fname]
   (debug "Setting nodejs *main-cli-fn*")


CMR-2308: Added tests to verify that JSON query keyword searches are sorted by and return score.

--- system-int-test/test/cmr/system_int_test/search/collection_keyword_search_test.clj
+++ system-int-test/test/cmr/system_int_test/search/collection_keyword_search_test.clj
@@ -73,7 +73,7 @@
         coll7 (d/ingest "PROV2" (dc/collection {:entry-title "coll7" :version-id "Laser"}))
         coll8 (d/ingest "PROV2" (dc/collection {:entry-title "coll8" :processing-level-id "PDQ123"}))

-        coll9 (d/ingest "PROV2" (dc/collection {:entry-title "coll9" :science-keywords [sk1 sk2]}))
+        coll9 (d/ingest "PROV2" (dc/collection {:entry-title "coll09" :science-keywords [sk1 sk2]}))

         coll10 (d/ingest "PROV2" (dc/collection {:entry-title "coll10"
@@ -312,10 +312,17 @@
                (println "Expected:" (map :entry-title items))
                (println "Actual:" (map :name (:refs refs))))
              matches?)
-           "Laser spoonA" [coll14 coll9]
-           "La?er spoonA" [coll14 coll9]
-           "L*er spo*A" [coll14 coll9]
-           "L?s* s?o*A" [coll14 coll9]))
+           "Laser spoonA" [coll14 coll9]))
+
+    (testing "sorted search by keywords JSON query."
+      (are [keyword-str items]
+           (let [refs (search/find-refs-with-json-query :collection {} {:keyword keyword-str})
+                 matches? (d/refs-match-order? items refs)]
+             (when-not matches?
+               (println "Expected:" (map :entry-title items))
+               (println "Actual:" (map :name (:refs refs))))
+             matches?)
+           "Laser spoonA" [coll14 coll9]))

     (testing "sorted search by keywords with sort keys."
       (are [keyword-str sort-key items]
@@ -329,6 +336,14 @@
            "Laser" "score" [coll14 coll5 coll7 coll9]
            "Laser" "+score" [coll5 coll7 coll9 coll14]
            "Laser" "-score" [coll14 coll5 coll7 coll9]))
+
+    (testing "parameter search by keywords returns score"
+      (let [refs (search/find-refs :collection {:keyword "Laser"})]
+        (is (every? :score (:refs refs)))))
+
+    (testing "JSON keywords search returns score"
+      (let [refs (search/find-refs-with-json-query :collection {} {:keyword "Laser"})]
+        (is (every? :score (:refs refs)))))

     (testing "search by multiple keywords returns an error."
       (let [resp (search/find-refs :collection {:provider "PROV1"


State.

State.

--- test/com/nomistech/clojure_the_language/c_400_state_and_concurrency/s_030_refs.clj
+++ test/com/nomistech/clojure_the_language/c_400_state_and_concurrency/s_030_refs.clj
@@ -42,12 +42,10 @@

 ;;;; Our bank account example could be done with an atom:

-(def bank-accounts-atom
-  (atom {:account-1 100
-         :account-2 200}))
-
 (fact
-  (let [amount 20]
+  (let [bank-accounts-atom (atom {:account-1 100
+                                  :account-2 200})
+        amount 20]
     (swap! bank-accounts-atom (fn [m]
                                 (-> m
                                     (update :account-1 + amount)


Add a space to the nthpath documentation.

--- src/clj/com/rpl/specter.cljc
+++ src/clj/com/rpl/specter.cljc
@@ -935,7 +935,7 @@
   must
   (eachnav n/must*))

-(def ^{:doc "Navigate to the specified indices one after another.If navigate to
+(def ^{:doc "Navigate to the specified indices one after another. If navigate to
             NONE, that element is removed from the sequence."}
   nthpath
   (eachnav n/nthpath*))


#9 Added functions for starting and stopping server from repl

--- src/clj/funstructor/core.clj
+++ src/clj/funstructor/core.clj
@@ -31,14 +31,37 @@
   (handler/site app-routes))

 (def application (-> handler
-                     ;(st/wrap-stacktrace)
                      (reload/wrap-reload)
                      ))

+(def stop-server-fn (atom nil))
+
+(defn start-server []
+  (if @stop-server-fn
+    (throw (RuntimeException. "Server is already running"))
+    (let [port (Integer/parseInt
+                (or (System/getenv "PORT") "8080"))]
+      (u/logging-process)
+      (u/log "Server started on port " port)
+      (p/pending-checker-process p/pending-players-chan)
+      (let [stop-fn (run-server application {:port port :join? false})]
+        (reset! stop-server-fn stop-fn)))))
+
+(defn stop-server []
+  (if-let [stop-fn @stop-server-fn]
+    (do (stop-fn)
+        (reset! stop-server-fn nil))
+    (throw (RuntimeException. "Server has not been started"))))
+
 (defn -main [& args]
-  (let [port (Integer/parseInt
-              (or (System/getenv "PORT") "8080"))]
-    (u/logging-process)
-    (u/log "Server started on port " port)
-    (p/pending-checker-process p/pending-players-chan)
-    (run-server application {:port port :join? false})))
+  (start-server))
+
+
+
+
+
+
+
+
+
+


Add api-docs for lambdacd.step-id

Add api-docs for lambdacd.step-id

--- src/clj/lambdacd/step_id.clj
+++ src/clj/lambdacd/step_id.clj
@@ -1,19 +1,34 @@
 (ns lambdacd.step-id
+  "Utility functions to deal with the logic behind step ids:
+  step-ids are a sequence of numbers that represent the structure of the pipeline.
+
+  Examples:
+
+  * `[1]` is the first step of the pipeline
+  * `[2 1]` is the second child of the first step of the pipeline.
+
+  For detailed examples on these functions, refer to their [tests](https://github.com/flosell/lambdacd/blob/master/test/clj/lambdacd/step_id_test.clj)."
   (:require [lambdacd.util.internal.coll :as coll-util]))

-(defn parent-of? [parent child]
+(defn parent-of?
+  "Returns true if the steps the given step-ids refer to are parent and child."
+  [parent child]
   (let [cut-off-b (take-last (count parent) child)]
     (and
       (not= parent child)
       (= parent cut-off-b))))

-(defn direct-parent-of? [parent child]
+(defn direct-parent-of?
+  "Returns true if the steps the given step-ids refer to are parent and immediate child."
+  [parent child]
   (and
     (parent-of? parent child)
     (= (inc (count parent))
        (count child))))

-(defn later-than? [a b]
+(defn later-than?
+  "Returns true if for two steps, the step with id a is executed after b in the pipeline."
+  [a b]
   (let [length (max (count a) (count b))
         a-parents-first (reverse a)
         b-parents-first (reverse b)
@@ -26,16 +41,24 @@
       (> (count a) (count b))
       (> x y))))

-(defn before? [a b]
+(defn before?
+  "Returns true if for two steps, the step with id b is executed after a in the pipeline."
+  [a b]
   (and
     (not= a b)
     (not (later-than? a b))))

-(defn child-id [parent-step-id child-number]
+(defn child-id
+  "Returns a step id for the `child-number`th child of the step with id `parent-step-id`."
+  [parent-step-id child-number]
   (cons child-number parent-step-id))

-(defn root-step-id? [step-id]
+(defn root-step-id?
+  "Returns true if the step-id belongs to a root-step, i.e. a step with no parents."
+  [step-id]
   (= 1 (count step-id)))

-(defn root-step-id-of [step-id]
+(defn root-step-id-of
+  "Returns the id of the root-parent of the step with the given id."
+  [step-id]
   (last step-id))


add tooltips, link back to basic site

add tooltips, link back to basic site

--- src/cljs/clj_money/core.cljs
+++ src/cljs/clj_money/core.cljs
@@ -37,17 +37,23 @@
      [:ul.nav.navbar-nav
       [:li
        [:a {:href "/commodities"
+            :title "Click here to manage commodities for this entity."
             :class (when (= active-nav :commodities)
                      "active")}
         "Commodities"]]]
      [:div.navbar-right
      [:ul.nav.navbar-nav
+      [:li
+       [:a {:href (str "/entities/" (:id @entities/current) "/accounts")
+            :title "Click here to go to the basic HTML site"}
+        "HTML"]]
       [:li.dropdown {:role "presentation"}
        [:a.dropdown-toggle
         {:href "#"
          :data-toggle "dropdown"
          :role "button"
-         :aria-haspopup true}
+         :aria-haspopup true
+         :title "Select the entity you want to work with here."}
         (:name @entities/current)
         [:span.caret]]
        [:ul.dropdown-menu


Use `nil`-out trick on missed multimethods.

--- src/clojure/parkour/conf.clj
+++ src/clojure/parkour/conf.clj
@@ -14,14 +14,17 @@
   "Base configuration, used as template for fresh configurations."
   (Configuration.))

+(def configuration* nil)
 (defmulti ^:private configuration*
   "Internal implementation multimethod for extracting a `Configuration`."
   type)

+(def conf-set* nil)
 (defmulti ^:private conf-set*
   "Internal implementation multimethod for setting value in Hadoop config."
   (fn [_ _ val] (type val)))

+(def conf-coerce nil)
 (defmulti ^:private conf-coerce
   "Internal implementation multimethod for converting value to one
 which may be set as Hadoop config value."


CMR-545: Added flag to skip background jobs in metadata-db.

--- src/cmr/bootstrap/system.clj
+++ src/cmr/bootstrap/system.clj
@@ -30,10 +30,19 @@
     :private true}
   component-order [:log :db :web])

+
+(comment
+
+  (into {:a :A :b :B} {:b nil :c :C})
+
+  )
+
 (defn create-system
   "Returns a new instance of the whole application."
   []
-  (let [metadata-db (dissoc (mdb-system/create-system) :log :web)
+  (let [metadata-db (-> (mdb-system/create-system)
+                        (dissoc :log :web)
+                        (assoc :skip-background-jobs true))
         indexer (-> (idx-system/create-system)
                     (dissoc :log :web)
                     ;; Setting the parent-collection-cache to cache parent collection umm


Bettern variable names and formatting.

Bettern variable names and formatting.

--- src/cmr/opendap/ous/core.clj
+++ src/cmr/opendap/ous/core.clj
@@ -279,36 +279,37 @@
   (let [start (util/now)
         search-endpoint (config/get-search-url component)
         ;; Stage 1
-        [params bounding-box granules coll s1-errs] (stage1
-                                                     component
-                                                     search-endpoint
-                                                     user-token
-                                                     raw-params)
+        [params bounding-box grans-promise coll-promise s1-errs]
+        (stage1 component
+                search-endpoint
+                user-token
+                raw-params)
         ;; Stage 2
-        [coll params data-files service-ids vars s2-errs] (stage2
-                                                           component
-                                                           search-endpoint
-                                                           user-token
-                                                           params
-                                                           coll
-                                                           granules)
+        [coll params data-files service-ids vars s2-errs]
+        (stage2 component
+                search-endpoint
+                user-token
+                params
+                coll-promise
+                grans-promise)
         ;; Stage 3
-        [services bounding-info s3-errs] (stage3
-                                          component
-                                          coll
-                                          search-endpoint
-                                          user-token
-                                          bounding-box
-                                          service-ids
-                                          vars)
+        [services bounding-info s3-errs]
+        (stage3 component
+                coll
+                search-endpoint
+                user-token
+                bounding-box
+                service-ids
+                vars)
         ;; Stage 4
-        [query s4-errs] (stage4 coll
-                                bounding-box
-                                services
-                                bounding-info)
+        [query s4-errs]
+        (stage4 coll
+                bounding-box
+                services
+                bounding-info)
         ;; Error handling for all stages
         errs (errors/collect
-              start params bounding-box granules coll s1-errs
+              start params bounding-box grans-promise coll-promise s1-errs
               data-files service-ids vars s2-errs
               services bounding-info s3-errs
               query s4-errs


Add ES bulk formatting.

Add ES bulk formatting.

--- src/monocle/core.clj
+++ src/monocle/core.clj
@@ -2,6 +2,7 @@
   (:gen-class)
   (:require [clojure.tools.cli :as cli]
             [clojure.tools.logging :as log]
+            [cheshire.core :as json]
             [monocle.io :as io]
             [monocle.rabbitmq :as rmq])
   (:use [monocle.io :only [with-offset]]))
@@ -23,8 +24,8 @@
    ["--trustpw" "Trust keystore password"]
    ["--index" (str "Format the batches in elasticsearch's bulk\n"
                    "                                "
-                   " format.  Also need --type.")
-    "--type " "The type to provide to elasticsearch"]
+                   " format.  Also need --type.")]
+   ["--type" "The type to provide to elasticsearch"]
    ["-h" "--help" "Help!" :default false :flag true]])

 (defn amqp-opts [iface]
@@ -42,8 +43,12 @@
 (defn send-iface [iface batches opts]
   ((whichfn iface) batches opts))

-(defn part [rdr opts]
-  (partition-all (:batch opts) (line-seq rdr)))
+(defn part [rdr {:keys [batch index type]}]
+  (if (and index type)
+    (let [bulk-header (json/encode {:index {:_index index :_type type}})]
+      (partition-all (* batch 2) (interleave (repeat bulk-header)
+                                             (line-seq rdr))))
+    (partition-all batch (line-seq rdr))))

 (defn main [{:keys [file offset-file interface batch reset] :as opts}]
   (with-offset [offset offset-file set-new-offset!]
@@ -61,16 +66,31 @@
 (defn delete-trailing-whitespace [s]
   (.replaceAll s "[ ]+\n" "\n"))

+(defn mixmatch [& args]
+  (= 2 (count (set (map boolean args)))))
+
+(defn exit [cont msg]
+  (println msg)
+  (reset! cont false))
+
+(defn fail [cont err]
+  (log/fatalf err)
+  (reset! cont false))
+
 (defn -main [& args]
-  (let [[{:keys [interface file offset-file batch help] :as opts} args helpstr]
+  (let [[{:keys [interface file offset-file
+                 batch help index type] :as opts} args helpstr]
         (apply cli/cli args options)
         opts (assoc opts :ssl (select-keys opts [:client :clientpw
-                                                 :trust :trustpw]))]
+                                                 :trust :trustpw]))
+        continue? (atom true)]
     (when-not offset-file
-      (log/fatalf "-o not supplied" offset-file))
+      (fail continue? "-o not supplied"))
     (when-not file
-      (log/fatalf "-f not supplied" file))
+      (fail continue? "-f not supplied"))
+    (when (mixmatch index type)
+      (fail continue? "supply both --index and --type if you want ES bulk"))
     (when help
-      (println (delete-trailing-whitespace helpstr)))
-    (when (and offset-file file)
+      (exit continue? (delete-trailing-whitespace helpstr)))
+    (when @continue?
       (main opts))))


Adds more interop support.

Adds more interop support.

--- src/onyx/interop.clj
+++ src/onyx/interop.clj
@@ -73,3 +73,12 @@

 (defn coerce-lifecycles [lifecycles]
   (mapv #(cast-types :lifecycle-entry %) lifecycles))
+
+(defn coerce-flow-conditions [fcs]
+  (mapv #(cast-types :flow-conditions-entry %) fcs))
+
+(defn coerce-windows [windows]
+  (mapv #(cast-types :window-entry %) windows))
+
+(defn coerce-trigger [trigger]
+  (mapv #(cast-types :trigger-entry %) trigger))


Add output resume point schema.

Add output resume point schema.

--- src/onyx/schema.cljc
+++ src/onyx/schema.cljc
@@ -520,6 +520,15 @@
    :replica-version ReplicaVersion
    :epoch Epoch})

+(s/defschema OutputResumeMode
+  {:mode (s/eq :resume)
+   :tenancy-id TenancyId
+   :job-id JobId
+   :task-id TaskId
+   :slot-migration SlotMigration
+   :replica-version ReplicaVersion
+   :epoch Epoch})
+
 (s/defschema WindowResumeMode
   {:mode (s/eq :resume)
    :tenancy-id TenancyId
@@ -539,6 +548,12 @@
                  #(= :resume (:mode %))
                  InputResumeMode))

+(s/defschema OutputResumeDefinition
+  (s/conditional #(= :initialize (:mode %))
+                 InitialiseMode
+                 #(= :resume (:mode %))
+                 OutputResumeMode))
+
 (s/defschema WindowResumeDefinition
   (s/conditional #(= :initialize (:mode %))
                  InitialiseMode
@@ -547,6 +562,7 @@

 (s/defschema ResumePoint
   {TaskId {(s/optional-key :input) InputResumeDefinition
+           (s/optional-key :output) OutputResumeDefinition
            (s/optional-key :windows) {WindowId WindowResumeDefinition}}})

 (s/defschema Job


open mailto in a new tab

open mailto in a new tab

--- src-cljs/frontend/components/pieces/page_header.cljs
+++ src-cljs/frontend/components/pieces/page_header.cljs
@@ -255,6 +255,7 @@
                      (button/link {:fixed? true
                                    :kind :primary
                                    :size :small
+                                   :target "_blank"
                                    :href "mailto:beta+ui@circleci.com?Subject=Topbar%20UI%20Feedback"
                                    :on-click #((om/get-shared owner :track-event) {:event-type :feedback-clicked
                                                                                :properties {:component "topbar"


Add test to exercise metadata.

Add test to exercise metadata.

--- test/multihash/core_test.clj
+++ test/multihash/core_test.clj
@@ -64,13 +64,19 @@
     (is (= [a b c] (sort [c b a])) "Multihashes sort in code/digest order")))

-; TODO: toString and print-method
 (deftest multihash-rendering
   (is (= "hash:sha1:0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
-         (str (multihash/create :sha1 "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")))))
+         (str (multihash/create :sha1 "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"))))
+  (is (= "hash:sha2-256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
+         (str (multihash/create :sha2-256 "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")))))

-; TODO: exercise metadata
+(deftest exercise-metadata
+  (let [a (multihash/create :sha1 "dbc95275da8a3d0d0beeea3f0fd47f3cc7b55bc3")
+        a' (vary-meta a assoc :foo :bar/baz)]
+    (is (empty? (meta a)) "values start with empty metadata")
+    (is (= :bar/baz (:foo (meta a'))) "metadata can be associated with value")
+    (is (= a a') "metadata does not affect equality")))

 (def examples


more refactoring of paredit core for removing direct access to :offset, :end-offset, etc.

--- src/paredit/core.clj
+++ src/paredit/core.clj
@@ -80,18 +80,18 @@
    chars-with-no-space-before chars-with-no-space-after]
     (let [parsed (parse text (.length text))
           offset-loc (-> parsed parsed-root-loc (loc-for-offset offset))]
-      (if (and offset-loc (not (*not-in-code* (-> offset-loc z/node :tag))))
+      (if (and offset-loc (not (*not-in-code* (loc-tag offset-loc))))
         (let [up-locs (take-while identity (iterate z/up offset-loc))
-              match (some #(when (= o (-> % z/node :tag)) %) up-locs)]
+              match (some #(when (= o (loc-tag %)) %) up-locs)]
           (if match
-            (let [last-node (-> match z/down z/rightmost z/left z/node)
-                  nb-delete (if (= (str \space) (:tag last-node))
-                              (- (:end-offset last-node) (:offset last-node))
+            (let [last-loc (-> match z/down z/rightmost z/left)
+                  nb-delete (if (= (str \space) (loc-tag last-loc))
+                              (loc-count last-loc)
                               0)
                   t (if (> nb-delete 0)
-                      (t/delete t (:offset last-node) nb-delete)
+                      (t/delete t (start-offset last-loc) nb-delete)
                       t)] ; z/left because there is the closing node
-              (-> t (t/set-offset (- (-> match z/node (:end-offset)) nb-delete))))
+              (-> t (t/set-offset (- (end-offset match) nb-delete))))
             (-> t (t/insert (str c)))))
         (-> t (t/insert (str c))))))

@@ -160,17 +160,16 @@
         parse-ok (not= :ko (:parser-state parsed))]
     (if parse-ok
       (let [offset-loc (-> parsed parsed-root-loc (loc-for-offset offset))
-            offset-node (-> offset-loc z/node)
             handled-forms (conj *open-brackets* "\"")
-            in-handled-form (handled-forms (:tag offset-node))]
+            in-handled-form (handled-forms (loc-tag offset-loc))]
         (cond
-          (and in-handled-form (= offset (:offset offset-node)))
+          (and in-handled-form (= offset (start-offset offset-loc)))
             (t/shift-offset t 1)
-          (and in-handled-form (= offset (dec (:end-offset offset-node))))
-            (if (> (-> offset-node :content count) 2)
+          (and in-handled-form (= offset (dec (end-offset offset-loc))))
+            (if (> (-> offset-loc z/node :content count) 2)
               t     ; don't move
               (-> t ; delete the form
-                (t/delete (:offset offset-node) (- (:end-offset offset-node) (:offset offset-node)))
+                (t/delete (start-offset offset-loc) (loc-count offset-loc))
                 (t/shift-offset -1)))
           :else
             (t/delete t offset 1)))
@@ -184,17 +183,16 @@
         parse-ok (not= :ko (:parser-state parsed))]
     (if parse-ok
       (let [offset-loc (-> parsed parsed-root-loc (loc-for-offset offset))
-            offset-node (-> offset-loc z/node)
             handled-forms (conj *open-brackets* "\"")
-            in-handled-form (handled-forms (:tag offset-node))]
+            in-handled-form (handled-forms (loc-tag offset-loc))]
         (cond
-          (and in-handled-form (= offset (:offset offset-node)))
-            (if (> (-> offset-node :content count) 2)
+          (and in-handled-form (= offset (start-offset offset-loc)))
+            (if (> (-> offset-loc z/node :content count) 2)
               t     ; don't move
               (-> t ; delete the form
-                (t/delete (:offset offset-node) (- (:end-offset offset-node) (:offset offset-node)))
+                (t/delete (start-offset offset-loc) (loc-count offset-loc))
                 (t/shift-offset -1)))
-          (and in-handled-form (= offset (dec (:end-offset offset-node))))
+          (and in-handled-form (= offset (dec (end-offset offset-loc))))
             (t/shift-offset t -1)
           :else
             (-> t (t/delete offset 1) (t/shift-offset -1))))


Reorganize code

Reorganize code

--- src/cyanite_fetcher/core.clj
+++ src/cyanite_fetcher/core.clj
@@ -33,32 +33,6 @@
     "path = ? AND tenant = ? AND rollup = ? AND period = ? "
     "AND time >= ? AND time <= ? ORDER BY time ASC;")))

-(defn cleaner
-  "Cleaner."
-  [data f name]
-  (println (format "Cleaning data with %s..." name))
-  (let [cdata (time (doall (f data)))]
-    (println "Number of rows:" (count cdata))
-    (newline)
-    cdata))
-
-(defn flatter
-  "Flatter."
-  [data f name]
-  (println (format "Flatting data with %s..." name))
-  (let [fdata (time (doall (f data)))]
-    (println "Number of rows:" (count fdata))
-    (newline)
-    fdata))
-
-(defn r-flatter-cleaner
-  [data]
-  (println "Flatting and clearing data with reducers...")
-  (let [frdata (time (doall (into [] (r/remove nil? (r/reduce into [] data)))))]
-    (println "Number of rows:" (count frdata))
-    (newline)
-    frdata))
-
 (defn par-fetch [session fetch! paths tenant rollup period from to]
   "Fetch data in parallel fashion."
   (let [futures
@@ -205,6 +179,36 @@
     (some within (sort-by :rollup rollups))))

 ;;------------------------------------------------------------------------------
+;; Data algorithms
+;;------------------------------------------------------------------------------
+
+(defn cleaner
+  "Cleaner."
+  [data f name]
+  (println (format "Cleaning data with %s..." name))
+  (let [cdata (time (doall (f data)))]
+    (println "Number of rows:" (count cdata))
+    (newline)
+    cdata))
+
+(defn flatter
+  "Flatter."
+  [data f name]
+  (println (format "Flatting data with %s..." name))
+  (let [fdata (time (doall (f data)))]
+    (println "Number of rows:" (count fdata))
+    (newline)
+    fdata))
+
+(defn r-flatter-cleaner
+  [data]
+  (println "Flatting and clearing data with reducers...")
+  (let [frdata (time (doall (into [] (r/remove nil? (r/reduce into [] data)))))]
+    (println "Number of rows:" (count frdata))
+    (newline)
+    frdata))
+
+;;------------------------------------------------------------------------------
 ;; Benchmark
 ;;------------------------------------------------------------------------------


More complete Mario modeling. Quite a lot of redundancy, eh.

--- src/player/core.cljs
+++ src/player/core.cljs
@@ -199,7 +199,7 @@

 (defn recalculate-edge [has ha index t]
   (let [edge (nth (:edges (current-state ha)) index)
-        ;todo: Does this suffice? Should the transition be intersected with "the future" in any other places, eg update-scene or next-transition?
+        ;todo: Does this suffice? Should the transition be intersected with "the future" in any other places, eg update-scene or next-transition? Does that explain the weird interval calculated for :m in the initial setup?
         transition (update (transition-interval has ha edge)
                            :interval (fn [intvl]
                                        (iv/intersection intvl [t Infinity])))
@@ -608,9 +608,10 @@
                (bumping-transitions id :right :falling-right nil walls others)
                (bumping-transitions id :top :left nil walls others)))))

+;todo: ABSTRACT!
 (defn mario [id x y others walls]
   (let [others (disj others id)
-        fall-speed 16
+        fall-speed 8
         move-speed 24]
     (make-ha id
              {:x     x :y y
@@ -626,7 +627,11 @@
                (make-edge
                  :moving-left
                  (non-bumping-guard :right walls others)
-                 #{[:on #{:left}]}))
+                 #{[:on #{:left}]})
+               (make-edge
+                 :falling-idle-right
+                 (unsupported-guard 16 16 walls others)
+                 #{:required}))
              (make-state
                :idle-left
                {}
@@ -637,10 +642,23 @@
                (make-edge
                  :moving-left
                  (non-bumping-guard :right walls others)
-                 #{[:on #{:left}]}))
+                 #{[:on #{:left}]})
+               (make-edge
+                 :falling-idle-left
+                 (unsupported-guard 16 16 walls others)
+                 #{:required}))
              (make-state
                :moving-right
                {:x move-speed}
+               (bumping-transitions id :left :idle-right nil walls others)
+               (make-edge
+                 :falling-idle-right
+                 (unsupported-guard 16 16 walls others)
+                 #{[:off #{:right}]})
+               (make-edge
+                 :falling-right
+                 (unsupported-guard 16 16 walls others)
+                 #{:required})
                (make-edge
                  :idle-right
                  nil
@@ -648,10 +666,69 @@
              (make-state
                :moving-left
                {:x (- move-speed)}
+               (bumping-transitions id :right :idle-left nil walls others)
+               (make-edge
+                 :falling-idle-left
+                 (unsupported-guard 16 16 walls others)
+                 #{[:off #{:right}]})
+               (make-edge
+                 :falling-left
+                 (unsupported-guard 16 16 walls others)
+                 #{:required})
                (make-edge
                  :idle-left
                  nil
-                 #{[:off #{:left}]})))))
+                 #{[:off #{:left}]}))
+             (make-state
+               :falling-idle-right
+               {:y (- fall-speed)}
+               (bumping-transitions id :top :idle-right nil walls others)
+               (make-edge
+                 :falling-right
+                 (non-bumping-guard :left walls others)
+                 #{[:on #{:right}]})
+               (make-edge
+                 :falling-left
+                 (non-bumping-guard :right walls others)
+                 #{[:on #{:left}]}))
+             (make-state
+               :falling-idle-left
+               {:y (- fall-speed)}
+               (bumping-transitions id :top :idle-left nil walls others)
+               (make-edge
+                 :falling-right
+                 (non-bumping-guard :left walls others)
+                 #{[:on #{:right}]})
+               (make-edge
+                 :falling-left
+                 (non-bumping-guard :right walls others)
+                 #{[:on #{:left}]}))
+             (make-state
+               :falling-right
+               {:x move-speed :y (- fall-speed)}
+               (bumping-transitions id :top :idle-right nil walls others)
+               (bumping-transitions id :left :falling-idle-right nil walls others)
+               (make-edge
+                 :falling-idle-right
+                 nil
+                 #{[:off #{:right}]})
+               (make-edge
+                 :falling-left
+                 nil
+                 #{[:on #{:left}]}))
+             (make-state
+               :falling-left
+               {:x (- move-speed) :y (- fall-speed)}
+               (bumping-transitions id :top :idle-left nil walls others)
+               (bumping-transitions id :right :falling-idle-left nil walls others)
+               (make-edge
+                 :falling-idle-left
+                 nil
+                 #{[:off #{:left}]})
+               (make-edge
+                 :falling-right
+                 nil
+                 #{[:on #{:right}]})))))

 (defn make-scene-a [] (let [ids #{:ga :gb :gc :gd :ge :m}
                             walls #{[0 0 256 8]
@@ -663,7 +740,7 @@
                                      (goomba :gc 11 25 16 :falling-left ids walls)
                                      (goomba :gd 64 8 16 :left ids walls)
                                      (goomba :ge 96 32 16 :right ids walls)
-                                     (mario :m 200 8 ids walls)]
+                                     (mario :m 200 64 ids walls)]
                             obj-ids (map :id objects)
                             obj-dict (zipmap obj-ids objects)
                             ; got to let every HA enter its current (initial) state to set up state invariants like


Make the code/chart toggle render as a link

--- src/foreclojure/problems.clj
+++ src/foreclojure/problems.clj
@@ -180,7 +180,9 @@
     (when settings
       [:div#golf-scores
        [:p#golfheader (str "Code Golf Score: " score)]
-       [:a.graph-class [:span#graph-link "View Chart"]]])))
+       [:a.graph-class {:href "#"
+                        :onclick "return false"}
+        [:span#graph-link "View Chart"]]])))

 (def-page code-box [id]
   (let [{:keys [title tags description restricted tests approved user]}


Korjattu pelaajan id:n haku

Korjattu pelaajan id:n haku

--- src/shl/dao/user.clj
+++ src/shl/dao/user.clj
@@ -39,10 +39,10 @@
 (defn- get-user-sql [username]
   (s/build :select [:u.* [:r.name "role"] [:p.id "playerid"]]
            :from [[:user_ :u]]
-           :join [[:role :r] [:= :r.id :u.roleid]]
-           :left-join [[:player :p] [:= :p.userid :u.id]
-                       [:conference :c] [:= :c.id :p.conferenceid]
-                       [:tournament :t] [:and [:= :t.id :c.tournamentid] [:= :t.active true]]]
+           :join [[:role :r] [:= :r.id :u.roleid]
+                  [:player :p] [:= :p.userid :u.id]
+                  [:conference :c] [:= :c.id :p.conferenceid]
+                  [:tournament :t] [:and [:= :t.id :c.tournamentid] [:= :t.active true]]]
            :where [:= :u.username username]
            :limit 1))


update list for workers in a hive

update list for workers in a hive

--- src/hivewing_core/worker.clj
+++ src/hivewing_core/worker.clj
@@ -2,6 +2,22 @@
   (:require [hivewing-core.configuration :refer [sql-db]]
             [hivewing-core.core :refer [ensure-uuid]]
             [clojure.java.jdbc :as jdbc]))
+
+(defn worker-list
+  "Gets the list of worker uuids. It is paginated
+   and per_page is limited.  Returns the total as well"
+  [hive-uuid & params]
+  (let [params   (into {:page 1, :per-page 50} (apply hash-map  params))
+        per-page (if (> (:per-page params) 100) 100 (:per-page params))
+        page     (:page params)
+        ]
+    (println params)
+    (println hive-uuid)
+    (map :uuid (jdbc/query sql-db ["SELECT uuid FROM workers WHERE hive_uuid = ? LIMIT ? OFFSET ?"
+                        (ensure-uuid hive-uuid)
+                        per-page
+                        (* (- page 1) per-page)])
+    )))

 (defn worker-get
   "Get the data for worker record.  You pass in the worker via the worker uuid.  Returns the data
@@ -10,8 +26,12 @@
   (jdbc/query sql-db ["SELECT * FROM workers WHERE uuid = ? LIMIT 1" (ensure-uuid worker-uuid)] :result-set-fn first))

 (defn worker-create
-  [parameters]
-  (first (jdbc/insert! sql-db :workers parameters)))
+  [{apiary-uuid :apiary_uuid hive-uuid :hive_uuid :as parameters}]
+
+  (let [clean-params (assoc parameters
+                            :apiary_uuid (ensure-uuid apiary-uuid)
+                            :hive_uuid (ensure-uuid hive-uuid))]
+    (first (jdbc/insert! sql-db :workers clean-params))))

 (defn worker-join-hive
   "Add a worker to a given hive. Removing it from a hive it was in before.


CMR-205: Added search by collection_data_type for collection search.

--- src/cmr/search/services/parameters.clj
+++ src/cmr/search/services/parameters.clj
@@ -1,6 +1,7 @@
 (ns cmr.search.services.parameters
   "Contains functions for parsing and converting query parameters to query conditions"
-  (:require [cmr.common.services.errors :as errors]
+  (:require [clojure.string :as s]
+            [cmr.common.services.errors :as errors]
             [cmr.search.models.query :as qm]
             [cmr.search.data.query-to-elastic :as q2e]
             [cmr.common.date-time-parser :as dt-parser]
@@ -16,6 +17,7 @@
                 :version :string
                 :updated-since :updated-since
                 :processing-level-id :string
+                :collection-data-type :collection-data-type
                 :temporal :temporal
                 :concept-id :string
                 :platform :string
@@ -135,6 +137,23 @@
       [(string-condition-with-options :granule-ur value options :readable-granule-name)
        (string-condition-with-options :producer-granule-id value options :readable-granule-name)])))

+(defmethod parameter->condition :collection-data-type
+  [concept-type param value options]
+  (if (sequential? value)
+    (if (= "true" (get-in options [param :and]))
+      (qm/and-conds
+        (map #(parameter->condition concept-type param % options) value))
+      (qm/or-conds
+        (map #(parameter->condition concept-type param % options) value)))
+    (let [nrt-aliases ["near_real_time","nrt", "NRT", "near real time","near-real time","near-real-time","near real-time"]
+          value (if (some #{value} nrt-aliases) "NEAR_REAL_TIME" value)]
+      (if (or (= "SCIENCE_QUALITY" value)
+              (and (= "SCIENCE_QUALITY" (s/upper-case value))
+                   (not= "false" (get-in options [:collection-data-type :ignore-case]))))
+        (qm/or-conds
+          [(string-condition-with-options :collection-data-type value options :collection-data-type)
+           (qm/map->MissingCondition {:field :collection-data-type})])
+        (string-condition-with-options :collection-data-type value options :collection-data-type)))))

 (defmethod parameter->condition :num-range
   [concept-type param value options]


Adding code accidentally missing from previous commit.

--- src/cmr/search/services/parameter_converters/spatial.clj
+++ src/cmr/search/services/parameter_converters/spatial.clj
@@ -17,4 +17,8 @@

 (defmethod p/parameter->condition :polygon
   [concept-type param value options]
-  (url-value->spatial-condition :polygon value))+  (url-value->spatial-condition :polygon value))
+
+(defmethod p/parameter->condition :bounding-box
+  [concept-type param value options]
+  (url-value->spatial-condition :br value))


Add volume control.

Add volume control.

--- src/kolmogorov_music/geb.clj
+++ src/kolmogorov_music/geb.clj
@@ -36,6 +36,7 @@
 (comment
   (map fx-chorus [0 1])
   (map fx-distortion [0 1] [0.8 0.6] [0.3 0.5])
+  (volume 0.8)
   (live/jam (var geb))
   (def geb nil)
   )


GAWB-1688: Works, but somehow still renders preview and then disappears it

--- src/cljs/main/broadfcui/common/gcs_file_preview.cljs
+++ src/cljs/main/broadfcui/common/gcs_file_preview.cljs
@@ -28,16 +28,17 @@
           (labeled "Google Bucket" (:bucket-name props))
           (labeled "Object" (:object props))
           [:div {:style {:marginTop "1em"}}
-           [:div {} "Previews for some filetypes may be unsupported. "]
+           [:div {} (when-not (= data-size "0") "Previews for some filetypes may be unsupported. ")]
            (when (> data-size preview-byte-count) (str "Last " (:preview-line-count @state)
                                                        " lines are shown. Use link below to view entire file."))
            ;; The max-height of 206 looks random, but it's so that the top line of the log preview is half cut-off
            ;; to hint to the user that they should scroll up.
-           (react/create-element
-             [:div {:ref "preview" :style {:marginTop "1em" :whiteSpace "pre-wrap" :fontFamily "monospace"
-                                           :fontSize "90%" :overflowY "auto" :maxHeight 206
-                                           :backgroundColor "#fff" :padding "1em" :borderRadius 8}}
-              (str (if (> data-size preview-byte-count) "...") (:preview @state))])]
+           (when-not (= data-size "0")
+             (react/create-element
+               [:div {:ref "preview" :style {:marginTop "1em" :whiteSpace "pre-wrap" :fontFamily "monospace"
+                                             :fontSize "90%" :overflowY "auto" :maxHeight 206
+                                             :backgroundColor "#fff" :padding "1em" :borderRadius 8}}
+                (str (if (> data-size preview-byte-count) "...") (:preview @state))]))]
           (when (:loading? @state)
             [Spinner {:text "Getting file info..."}])
           (when data
@@ -86,14 +87,14 @@
    (fn [{:keys [props state refs after-update]}]
      (swap! state assoc :loading? true)
      (endpoints/call-ajax-orch
-      {:endpoint (endpoints/get-gcs-stats (:bucket-name props) (:object props))
-       :on-done (fn [{:keys [success? get-parsed-response xhr status-code]}]
-                  (swap! state assoc
-                         :loading? false
-                         :response (if success?
-                                     {:data (get-parsed-response)}
-                                     {:error (.-responseText xhr)
-                                      :status status-code})))})
+       {:endpoint (endpoints/get-gcs-stats (:bucket-name props) (:object props))
+        :on-done (fn [{:keys [success? get-parsed-response xhr status-code]}]
+                   (swap! state assoc
+                          :loading? false
+                          :response (if success?
+                                      {:data (get-parsed-response)}
+                                      {:error (.-responseText xhr)
+                                       :status status-code})))})
      (utils/ajax {:url (str "https://www.googleapis.com/storage/v1/b/" (:bucket-name props) "/o/"
                             (js/encodeURIComponent (:object props)) "?alt=media")
                   :headers {"Authorization" (str "Bearer " (utils/get-access-token))


workaround for tentacles contributors bug

--- src/github_contributions/github.clj
+++ src/github_contributions/github.clj
@@ -24,12 +24,19 @@
 (defn fetch-repos [user]
   (user-repos user (assoc (gh-auth) :all-pages true)))

+;;; get around tentacles bug
+(defn fetch-contributors [user repo]
+  (let [cs (contributors user repo (gh-auth))]
+    (if (= (last cs) {})
+      (vec (drop-last 1 cs))
+      cs)))
+
 (defn fetch-fork-info [user repo]
   (log/info :msg (format "Fetching fork info for %s/%s" user repo))
   (let [repo-map (specific-repo user repo (gh-auth))
         full-name (get-in! repo-map [:parent :full_name])
         [_ parent-user parent-repo] (re-find #"([^/]+)/([^/]+)" full-name)
-        contribs (->> (contributors parent-user parent-repo (gh-auth))
+        contribs (->> (fetch-contributors parent-user parent-repo)
                       (sort-by :contributions)
                       reverse
                       (map-indexed (fn [num elem] (assoc elem :num num))))


test hook

test hook

--- src/main/cawala/api/read.clj
+++ src/main/cawala/api/read.clj
@@ -6,7 +6,7 @@
                      :person/relation :friend}
                  2  {:db/id 2 :person/name "Sally" :person/age 22
                      :person/relation :friend}
-                 3  {:db/id 3 :person/name "Allie" :person/age 50
+                 3  {:db/id 3 :person/name "Allie" :person/age 51
                      :person/relation :enemy}
                  4  {:db/id 4 :person/name "Zoe" :person/age 32
                      :person/relation :friend}


more perf tweaks

more perf tweaks

--- src/main/cljs/cljs/core.cljs
+++ src/main/cljs/cljs/core.cljs
@@ -9883,13 +9883,17 @@
         ".."
         (demunge-str (str name))))))

+(defn- ns-lookup [ns-obj k]
+  (fn [] (gobject/get ns-obj k)))
+
 (deftype Namespace [obj name]
   Object
   (findInternedVar [this sym]
     (let [k (munge (str sym))]
-      (when (gobject/containsKey obj k)
-        (Var. #(gobject/get obj k)
-          (symbol (str name) (str sym)) {:ns this}))))
+      (when ^boolean (gobject/containsKey obj k)
+        (let [var-sym (symbol (str name) (str sym))
+              var-meta {:ns this}]
+          (Var. (ns-lookup obj k) var-sym var-meta)))))
   (getName [_] name)
   (toString [_]
     (str name))
@@ -9949,14 +9953,17 @@
    (Namespace. ns-obj sym)))

 (defn find-ns [ns]
-  (when-let [ns-obj (find-ns-obj ns)]
-    (create-ns ns ns-obj)))
+  (let [ns-obj (find-ns-obj ns)]
+    (when-not (nil? ns-obj)
+      (create-ns ns ns-obj))))

 (defn find-macros-ns [ns]
-  (let [ns (cond-> ns
-             (not (gstring/contains (str ns) "$macros"))
-             (-> (str "$macros") symbol))]
-    (when-let [ns-obj (find-ns-obj ns)]
+  (let [ns-str (str ns)
+        ns (if (not ^boolean (gstring/contains ns-str "$macros"))
+             (symbol (str ns-str "$macros"))
+             ns)
+        ns-obj (find-ns-obj ns)]
+    (when-not (nil? ns-obj)
       (create-ns ns ns-obj))))

 (defn ns-name [ns-obj]


Add and remove files from tracker

Add and remove files from tracker

--- src/main/clojure/clojure/tools/namespace/tracker.clj
+++ src/main/clojure/clojure/tools/namespace/tracker.clj
@@ -18,23 +18,34 @@
       (remove-deps new-decls)
       (add-deps new-decls)))

-(defn- affected-namespaces [deps new-decls]
-  (let [new-names (map second new-decls)]
-    (apply set/union
-           (set new-names)
-           (map #(dep/transitive-dependents deps %) new-names))))
+(defn- affected-namespaces [deps new-names]
+  (apply set/union
+         (set new-names)
+         (map #(dep/transitive-dependents deps %) new-names)))

-(defn tracker []
+(defn tracker
+  "Returns a new namespace dependency tracker."
+  []
   {:deps (dep/graph)
-   :unload []
-   :load []})
+   :unload ()
+   :load ()
+   :namespaces {}})

-(defn update [state files]
-  (let [{:keys [load unload deps]} state
-        new-decls (keep tns/read-file-ns-decl files)
+(defn add-files
+  "Reads ns declarations from files; returns an updated dependency
+  tracker indicating which namespaces need to be reloaded after files
+  were added."
+  [state files]
+  (let [{:keys [load unload deps namespaces]} state
+        new-pairs (keep (fn [file]
+                          (when-let [decl (tns/read-file-ns-decl file)]
+                            [file decl]))
+                        files)
+        new-decls (map second new-pairs)
         new-deps (update-deps deps new-decls)
-        changed (affected-namespaces deps new-decls)]
+        changed (affected-namespaces deps (map second new-decls))]
     (assoc state
+      :namespaces (into namespaces new-pairs)
       :deps new-deps
       :unload (distinct
                (concat (reverse (sort (dep/topo-comparator deps) changed))
@@ -43,7 +54,30 @@
              (concat (sort (dep/topo-comparator new-deps) changed)
                      load)))))

-(defn reload-one [state]
+(defn remove-files
+  "Returns an updated dependency tracker indicating which namespaces
+  need to be reloaded after files were removed."
+  [state files]
+  (let [{:keys [load unload deps namespaces]} state
+        removed (keep (comp second namespaces) files)
+        new-deps (reduce dep/remove-key deps removed)
+        changed (affected-namespaces deps removed)]
+    (assoc state
+      :namespaces (apply dissoc namespaces files)
+      :deps new-deps
+      :unload (distinct
+               (concat (reverse (sort (dep/topo-comparator deps) changed))
+                       unload))
+      :load (distinct
+             (filter (complement (set removed))
+                     (concat (sort (dep/topo-comparator new-deps) changed)
+                             load))))))
+
+(defn reload-one
+  "Executes one unload/reload operation; returns updated dependency
+  tracker indicating errors and which namespaces remain to be
+  removed/reloaded."
+  [state]
   (let [{:keys [unload load]} state]
     (cond
       (seq unload)
@@ -59,7 +93,11 @@
       :else
         state)))

-(defn reload-all [state]
+(defn reload
+  "Executes remove/reload operations on a dependency tracker until
+  either an error is encountered or there are no more pending
+  operations."
+  [state]
   (loop [state (dissoc state :error)]
     (let [{:keys [unload load error]} state]
       (if (and (or (seq load) (seq unload))


fix macro doc regression caused by fcd158

--- src/main/clojure/cljs/analyzer.cljc
+++ src/main/clojure/cljs/analyzer.cljc
@@ -558,7 +558,8 @@
             (throw err#)
             (throw (error ~env (.getMessage err#) err#)))))))

-(def implicit-nses '#{cljs.core goog goog.object goog.string goog.array Math})
+;; namespaces implicit to the inclusion of cljs.core
+(def implicit-nses '#{goog goog.object goog.string goog.array Math})

 (defn implicit-import?
   #?(:cljs {:tag boolean})
@@ -619,7 +620,8 @@
   "Given env, an analysis environment, and ns-sym, a symbol identifying a
    namespace, confirm that the namespace exists. Warn if not found."
   [env ns-sym]
-  (when (and (nil? (get implicit-nses ns-sym))
+  (when (and (not= 'cljs.core ns-sym)
+             (nil? (get implicit-nses ns-sym))
              (nil? (get (-> env :ns :requires) ns-sym))
              ;; something else may have loaded the namespace, i.e. load-file
              (nil? (gets @env/*compiler* ::namespaces ns-sym))


solutions for matrix results

solutions for matrix results

--- src/main/clojure/dojo/solutions.clj
+++ src/main/clojure/dojo/solutions.clj
@@ -8,19 +8,26 @@
 ;; There is no right answer.....
 ;; But here are some suggested ideas / solutions for the challenge

+;; ========================================================================
+;; Challenge 1: computing stats for each team
+
+;; handy utility function to get a names column
+(defn col [v col-name]
+  (mget v (COL-NUMS col-name)))
+
 ;; a map of column names -> column data
 (def COLS (zipmap HEADINGS (for [h HEADINGS] (get-column RESULTS (COL-NUMS h)))))

 ;; matrix of home games for each team: 1 = home game, 0 = otherwise
-(def HOME-GAMES (vec (for [team TEAMS] (mapv #(if (= team (mget % (COL-NUMS "HomeTeam"))) 1 0) (slices RESULTS)))))
+(def HOME-GAMES (vec (for [team TEAMS] (mapv #(if (= team (col % "HomeTeam")) 1 0) (slices RESULTS)))))

 ;; matrix of away games for each team: 1 = home game, 0 = otherwise
-(def AWAY-GAMES (vec (for [team TEAMS] (mapv #(if (= team (mget % (COL-NUMS "AwayTeam"))) 1 0) (slices RESULTS)))))
+(def AWAY-GAMES (vec (for [team TEAMS] (mapv #(if (= team (col % "AwayTeam")) 1 0) (slices RESULTS)))))

 ;; vectors of result types for each match
-(def HWINS (mapv #(if (= "H" (mget % (COL-NUMS "FTR"))) 1 0) (slices RESULTS)))
-(def DRAWS (mapv #(if (= "D" (mget % (COL-NUMS "FTR"))) 1 0) (slices RESULTS)))
-(def AWINS (mapv #(if (= "A" (mget % (COL-NUMS "FTR"))) 1 0) (slices RESULTS)))
+(def HWINS (mapv #(if (= "H" (col % "FTR")) 1 0) (slices RESULTS)))
+(def DRAWS (mapv #(if (= "D" (col % "FTR")) 1 0) (slices RESULTS)))
+(def AWINS (mapv #(if (= "A" (col % "FTR")) 1 0) (slices RESULTS)))

 ;; check we have captured all games
 (esum (add HWINS AWINS DRAWS))
@@ -35,3 +42,78 @@

 ;; percentages
 (def HOME-WIN-PERCENTAGE (/ HOME-WINS 19.0)) ;; note: division of vector by a scalar
+
+;; wins, draws, losses for each team
+(def TEAM-RESULTS
+  (transpose [(+ HOME-WINS AWAY-WINS) DRAW-RESULTS (+ HOME-LOSSES AWAY-LOSSES)]))
+
+;; end of season points for each team (3 = win, 1 = draw, 0 = loss)
+(def TEAM-POINTS
+  (inner-product TEAM-RESULTS [3 1 0]))
+
+;; create a sorted league table
+(def LEAGUE-TABLE
+  (sort-by #(- (second %)) (zipmap TEAMS TEAM-POINTS)))
+
+;; Should match the Pts results at:
+;;   http://en.wikipedia.org/wiki/2012%E2%80%9313_Premier_League
+
+;; pretty-print the results
+(comment
+  (pm LEAGUE-TABLE)
+)
+;; ========================================================================
+;; Challenge 2: matrices of results
+
+;; create a sorted map of TeamName -> team number (for array indexing)
+(def TEAM-NUMS
+  (into (sorted-map) (zipmap TEAMS (range))))
+
+;; 20x20 matrix of goals for home team
+(def HOME-GOALS
+  (reduce
+    (fn [m v]
+      (mset m
+            (TEAM-NUMS (col v "HomeTeam"))
+            (TEAM-NUMS (col v "AwayTeam"))
+            (read-string (col v "FTHG"))))
+    (zero-matrix 20 20)
+    (slices RESULTS)))
+
+;; 20x20 matrix of goals for away team
+(def AWAY-GOALS
+  (reduce
+    (fn [m v]
+      (mset m
+            (TEAM-NUMS (col v "HomeTeam"))
+            (TEAM-NUMS (col v "AwayTeam"))
+            (read-string (col v "FTAG"))))
+    (array (repeat 20 (repeat 20 "-")))
+    (slices RESULTS)))
+
+(defn match-result
+  "Helper function to calculate the result of a match, given home goals and away goals"
+  ([hg ag]
+      (cond
+        (or (string? hg) (string? ag)) "-"
+        (> hg ag) "W"
+        (< hg ag) "L"
+        :else "D")))
+
+;; use 'emap' compare these element-by-element to get 20x20 matrix of match results
+(def MATCH-RESULTS
+  (emap
+    match-result
+    HOME-GOALS
+    AWAY-GOALS))
+
+;; print out the match results
+(comment
+  (pm MATCH-RESULTS)
+)
+
+
+;; ========================================================================
+;; Challenge 3: time series
+
+;; TODO


add definition to set url for embeds (#12)

--- src/main/resources/sandbox-init.clj
+++ src/main/resources/sandbox-init.clj
@@ -26,5 +26,6 @@
   (def embed-color (memfn withColor r g b))
   (def embed-image (memfn withImage url))
   (def embed-thumb (memfn withThumbnail url))
+  (def embed-url   (memfn withUrl url))
   (def embed-build (memfn build))
 )


Speedtest is code-complete, but entirely untested (and unproven)

--- src/net/slreynolds/ds/speedtest.clj
+++ src/net/slreynolds/ds/speedtest.clj
@@ -1,6 +1,6 @@
 (ns net.slreynolds.ds.speedtest)

-;;; Does not work yet
+;;; Caution: does not work yet

 ; Warmup the jit compiler etc in the JVM
 ; before doing any measurements
@@ -60,23 +60,24 @@
       (print "Times (seconds)")
       (print times))))

+; setup implmentation for std clojure hashmap
 (defn htsetup[]
   (let [is (range 0 (- IntMapSource/initialSize 1))
         vs (map #(SomeValue. %) is)
         themap (hash-map (interleave is vs))]
     themap))

+; dowork implementation for std clojure hashmap
 (defn htdowork[themap]
   ; Note doing a lot of extra work here!
-  ; Making a list ahead of time would be better
-  (let [vs (list IntMapSource/valuesToInsert)]
-    (loop [map themap
-          [firstv restv]]
-      (if (nilp restv)
-        (dosomething)
-        (do
-          (somemmthing)
-          (recur blah blah))))))
+  ; Making a list ahead of time is very important!!!!
+  (let [list-of-vs (list IntMapSource/valuesToInsert)]
+    (loop [newmap themap
+           vs list-of-vs]
+      (if (empty vs)
+        newmap
+        (recur (assoc newmap (first vs) (rest vs)))))

+; Run the test for std clojure hashmap
 (defn htrun[]
   (run htsetup htdowork "Clojure hash map"))


Fix typos

Fix typos

--- src/org/spootnik/cyanite/config.clj
+++ src/org/spootnik/cyanite/config.clj
@@ -169,8 +169,8 @@
         (update-in [:stats] (partial merge default-stats))
         (update-in [:store] (partial merge default-store))
         (update-in [:store] get-instance :store)
-        (update-in [:store-middelware] (partial merge default-store-middleware))
-        (update-in [:store-middelware] get-instance :store-middelware)
+        (update-in [:store-middleware] (partial merge default-store-middleware))
+        (update-in [:store-middleware] get-instance :store-middleware)
         (config-store-cache)
         (update-in [:carbon] (partial merge default-carbon))
         (update-in [:carbon :rollups] convert-shorthand-rollups)


cleanup

cleanup

--- src/name_bazaar/ui/core.cljs
+++ src/name_bazaar/ui/core.cljs
@@ -1,23 +1,23 @@
 (ns name-bazaar.ui.core
   (:require
-   [cljs-time.extend]
-   [cljs.spec.alpha :as s]
-   [cljsjs.material-ui]
-   [cljsjs.react-flexbox-grid]
-   [cljsjs.web3]
-   [district0x.ui.events]
-   [district0x.ui.subs]
-   [madvas.re-frame.google-analytics-fx :as google-analytics-fx]
-   [name-bazaar.ui.components.main-panel :refer [main-panel]]
-   [name-bazaar.ui.constants :as constants]
-   [name-bazaar.ui.db]
-   [name-bazaar.ui.events]
-   [name-bazaar.ui.subs]
-   [print.foo :include-macros true]
-   [re-frame.core :refer [dispatch dispatch-sync clear-subscription-cache!]]
-   [re-frisk.core :refer [enable-re-frisk!]]
-   [reagent.core :as r]
-   [district0x.ui.utils :as d0x-ui-utils]))
+    [cljs-time.extend]
+    [cljs.spec.alpha :as s]
+    [cljsjs.material-ui]
+    [cljsjs.react-flexbox-grid]
+    [cljsjs.web3]
+    [district0x.ui.events]
+    [district0x.ui.subs]
+    [madvas.re-frame.google-analytics-fx :as google-analytics-fx]
+    [name-bazaar.ui.components.main-panel :refer [main-panel]]
+    [name-bazaar.ui.constants :as constants]
+    [name-bazaar.ui.db]
+    [name-bazaar.ui.events]
+    [name-bazaar.ui.subs]
+    [print.foo :include-macros true]
+    [re-frame.core :refer [dispatch dispatch-sync clear-subscription-cache!]]
+    [re-frisk.core :refer [enable-re-frisk!]]
+    [reagent.core :as r]
+    [district0x.ui.utils :as d0x-ui-utils]))

 (def debug?
   ^boolean js/goog.DEBUG)


State.

State.

--- test/com/nomistech/clojure_the_language/c_400_state_and_concurrency/s_020_atoms.clj
+++ test/com/nomistech/clojure_the_language/c_400_state_and_concurrency/s_020_atoms.clj
@@ -148,7 +148,7 @@
                 (.start (Thread. long-running-inc-on-atom!))))
             (report-on-what-is-happening []
               (loop []
-                (println (get-info))
+                (println "[value n-attempts] =" (get-info))
                 (when (< @competing-updates-atom
                          n-competitors)
                   (Thread/sleep 1000)


changes to loader.clj to make kondo/codeclimate more happy (#160)

* make kondo and codeclimate as happy as they can be

* more comments on why i did what i did

--- src/yetibot/core/loader.clj
+++ src/yetibot/core/loader.clj
@@ -1,6 +1,6 @@
 (ns yetibot.core.loader
   (:require
-   [taoensso.timbre :refer [debug info warn error]]
+   [taoensso.timbre :refer [debug info warn]]
    [yetibot.core.config :refer [get-config]]
    [clojure.spec.alpha :as s]
    [yetibot.core.spec :as yspec]
@@ -22,15 +22,22 @@
 (defn plugins-config []
   (get-config ::plugins-config [:plugins]))

-(defn all-namespaces []
+(defn all-namespaces
+  "find and return all namespaces found on the (system)classpath"
+  []
   (concat
    (ns/find-namespaces (cp/system-classpath))
    (ns/find-namespaces (cp/classpath))))

-(defn find-namespaces [pattern]
+(defn find-namespaces
+  "find-n-filter namespaces based on a provided pattern"
+  [pattern]
   (->> (all-namespaces)
        (filter #(re-matches pattern (str %)))
        (distinct)))
+
+; mycompany.plugins.commands.*
+(def all-command-plugins-regex #"^.*plugins\.commands.*")

 (def yetibot-command-namespaces
   [;; support for e.g.:
@@ -38,44 +45,72 @@
    ;; yetibot.core.commands.*
    ;; yetibot-pluginname.commands.*
    #"^yetibot(\S*)\.(core\.)?commands.*"
-   ;; mycompany.plugins.commands.*
-   #"^.*plugins\.commands.*"
+   all-command-plugins-regex
    ])

 (comment
   (find-namespaces
     (first yetibot-command-namespaces)))

+; mycompany.plugins.observers.*
+(def all-observer-plugins-regex #"^.*plugins\.observers.*")
+
 (def yetibot-observer-namespaces
-  [#"^yetibot\.(core\.)?observers.*" #"^.*plugins\.observers.*"])
+  [#"^yetibot\.(core\.)?observers.*"
+   all-observer-plugins-regex
+   ])
+
+(comment
+  (find-namespaces
+   (first yetibot-observer-namespaces)))

 (def yetibot-all-namespaces
-  (merge
-    (map last [yetibot-command-namespaces
-               yetibot-observer-namespaces])
-    ; with a negative lookahead assertion
-    #"^yetibot\.(.(?!(core)))*"))
+  ;; to mimic previous return type of (merge), using (list) vs plain old vector
+  ;; in theory, it should not matter (lazy vs non-lazy) -- but don't want to risk it
+  (list all-command-plugins-regex
+        all-observer-plugins-regex
+        #"^yetibot\.(.(?!(core)))*"    ; with a negative lookahead assertion
+  ))
+
+(comment
+  yetibot-all-namespaces
+  )

 (defn load-ns [arg]
   (debug "Loading" arg)
-  (try (require arg)
-       arg
-       (catch Exception e
-         (warn "WARNING: problem requiring" arg "hook:" (.getMessage e))
-         (st/print-stack-trace (st/root-cause e) 15))))
+  (try
+    (require arg)
+    arg
+    (catch Exception e
+      (warn "WARNING: problem requiring" arg "hook:" (.getMessage e))
+      (st/print-stack-trace (st/root-cause e) 15))))
+
+(comment
+  (load-ns 'yetibot.core.commands.help)
+  (load-ns 'i.will.fail)
+  )

 (defn find-and-load-namespaces
   "Find namespaces matching ns-patterns: a seq of regex patterns. Load the matching
    namespaces and return the seq of matched namespaces."
   [ns-patterns]
-  (let [nss (flatten (map find-namespaces ns-patterns))]
-    (info "☐ Loading" (count nss) "namespaces matching" ns-patterns)
-    (dorun (map load-ns nss))
-    (info "☑ Loaded" (count nss) "namespaces matching" ns-patterns)
+  (let [nss (flatten (map find-namespaces ns-patterns))
+        nss-count-output (str (count nss) " namespaces matching " ns-patterns)]
+    (info "☐ Loading" nss-count-output)
+    (doseq [n nss] (load-ns n))
+    (info "☑ Loaded" nss-count-output)
     nss))
+
+(comment
+  (find-and-load-namespaces '(#"yetibot\.core\.commands\.help"))
+  )

 (defn load-commands []
   (find-and-load-namespaces yetibot-command-namespaces))
+
+(comment
+  (load-commands)
+  )

 (defn load-observers []
   (find-and-load-namespaces yetibot-observer-namespaces))
@@ -99,6 +134,10 @@
        plugins)
       (info "There are no plugins configured to load"))))

+(comment
+  (load-plugins)
+  )
+
 (defn load-all
   "Load all plugins, observers, and commands.


Added export expiry days to config

Added export expiry days to config

--- src/polismath/components/config.clj
+++ src/polismath/components/config.clj
@@ -2,8 +2,7 @@
   (:require [polismath.utils :as utils]
             [clojure.tools.logging :as log]
             [com.stuartsierra.component :as component]
-            [environ.core :as environ]
-            ))
+            [environ.core :as environ]))

 (defn ->long [x]
@@ -28,6 +27,7 @@
    :primary-polis-url :localhost ;; Must do it in the component load...
    :database   {:pool-size 3}
    :math-schema-date "2014_08_22"
+   :export-expiry-days 10
    })

 (def rules
@@ -58,6 +58,8 @@
                                 :doc "API key for graphite db (perf monitoring)"}
    :hostedgraphite-hostname    {:path [:meta :graphite :hostname]
                                 :doc "The hostname for sending messages to graphite"}
+   :export-expiry-days         {:path [:export :expiry-days] :parse ->long
+                                :doc "The number of days before a mongo record representing a data exports gets removed"}
    ;; XXX TODO & Thoughts
    ;; Mini batch sizes (see polismath.math.conversation)
    })


Work on toolbox...

Work on toolbox...

Use custom-dialog instead of JWindow.

* The dialog is modal and returns the new selection.
* The dialog is created in popup-toolbox instead of toolbox
  since it is good for one use only.

Use protocols and datatypes

* Added Toolbox datatype.
* Extend ToWidget, Selection, MakeWidget, and Value protocols.
* Use Toolbox in place of previous swing widget.
* Use Toolbox to store tool selection, no need for button-group.

TODO:
* add a real example.
* change the cursor to show which tool is active.
* use custom icons.

--- src/overtone/gui/toolbox.clj
+++ src/overtone/gui/toolbox.clj
@@ -1,51 +1,88 @@
 (ns overtone.gui.toolbox
-  (:use [seesaw.core])
+  (:use [seesaw core
+         [selection :only [Selection]]
+         [make-widget :only [MakeWidget]]
+         [to-widget :only [ToWidget]]
+         [value :only [Value]]])
   (:import javax.swing.JWindow
            java.awt.MouseInfo))

+(defrecord Toolbox [tools primary secondary])
+
+(extend-type Toolbox
+
+  ToWidget
+  (to-widget* [tbox] tbox)
+
+  Selection
+  (get-selection [tbox]
+    (list @(:primary tbox)))
+  (set-selection [tbox [v]]
+    (reset! (:primary tbox) v))
+
+  MakeWidget
+  (make-widget* [tbox]
+    (invoke-now
+     (flow-panel :align :left :items (:tools tbox))))
+
+  Value
+  (container?* [tbox] false)
+  (value* [tbox]
+    (let [{:keys [primary secondary]} tbox]
+      {:primary @primary :secondary @secondary}))
+  (value!* [tbox v]
+    (let [{:keys [primary secondary]} v]
+      (reset! (:primary tbox) primary)
+      (reset! (:secondary tbox) secondary)
+      (value tbox))))
+
 (defn tool
-  "Returns a new tool (a tqoggle-button for now) for the given tool-spec."
+  "Returns a new tool (a button for now) for the given tool-spec."
   [& tool-spec]
   (let [tool-spec (if (= (count tool-spec) 1)
                     (first tool-spec)
                     tool-spec)
         tool-spec ((comp flatten seq) tool-spec)]
-
-  (apply toggle tool-spec)))
+    (apply button tool-spec)))

 (def ^:private pointer-spec
   {:id :pointer
    :text "Pointer"
+   :cursor :default
    :selected? true})

 (def ^:private hand-spec
   {:id :hand
-   :text "Hand"})
+   :text "Hand"
+   :cursor :hand})

-(defn toolbox-bg
-  [& tool-specs]
-  (let [tool-specs (or (not-empty tool-specs)
-                       [pointer-spec hand-spec])
-        tools      (map tool tool-specs)]
+(defn default-tools
+  []
+  (map tool [pointer-spec hand-spec]))

-    (button-group :buttons tools)))
+(defn- add-behavior
+  ([tbox]
+     (let [tools (:tools tbox)]
+       (listen tools :mouse-clicked
+               (fn [e]
+                 (let [id (id-of e)]
+                   (selection! tbox [(to-widget e)])
+                   (return-from-dialog e (id-of e)))))
+       tbox)))

 (defn toolbox
-  "Create a temporary popup window containing a set of selectable tools."
+  "Create a Toolbox instance with a set of 'clickable' tools and initial primary
+   and secondary tool selections."
   ([]
-     (toolbox (toolbox-bg)))
-  ([tools-bg]
-     (invoke-now
-      (let [popup (JWindow.)
-            tools (enumeration-seq (.getElements tools-bg))
-            body (flow-panel :align :left :items tools)]
+     (toolbox (default-tools)))
+  ([tools]
+     (let [primary   (or (first (filter :selected? tools))
+                         (first tools))
+           secondary (or (second (filter :selected? tools))
+                         primary)]

-        (listen tools-bg :mouse-clicked (fn [e] (hide! popup)))
-
-        (doto popup
-          (.add body)
-          (.pack))
-        popup))))
+       (add-behavior
+        (Toolbox. tools (atom primary) (atom secondary))))))

 (def ^:dynamic *toolbox* (toolbox))

@@ -57,8 +94,7 @@
   ([]
      (current-tool *toolbox*))
   ([tbox]
-     ((comp key first) (filter (comp true? val)
-                               (value tbox)))))
+     (id-of (selection tbox))))

 (defn popup-toolbox
   "Show the toolbox until clicked."
@@ -67,17 +103,16 @@
   ([tbox]
      (popup-toolbox tbox :to (mouse-location)))
   ([tbox & opts]
-     (apply move! tbox opts)
-     (show! tbox)))
+     (let [popup (custom-dialog :modal? true :content tbox)]
+       (apply move! popup opts)
+       (-> popup
+           pack!
+           show!))))

 (comment
-
   ;; global toolbox
   (popup-toolbox)
   (current-tool)
-
-  ;;local toolbox
-  (toolbox (toolbox-bg))

   ;; thread-local toolbox.
   (binding [*toolbox* (toolbox)]


Corrected whitespace nonesense

Corrected whitespace nonesense

--- src/leiningen/new/figwheel/project.clj
+++ src/leiningen/new/figwheel/project.clj
@@ -17,23 +17,23 @@
   :source-paths ["src"]

   :cljsbuild {
-              :builds [{:id "dev"
-                        :source-paths ["src"]
-                        :compiler {:output-to "resources/public/js/compiled/{{sanitized}}.js"
-                                   :output-dir "resources/public/js/compiled/out"
-                                   :optimizations :none
-                                   :source-map true
-                                   :source-map-timestamp true
-                                   :cache-analysis true }}
-                       {:id "min"
-                        :source-paths ["src"]
-                        :compiler {:output-to "resources/public/{{sanitized}}.min.js"
-                                   :optimizations :advanced
-                                   :pretty-print false}}]}
+   :builds [{:id "dev"
+             :source-paths ["src"]
+             :compiler {:output-to "resources/public/js/compiled/{{sanitized}}.js"
+                        :output-dir "resources/public/js/compiled/out"
+                        :optimizations :none
+                        :source-map true
+                        :source-map-timestamp true
+                        :cache-analysis true }}
+            {:id "min"
+             :source-paths ["src"]
+             :compiler {:output-to "resources/public/{{sanitized}}.min.js"
+                        :optimizations :advanced
+                        :pretty-print false}}]}

   :figwheel {
              :http-server-root "public" ;; default and assumes "resources"
-             :server-port 3449          ;; default
+             :server-port 3449 ;; default
              :css-dirs ["resources/public/css"] ;; watch and update CSS

              ;; Server Ring Handler (optional)


rename constant

rename constant

--- src/panpan/github/search.clj
+++ src/panpan/github/search.clj
@@ -4,8 +4,11 @@
     [clj-http.client   :as client]
     [clojure.data.json :as json]))

-(def ^:const SEARCH_API
+(def ^:const SEARCH_ISSUE
   "https://api.github.com/search/issues")
+
+(def ^:const SEARCH_REPOSITORY
+  "https://api.github.com/search/repositories")

 (defn- parse-json
   [s]
@@ -23,7 +26,7 @@
   (some->> {:assignee username}
            (merge option)
            map->query
-           (str SEARCH_API "?q=")
+           (str SEARCH_ISSUE "?q=")
            client/get
            :body
            parse-json


CMR-3409: Corrected namespace reference for queue-broker

--- access-control-app/dev/user.clj
+++ access-control-app/dev/user.clj
@@ -15,7 +15,7 @@
    [cmr.common.jobs :as jobs]
    [cmr.common.lifecycle :as l]
    [cmr.common.log :as log :refer (debug info warn error)]
-   [cmr.message-queue.services.queue :as queue]
+   [cmr.message-queue.queue.queue-broker :as queue-broker]
    [cmr.message-queue.test.queue-broker-side-api :as queue-broker-side-api]
    [cmr.message-queue.test.queue-broker-wrapper :as queue-broker-wrapper]
    [cmr.metadata-db.system :as mdb]
@@ -71,7 +71,7 @@

   (let [queue-broker (queue-broker-wrapper/create-queue-broker-wrapper
                       (if use-external-mq?
-                        (queue/create-queue-broker (int-test-util/queue-config))
+                        (queue-broker/create-queue-broker (int-test-util/queue-config))
                         (int-test-util/create-memory-queue-broker)))]
     ;; Start side api server
     (alter-var-root


Make tile renderer functions behave like their LibGDX equivalents

--- src/play_clj/core_render.clj
+++ src/play_clj/core_render.clj
@@ -49,21 +49,20 @@
     s))

 (defn orthogonal-tiled-map
-  [path ppt]
-  (OrthogonalTiledMapRenderer. ^TiledMap (tiled-map path) ^double (/ 1 ppt)))
+  [path unit]
+  (OrthogonalTiledMapRenderer. ^TiledMap (tiled-map path) ^double unit))

 (defn isometric-tiled-map
-  [path ppt]
-  (IsometricTiledMapRenderer. ^TiledMap (tiled-map path) ^double (/ 1 ppt)))
+  [path unit]
+  (IsometricTiledMapRenderer. ^TiledMap (tiled-map path) ^double unit))

 (defn isometric-staggered-tiled-map
-  [path ppt]
-  (IsometricStaggeredTiledMapRenderer. ^TiledMap (tiled-map path)
-                                       ^double (/ 1 ppt)))
+  [path unit]
+  (IsometricStaggeredTiledMapRenderer. ^TiledMap (tiled-map path) ^double unit))

 (defn hexagonal-tiled-map
-  [path ppt]
-  (HexagonalTiledMapRenderer. ^TiledMap (tiled-map path) ^double (/ 1 ppt)))
+  [path unit]
+  (HexagonalTiledMapRenderer. ^TiledMap (tiled-map path) ^double unit))

 (defn stage
   []


:lipstick: Minor changes.

:lipstick: Minor changes.

--- frontend/src/uxbox/main/ui/workspace/header.cljs
+++ frontend/src/uxbox/main/ui/workspace/header.cljs
@@ -65,8 +65,9 @@
 (mf/defc header
   [{:keys [page file layout] :as props}]
   (let [toggle-layout #(st/emit! (dw/toggle-layout-flag %))
-        on-undo #(st/emit! (udu/undo))
-        on-redo #(st/emit! (udu/redo))
+        on-undo (constantly nil)
+        on-redo (constantly nil)
+
         on-image #(modal/show! import-image-modal {})
         ;;on-download #(udl/open! :download)
         selected-drawtool (mf/deref refs/selected-drawing-tool)


Speed up LCA a bit.

Speed up LCA a bit.

--- src/replikativ/crdt/cdvcs/meta.cljc
+++ src/replikativ/crdt/cdvcs/meta.cljc
@@ -7,6 +7,17 @@
   (:require [clojure.set :as set]
             [replikativ.environ :refer [*date-fn*]]))

+
+;; adapted from clojure.set, but is faster if the intersection is small
+;; where intereseciton in clojure.set is faster when the intersection is large
+(defn intersection [s1 s2]
+  (if (< (count s2) (count s1))
+    (recur s2 s1)
+    (reduce (fn [result item]
+              (if (contains? s2 item)
+                (conj result item)
+                result))
+            #{} s1)))

 (defn consistent-graph? [graph]
   (let [parents (->> graph vals (map set) (apply set/union))
@@ -32,7 +43,7 @@
          new-heads-b (set (mapcat graph-b heads-b))
          visited-a (set/union visited-a new-heads-a)
          visited-b (set/union visited-b new-heads-b)
-         lcas (set/intersection visited-a visited-b)]
+         lcas (intersection visited-a visited-b)]
      (if (and (not (empty? lcas))
               ;; keep going until all paths of b are in graph-a to
               ;; complete visited-b.


Ignore nil id values in akvo.lumen.lib.auth/ids

--- backend/src/akvo/lumen/lib/auth.clj
+++ backend/src/akvo/lumen/lib/auth.clj
@@ -197,13 +197,16 @@
   "returns `{:dataset-ids #{id...} :dashboard-ids #{id...} :visualisation-ids #{id...} :collection-ids #{id...}}` found in `data` arg. Logic based on clojure.spec/def `spec`
    Based on dynamic thread binding."
   [spec data]
-  (let [ids      (atom {:collection-ids    #{}
-                        :dashboard-ids     #{}
-                        :dataset-ids       #{}
-                        :visualisation-ids #{}})]
-    (binding [collection.s/*id?*    #(swap! ids update :collection-ids conj %)
-              dashboard.s/*id?*     #(swap! ids update :dashboard-ids conj %)
-              dataset.s/*id?*       #(swap! ids update :dataset-ids conj %)
-              visualisation.s/*id?* #(swap! ids update :visualisation-ids conj %)]
+  (let [ids    (atom {:collection-ids    #{}
+                      :dashboard-ids     #{}
+                      :dataset-ids       #{}
+                      :visualisation-ids #{}})
+        add-id (fn [k id]
+                 (when id
+                   (swap! ids update k conj id)))]
+    (binding [collection.s/*id?*    (partial add-id :collection-ids)
+              dashboard.s/*id?*     (partial add-id :dashboard-ids)
+              dataset.s/*id?*       (partial add-id :dataset-ids)
+              visualisation.s/*id?* (partial add-id :visualisation-ids)]
       (s/explain-str spec data)
       (deref ids))))


Extended generated path

Extended generated path

--- builder/src/builder/core.clj
+++ builder/src/builder/core.clj
@@ -28,7 +28,7 @@

 (defn write-output-file
   [gen-path {file :file contents :contents :as namespace}]
-  (let [path (str gen-path "/src/" file)]
+  (let [path (str gen-path "/src/goocle/" file)]
     (println "Generating contents of" path)
     (spit path contents)))

@@ -59,6 +59,7 @@
     (recreate-dir gen-path)
     (write-project-file gen-path version)
     (.mkdir (java.io.File. (str gen-path "/src")))
+    (.mkdir (java.io.File. (str gen-path "/src/goocle")))
     (doall (map #(write-output-file gen-path %) namespaces))))

 (defn perform


Remove unused code.

Remove unused code.

--- src/uxbox/main/state/clipboard.cljs
+++ src/uxbox/main/state/clipboard.cljs
@@ -1,16 +0,0 @@
-(ns uxbox.main.state.clipboard)
-
-(defonce ^:private +max-items+ 5)
-
-(defn conj-item
-  [state item]
-  (if-let [project (get-in state [:workspace :project])]
-    (let [queue (get-in state [:clipboard project] #queue [])
-          queue (conj queue item)]
-      (assoc-in state [:clipboard project]
-                (if (> (count queue) +max-items+)
-                  (pop queue)
-                  queue)))
-    (do
-      (js/console.warn "no active project for manage clipboard.")
-      state)))


Remove unused imports on selrect ns.

Remove unused imports on selrect ns.

--- src/uxbox/ui/workspace/selrect.cljs
+++ src/uxbox/ui/workspace/selrect.cljs
@@ -7,21 +7,15 @@

 (ns uxbox.ui.workspace.selrect
   "Components for indicate the user selection and selected shapes group."
-  (:require-macros [uxbox.util.syntax :refer [define-once]])
   (:require [sablono.core :as html :refer-macros [html]]
             [rum.core :as rum]
             [beicon.core :as rx]
-            [lentes.core :as l]
             [uxbox.rstore :as rs]
-            [uxbox.state :as st]
             [uxbox.shapes :as sh]
             [uxbox.data.workspace :as dw]
             [uxbox.ui.core :as uuc]
-            [uxbox.ui.workspace.base :as wb]
             [uxbox.ui.mixins :as mx]
-            [uxbox.util.geom.point :as gpt]
-            [uxbox.util.geom.matrix :as gmx]
-            [uxbox.util.dom :as dom]))
+            [uxbox.ui.workspace.base :as wb]))

 (defonce position (atom nil))