PDOK-1599: callback addded

PDOK-1599: callback addded

--- src/main/clojure/pdok/featured/api.clj
+++ src/main/clojure/pdok/featured/api.clj
@@ -13,6 +13,7 @@
             [pdok.featured
              [config :as config]
              [processor :as processor :refer [consume shutdown]]
+             [extracts :as extracts]
              [json-reader :as reader]]
             [ring.middleware.defaults :refer :all]
             [ring.middleware.json :refer :all]
@@ -76,7 +77,17 @@
   )

 (defn- extract* [callback-chan request]
-  (log/info "Processing extract: " request))
+  (log/info "Processing extract: " request)
+
+  (try (extracts/fill-extract (:dataset request) (:collection request) (:extractType request) (:extractVersion request))
+    (let [extract-stats (assoc request :status "ok")]
+       (when (:callback request)
+         (go (>! callback-chan [(:callback request) extract-stats]))))
+    (catch Exception e
+      (let [error-stats (assoc request :error (str e))]
+        (log/warn error-stats)
+        (when (:callback request)
+          (go (>! callback-chan [(:callback request) error-stats])))))))

 (defn- process-request [schema request-chan http-req]
   (let [request (:body http-req)


Add lazy-map so that mapping submit! to a seq of prints doesn't cause multiple jobs to print when seq is called on call, due to chunking

--- src/main/clojure/clj_print/core.clj
+++ src/main/clojure/clj_print/core.clj
@@ -80,10 +80,21 @@

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Util ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

+(defn lazy-map
+  "A lazier version of map so that calling (take 1 (map submit! multidoc))
+  on a lazy-seq made by multimethod make-job :docs doesn't cause
+  print events to be realized sooner than they should be due to
+  chunking."
+  {:since "0.0.1"}
+  [f coll]
+  (if (seq coll)
+    (lazy-seq (cons (f (first coll)) (lazy-map f (rest coll))))
+    nil))
+
 (defn- choose-source-key
   "Returns a keyword representative of the document source's
    type."
-  {:since "1.0"}
+  {:since "0.0.1"}
   [source]
   (cond (try (.. (io/file source) exists) (catch Throwable t)) :file
         (try (URL. source) (catch Throwable t)) :url
@@ -92,7 +103,7 @@
 (defn- choose-flavor
   "Attempts to guess the appropriate DocFlavor for the document.
    Returns nil if no suitable DocFlavor is found."
-  {:since "1.0"}
+  {:since "0.0.1"}
   [source]
   (condp = (choose-source-key source)
     :file (:autosense flavors/input-streams)
@@ -234,7 +245,7 @@
       (-> spec (dissoc :docs) (assoc :doc doc) make-job))))

 ;; Old method of encapsulating a 'MultiJobSpec', most
-;; values in a JobSpec will be Singleton/Enum instances
+;; values in a JobSpec will be singleton instances
 ;; anyways, so structural sharing may not be necessary,
 ;; though I'll throw this in here anyways:
 ;;


moar buttonz on the landingpage

moar buttonz on the landingpage

--- src/checkmate/views.clj
+++ src/checkmate/views.clj
@@ -31,7 +31,11 @@
     [:div.container
      [:h1 "Check-Mate" [:small "A tiny yet friendly checklist app."]]
      [:p "If you came here hoping for an app about chess, I'm sorry. If not go ahead and improve your day with some checklists. No matter what brought you here, you should read Atul Gawande's great book " [:a {:href "https://en.wikipedia.org/wiki/The_Checklist_Manifesto"} "'The Checklist Manifesto'."] " You definitely will feel the urge for some checklists afterwards. :-)"]
-     [:p [:a.btn.btn-primary {:href "/new"} "Create a new checklist"]]]]})
+     [:p [:div.btn-toolbar
+          [:div.btn-group
+           [:a.btn.btn-default {:href "/new"} "Create a new checklist"]
+           [:a.btn.btn-default {:href "/az"} "See all existing checklists"]]
+          [:div.btn-group [:a.btn.btn-primary {:href "http://clojurecup.com/app.html?app=checkmate"} "Vote for Check-Mate"]]]]]]})

 (defn bs-button [text & {:keys [tooltip onclick] :as options :or {tooltip "" onclick nil}}]
   [:button (merge {:onclick onclick :class "btn btn-default" :type "button" :title tooltip} options) text])


add-js-lib task not used anymore

add-js-lib task not used anymore

--- src/clj/saapas/boot.clj
+++ src/clj/saapas/boot.clj
@@ -16,19 +16,3 @@
         (go)
         (reset! done true))
       fileset)))
-
-(deftask add-js-lib
-  "Add non-boot ready js files to the fileset"
-  [p path PATH str "The path of file in classpath"
-   t target TARGET str "Target path"
-   x package bool "Don't include files in result"]
-  (let [tmp (temp-dir!)
-        state (atom nil)]
-    (with-pre-wrap
-      fileset
-      (when-not @state
-        (let [f (io/resource path)]
-          (if f
-            (pod/copy-url f (io/file tmp target))
-            (throw (str "File " path " not found!")))))
-      (-> fileset ((if package add-source add-resource) tmp) commit!))))


Fix performance regression related to #528 (#546)

--- src/clj_http/client.clj
+++ src/clj_http/client.clj
@@ -450,7 +450,7 @@
   (let [^BufferedReader br (io/reader (util/force-stream body))]
     (try
       (.mark br 1)
-      (let [^int first-char (try (.read br) (catch EOFException _ -1))]
+      (let [first-char (int (try (.read br) (catch EOFException _ -1)))]
         (case first-char
           -1 nil
           (do (.reset br)


clean code

clean code

Signed-off-by: Yen-Chin Lee <082d453d72dce940e12089a4ad48b97cfe1f3ec4@gmail.com>

--- src/cljs/chip8/cpu.cljs
+++ src/cljs/chip8/cpu.cljs
@@ -584,35 +584,3 @@
   (-> state
       (decoding))
   )
-
-
-(comment
-
-  (-> (make-cpu)
-      (load-rom [0xA2 0x1E
-                 0xC2 0x01
-                 0x32 0x01
-                 0xA2 0x1A
-                 0xD0 0x14])
-      (decoding)
-      :pc
-      )
-
-
-
-  (.log js/console "adadasda")
-
-  (-> (make-cpu)
-      (screen/set-pixel 31 31)
-      (screen/set-pixel 1 1)
-
-      (screen/set-pixel 31 0)
-      (screen/set-pixel 33 0)
-      (screen/set-pixel 63 0)
-      (screen/set-pixel 63 31)
-      (screen/render)
-      )
-
-  (:pc (-> (make-cpu)
-           (assoc :pc 2)))
-  )


* src/cljs/cljs/core.cljs: CLJS-125: IHash implementation for Atoms

--- src/cljs/cljs/core.cljs
+++ src/cljs/cljs/core.cljs
@@ -2986,7 +2986,10 @@
   (-add-watch [this key f]
     (set! (.-watches this) (assoc watches key f)))
   (-remove-watch [this key]
-    (set! (.-watches this) (dissoc watches key))))
+    (set! (.-watches this) (dissoc watches key)))
+
+  IHash
+  (-hash [this] (goog.getUid this)))

 (defn atom
   "Creates and returns an Atom with an initial value of x and zero or


missing main

missing main

--- src/cljs/moon/core.cljs
+++ src/cljs/moon/core.cljs
@@ -88,7 +88,6 @@
     (aset (aget el "style") "color" "red")
     (dorun (map set-html (dissoc (assoc excercise :total total) :id)))))

-
 (defn create-td [parent workout key]
   (let [td (. js/document createElement "td")]
     (. parent appendChild td)
@@ -139,6 +138,7 @@
     (progressor clock-channel state-channel)
     (onto-chan state-channel workout)))

-(let [workout (map-indexed (fn [i coll] (assoc coll :id i)) workout)]
-  (to-html workout)
-  (run (mapcat expand workout)))
+(defn main []
+  (let [workout (map-indexed (fn [i coll] (assoc coll :id i)) workout)]
+    (to-html workout)
+    (run (mapcat expand workout))))


removing locations page stub from core

removing locations page stub from core

--- src/cljs/ohds/core.cljs
+++ src/cljs/ohds/core.cljs
@@ -31,9 +31,6 @@
           200 (swap! app-state assoc :page :location)))))

-(defn location-page []
-  [:div "locations"])
-
 (defn root-component []
   [:div {:class "container"}
    [:div {:class "row"} [c/top]]


Removing nav bar from core

Removing nav bar from core

--- src/cljs/ohds/core.cljs
+++ src/cljs/ohds/core.cljs
@@ -36,14 +36,6 @@
            :id id
            :class "form-control"
            :on-change #(reset! value (-> % .-target .-value))}])
-
-(defn nav-bar []
-  [:div {:id "navbar" :class "navbar-collapse collapse" :aria-expanded "false"}
-   [:ul {:class "nav navbar-nav"}
-    [:li
-     [:a {:href "#"} "Home"]]
-    [:li
-     [:a {:href "#"} "Logout"]]]])

 (defn top []
   [:nav {:class "navbar navbar-inverse navbar-fixed-top"}


RR: add main menu component

RR: add main menu component

--- src/cljs/ona/login.cljs
+++ src/cljs/ona/login.cljs
@@ -3,9 +3,58 @@
                   [dommy.macros :refer [sel sel1]])
  (:require [cljs.core.async :refer [<! chan mult tap put!]]
            [om.core :as om :include-macros true]
+           [ona.utils.tags :refer [image]]
            [sablono.core :refer-macros [html]]))

 (def app-state (atom {}))
+
+
+(defn main-menu
+  "Component that renders main-menu"
+  [cursor owner]
+  (om/component
+    (html [:div {:id "main-menu" :class "cfix"}
+           [:div {:class "vw-menu pure-menu-horizontal container cfix"}
+           [:a {:id "logo-link" :href "#" :class "pure-menu-heading left"}
+            [:span
+             [:img {:id "ona-logo" :src (image "onadata-logo.png") :alt "ONA"}]]]
+           [:ul {:class "left" :id "mian-nav-links"}
+            [:li
+             [:a {:id "home-link" :href "#"}
+              [:span {:data-i18n-key "main-navigation/home-link-text"} "Home"]]]
+            [:li
+             [:div {:class "dropdown projects-drop drop-hover"}
+              [:a {:href "#"}
+               [:span {:data-i18n-key "main-navigation/organizations-dropdown-header"} "Organizations"
+                [:i {:class "fa fa-angle-down"}]]]
+              [:ul {:id "orgs-dropdown" :class "submenu"}
+               [:li [:div {:class "drop-search orgs-search"}
+                     [:i {:class"fa fa-search"}]
+                     [:input {:type "text" :name "" :class "" :id "" :placeholder "Find an organization"}]]]
+               [:li [:a {:href "#"} [:span {:class "label label-initial pink"}"A"] [:span {:class "org-name"} "Org 1"]]]
+               [:li [:a {:href "#"} [:span {:class "label label-initial pink"}"B"] [:span {:class "org-name"} "Org 2"]]]]]]
+            [:li {:id "projects"}
+             [:div {:class "dropdown projects-drop drop-hover"}
+              [:a {:href "#"}
+               [:span {:data-i18n-key "main-navigation/main-navigation/projects-dropdown-header"} "Projects"
+                [:i {:class "fa fa-angle-down"}]]]
+              [:ul {:id "project-dropdown" :class "submenu"}
+               [:li [:div {:class "drop-search orgs-search"}
+                     [:i {:class"fa fa-search"}]
+                     [:input {:type "text" :name "" :class "" :id "" :placeholder "Find a project"}]]]
+               [:li [:a {:href "#"} [:span {:class "label label-initial pink"}"A"] [:span {:class "proj-name"} "Project 1"]]]
+               [:li [:a {:href "#"} [:span {:class "label label-initial pink"}"B"] [:span {:class "proj-name"} "Project 2"]]]]]]
+            [:li [:a {:id "whatsnew-link" :data-i18n-key "main-navigation/new-features-link-text" :href "#"} "What's New"]]]
+           [:ul {:id "user" :class "right"}
+            [:li {:class "header-user"} [:span {:class "bell-wrap"} [:i {:class "fa fa-bell-o"}]]
+             [:div {:class "dropdown drop-hover"}
+              [:a {:id "user-avatar" :href "#"} [:span {:class "label label-initial pink"} "G"]
+               [:i {:class "fa fa-angle-down"}]]
+              [:ul {:class "submenu" :id "user-dropdown"}
+               [:li [:a {:href "#"} "username"]]
+               [:li [:a {:href "#"} "Settings"]]
+               [:li [:a {:href "#"} "Help"]]
+               [:li [:a {:href "#"} "Logout"]]]]]]]])))

 (defn login
   "Component that renders the login page and components."
@@ -14,9 +63,10 @@
     om/IRender
     (render [_]
       (html [:div
+             (om/build main-menu cursor)
              [:div {:class "content container"}
               [:div {:class "standard-account-form"}
-              [:h2 "Sign in"]
+               [:h2 "Sign in"]
                [:form {:action "/login"
                        :method "post"
                        :class "pure-form pure-form-stacked ie-form"}


Now clojure connection type now implements java.io.Closeable.

--- src/clojure/nanomsg.clj
+++ src/clojure/nanomsg.clj
@@ -70,6 +70,10 @@
   (recv! [_ blocking]
     (.recvString s blocking))
   (close! [_]
+    (.close s))
+
+  java.io.Closeable
+  (close [_]
     (.close s)))

 (defrecord AsyncConnection [s px]


Adapt clojure implementation to java library changes.

--- src/clojure/nanomsg.clj
+++ src/clojure/nanomsg.clj
@@ -44,7 +44,6 @@
   (unsubscribe! [_ pattern] "Unsubscribe current socket from specified topic.")
   (send! [_ data] [_ data blocking] "Send string using a socket.")
   (recv! [_] [_ blocking] "Receive string using a socket.")
-  (send-bytes! [_ data] [_ data blocking] "Send bytes using socket.")
   (recv-bytes! [_] [_ blocking] "Receive bytes using socket.")
   (close! [_] "Close a socket."))

@@ -58,20 +57,16 @@
     (.subscribe s pattern))
   (unsubscribe! [_ pattern]
     (.unsubscribe s pattern))
-  (send-bytes! [_ data]
-    (.sendBytes s data))
   (recv-bytes! [_]
     (.recvBytes s))
-  (send-bytes! [_ data blocking]
-    (.sendBytes s data blocking))
   (recv-bytes! [_ blocking]
     (.recvBytes s blocking))
-  (send! [_ data]
-    (.sendString s data))
   (recv! [_]
     (.recvString s))
+  (send! [_ data]
+    (.send s data))
   (send! [_ data blocking]
-    (.sendString s data blocking))
+    (.send s data blocking))
   (recv! [_ blocking]
     (.recvString s blocking))
   (close! [_]
@@ -87,11 +82,6 @@
     (.subscribe s pattern))
   (unsubscribe! [_ pattern]
     (.unsubscribe s pattern))
-  (send-bytes! [_ data]
-    (let [ch (chan)
-          cb (make-iasynccallback ch)]
-      (.sendBytes px cb)
-      ch))
   (recv-bytes! [_]
     (let [ch (chan)
           cb (make-iasynccallback ch)]
@@ -100,7 +90,7 @@
   (send! [_ data]
     (let [ch (chan)
           cb (make-iasynccallback ch)]
-      (.sendString px data cb)
+      (.send px data cb)
       ch))
   (recv! [_]
     (let [ch (chan)
@@ -112,8 +102,6 @@
   (send! [_ data blocking]
     (throw (UnsupportedOperationException. "Unsuporded arity for async connection.")))
   (recv! [_ blocking]
-    (throw (UnsupportedOperationException. "Unsuporded arity for async connection.")))
-  (send-bytes! [_ data blocking]
     (throw (UnsupportedOperationException. "Unsuporded arity for async connection.")))
   (recv-bytes! [_ blocking]
     (throw (UnsupportedOperationException. "Unsuporded arity for async connection."))))


Add a max-pending to bookkeeper task

Add a max-pending to bookkeeper task

--- src/onyx_peers/tasks/bookkeeper.clj
+++ src/onyx_peers/tasks/bookkeeper.clj
@@ -19,6 +19,7 @@
                          :onyx/medium :bookkeeper
                          :onyx/restart-pred-fn :onyx-peers.lifecycles.restart-lifecycle/restart?
                          ;; TODO: Vary pending timeout in different Jepsen tests
+                         :onyx/max-pending 5000
                          :onyx/pending-timeout 10000
                          ;; TODO: Vary read max chunk in different tests
                          ;:bookkeeper/read-max-chunk-size 10


Add info to description.

Add info to description.

--- src/org/spootnik/cyanite/rollup.clj
+++ src/org/spootnik/cyanite/rollup.clj
@@ -24,7 +24,7 @@
         (some within-fn (sort-by :rollup rollups))))))

 (defn resolution-rollup-finder
-  "Find most suitable rollup for given resolution"
+  "Find most suitable rollup for given resolution (minimal number of data points)"
   [{:keys [rollups resolution] :or {resolution 800}}]
   (info "creating resolution rollup finder")
   (reify


Added lein-exec

Added lein-exec

--- lein/profiles.clj
+++ lein/profiles.clj
@@ -4,5 +4,6 @@
     [clj-ns-browser "1.3.0"]
     [marmaduke/commons-math-3 "3"]
     [org.clojure/data.json "0.2.0"]
+    [lein-exec "0.3.0"]
 ]}}


lein: bump lein-ancient

lein: bump lein-ancient

--- lein_profiles.clj
+++ lein_profiles.clj
@@ -1,6 +1,6 @@
 {:user {:plugins [
                   [lein-ring "0.9.2"]
-                  [lein-ancient "0.6.3"]
+                  [lein-ancient "0.6.5"]
                   [jonase/eastwood "0.2.1"]
                   [cider/cider-nrepl "0.8.2"]
                   ]}}


utf-8 fixes

utf-8 fixes

--- src/neversleep_clojure_client/core.clj
+++ src/neversleep_clojure_client/core.clj
@@ -39,11 +39,12 @@
         :else (throw (Exception. (str "Callback of type " (type callback) " not supported")))))

 (defn start-tcp-responce-async-loop [client]
-  (go (loop []
-        (let [callback (<! @tcp-responce-ch)
+  (thread (loop []
+        (let [callback (<!! @tcp-responce-ch)
               stream-in-ch (:in @client)]
           (if-not (nil? stream-in-ch)
-            (let [responce (<! stream-in-ch)
+            (let [responce (<!! stream-in-ch)
+                  _ (println "got responce" responce)
                   responce (clojure.walk/keywordize-keys (cheshire/decode (String. (byte-array responce))))
                   request-uuid (keyword (get responce :request-uuid))
                   callback (get @pending-requests request-uuid)]
@@ -56,18 +57,20 @@
 (def tcp-request-ch (atom (chan 1000)))

 (defn start-tcp-request-async-loop [client]
-  (go (loop []
-        (let [{:keys [callback b-a request-uuid]} (<! @tcp-request-ch)
+  (thread (loop []
+        (let [{:keys [callback b-a request-uuid]} (<!! @tcp-request-ch)
               request-uuid (keyword request-uuid)
               stream-out-ch (:out @client)
               send-result (if stream-out-ch
-                            (>! stream-out-ch b-a)
+                            (>!! stream-out-ch b-a)
                             false)]
           ;add to pending-requests
           (swap! pending-requests assoc request-uuid callback)
           (if send-result
             ;schedule a "take" from the socket
-            (>! @tcp-responce-ch callback)
+            (do
+              (println "scheduling a take...")
+              (>!! @tcp-responce-ch callback))
             (dispatch-to-callback callback {:error ":out socket channel closed, no data sent"}))
           (recur)))))

@@ -75,6 +78,7 @@
 (defn init
   "Initiates a tcp socket connection to the server"
   [host port]
+  (reset! pending-requests {})
   (reset! tcp-request-ch (chan 1000))
   (reset! tcp-responce-ch (chan 1000))
   (reset! client (connect-stream-to-core-async-channels
@@ -138,8 +142,8 @@

 (defn- io-get-entity-as-of-base [^String entity-id timestamp]
   (let [{:keys [header-bytes request-uuid]} (header-bytes -127)
-        entity-id-length (byte-array [(count entity-id)])
-        entity-id-bytes (.getBytes entity-id)
+        entity-id-bytes (.getBytes entity-id)
+        entity-id-length (byte-array [(count entity-id-bytes)])
         timestamp (.getBytes (str timestamp))]
     {:b-a (byte-array (concat header-bytes entity-id-length entity-id-bytes timestamp))
      :request-uuid request-uuid}))
@@ -168,6 +172,9 @@
    (let [{:keys [b-a request-uuid]} (io-assoc-base entity-id key value)]
      (>!! @tcp-request-ch {:b-a b-a :request-uuid request-uuid :callback callback}))))

+(defn io-hash-map [entity-id a-map]
+  (doseq [[k v] a-map]
+    (io-assoc entity-id k v (fn [x] (println "confirmed write " k v x)))))

 (defn io-dissoc
   ([^String entity-id key]


Reformatted core_test.clj by zprint

Reformatted core_test.clj by zprint

--- test/zg/core_test.clj
+++ test/zg/core_test.clj
@@ -21,130 +21,130 @@
 ;

 (defn callable?
-    "Test if given function-name is bound to the real function."
-    [function-name]
-    (clojure.test/function? function-name))
+  "Test if given function-name is bound to the real function."
+  [function-name]
+  (clojure.test/function? function-name))

 ;
 ; Tests for various functions
 ;

 (deftest test-start-server-existence
-    "Check that the zg.core/start-server definition exists."
-    (testing "if the zg.core/start-server definition exists."
-        (is (callable? 'zg.core/start-server))))
+  "Check that the zg.core/start-server definition exists."
+  (testing "if the zg.core/start-server definition exists."
+           (is (callable? 'zg.core/start-server))))

 (deftest test-get-and-check-port-existence
-    "Check that the zg.core/get-and-check-port definition exists."
-    (testing "if the zg.core/get-and-check-port definition exists."
-        (is (callable? 'zg.core/get-and-check-port))))
+  "Check that the zg.core/get-and-check-port definition exists."
+  (testing "if the zg.core/get-and-check-port definition exists."
+           (is (callable? 'zg.core/get-and-check-port))))

 (deftest test-get-port-existence
-    "Check that the zg.core/get-port definition exists."
-    (testing "if the zg.core/get-port definition exists."
-        (is (callable? 'zg.core/get-port))))
+  "Check that the zg.core/get-port definition exists."
+  (testing "if the zg.core/get-port definition exists."
+           (is (callable? 'zg.core/get-port))))

 (deftest test--main-existence
-    "Check that the zg.core/-main definition exists."
-    (testing "if the zg.core/-main definition exists."
-        (is (callable? 'zg.core/-main))))
+  "Check that the zg.core/-main definition exists."
+  (testing "if the zg.core/-main definition exists."
+           (is (callable? 'zg.core/-main))))

 ;
 ; Tests for function behaviours
 ;

 (deftest test-get-port
-    "Check the function zg.core/get-port."
-    (testing "the function zg.core/get-port."
-        (is (= (get-port "1")     "1"))
-        (is (= (get-port "2")     "2"))
-        (is (= (get-port "3000")  "3000"))
-        (is (= (get-port "65534") "65534"))
-        (is (= (get-port "65535") "65535"))))
+  "Check the function zg.core/get-port."
+  (testing "the function zg.core/get-port."
+           (is (= (get-port "1")     "1"))
+           (is (= (get-port "2")     "2"))
+           (is (= (get-port "3000")  "3000"))
+           (is (= (get-port "65534") "65534"))
+           (is (= (get-port "65535") "65535"))))

 (deftest test-get-port-special-cases
-    "Check the function zg.core/get-port."
-    (testing "the function zg.core/get-port."
-        (is (= (get-port nil)     "3000"))
-        (is (= (get-port "")      "3000"))
-        (is (= (get-port 0)       "3000"))
-        (is (= (get-port 1)       "3000"))
-        (is (= (get-port 65535)   "3000"))
-        (is (= (get-port 65536)   "3000"))))
+  "Check the function zg.core/get-port."
+  (testing "the function zg.core/get-port."
+           (is (= (get-port nil)     "3000"))
+           (is (= (get-port "")      "3000"))
+           (is (= (get-port 0)       "3000"))
+           (is (= (get-port 1)       "3000"))
+           (is (= (get-port 65535)   "3000"))
+           (is (= (get-port 65536)   "3000"))))

 (deftest test-get-port-negative
-    "Check the function zg.core/get-port."
-    (testing "the function zg.core/get-port."
-        (is (thrown? AssertionError (get-port "0")))
-        (is (thrown? AssertionError (get-port "-1")))
-        (is (thrown? AssertionError (get-port "-2")))
-        (is (thrown? AssertionError (get-port "65536")))
-        (is (thrown? AssertionError (get-port "65537")))
-        (is (thrown? AssertionError (get-port "1000000")))))
+  "Check the function zg.core/get-port."
+  (testing "the function zg.core/get-port."
+           (is (thrown? AssertionError (get-port "0")))
+           (is (thrown? AssertionError (get-port "-1")))
+           (is (thrown? AssertionError (get-port "-2")))
+           (is (thrown? AssertionError (get-port "65536")))
+           (is (thrown? AssertionError (get-port "65537")))
+           (is (thrown? AssertionError (get-port "1000000")))))

 (deftest test-get-and-check-port
-    "Check the function zg.core/get-and-check-port."
-    (testing "the function zg.core/get-and-check-port."
-        (is (= (get-and-check-port "1")     "1"))
-        (is (= (get-and-check-port "2")     "2"))
-        (is (= (get-and-check-port "65534") "65534"))
-        (is (= (get-and-check-port "65535") "65535"))))
+  "Check the function zg.core/get-and-check-port."
+  (testing "the function zg.core/get-and-check-port."
+           (is (= (get-and-check-port "1")     "1"))
+           (is (= (get-and-check-port "2")     "2"))
+           (is (= (get-and-check-port "65534") "65534"))
+           (is (= (get-and-check-port "65535") "65535"))))

 (deftest test-get-and-check-port-negative
-    "Check the function zg.core/get-and-check-port."
-    (testing "the function zg.core/get-and-check-port."
-        (is (thrown? AssertionError (get-and-check-port "-1")))
-        (is (thrown? AssertionError (get-and-check-port "0")))
-        (is (thrown? AssertionError (get-and-check-port "65536")))
-        (is (thrown? AssertionError (get-and-check-port "65537")))
-        (is (thrown? AssertionError (get-and-check-port "1000000")))))
+  "Check the function zg.core/get-and-check-port."
+  (testing "the function zg.core/get-and-check-port."
+           (is (thrown? AssertionError (get-and-check-port "-1")))
+           (is (thrown? AssertionError (get-and-check-port "0")))
+           (is (thrown? AssertionError (get-and-check-port "65536")))
+           (is (thrown? AssertionError (get-and-check-port "65537")))
+           (is (thrown? AssertionError (get-and-check-port "1000000")))))

 (deftest test-start-server-positive-1
-    (testing "zg.core/start-server"
-        ; use mock instead of jetty/run-jetty
-        (with-redefs [jetty/run-jetty (fn [app port] port)]
-            (is (= {:port 1}     (start-server "1")))
-            (is (= {:port 2}     (start-server "2")))
-            (is (= {:port 1000}  (start-server "1000")))
-            (is (= {:port 65534} (start-server "65534")))
-            (is (= {:port 65535} (start-server "65535"))))))
+  (testing "zg.core/start-server"
+           ; use mock instead of jetty/run-jetty
+           (with-redefs [jetty/run-jetty (fn [app port] port)]
+             (is (= {:port 1}     (start-server "1")))
+             (is (= {:port 2}     (start-server "2")))
+             (is (= {:port 1000}  (start-server "1000")))
+             (is (= {:port 65534} (start-server "65534")))
+             (is (= {:port 65535} (start-server "65535"))))))

 (deftest test-start-server-positive-2
-    (testing "zg.core/start-server"
-        ; use mock instead of jetty/run-jetty
-        (with-redefs [jetty/run-jetty (fn [app port] app)]
-            (is (= app (start-server "1")))
-            (is (= app (start-server "2")))
-            (is (= app (start-server "1000")))
-            (is (= app (start-server "65534")))
-            (is (= app (start-server "65535"))))))
+  (testing "zg.core/start-server"
+           ; use mock instead of jetty/run-jetty
+           (with-redefs [jetty/run-jetty (fn [app port] app)]
+             (is (= app (start-server "1")))
+             (is (= app (start-server "2")))
+             (is (= app (start-server "1000")))
+             (is (= app (start-server "65534")))
+             (is (= app (start-server "65535"))))))

 (deftest test-start-server-wrong-port-number
-    (testing "zg.core/start-server"
-        ; use mock instead of jetty/run-jetty
-        (with-redefs [jetty/run-jetty (fn [app port] port)]
-            (is (= {:port -1}      (start-server "-1")))
-            (is (= {:port 0}       (start-server "0")))
-            (is (= {:port 65536}   (start-server "65536")))
-            (is (= {:port 65537}   (start-server "65537")))
-            (is (= {:port 1000000} (start-server "1000000"))))))
+  (testing "zg.core/start-server"
+           ; use mock instead of jetty/run-jetty
+           (with-redefs [jetty/run-jetty (fn [app port] port)]
+             (is (= {:port -1}      (start-server "-1")))
+             (is (= {:port 0}       (start-server "0")))
+             (is (= {:port 65536}   (start-server "65536")))
+             (is (= {:port 65537}   (start-server "65537")))
+             (is (= {:port 1000000} (start-server "1000000"))))))

 (deftest test-main-1
-    "Check the function zg.core/main."
-    (testing "the function zg.core/main."
-        ; use mock instead of jetty/run-jetty
-        (with-redefs [jetty/run-jetty (fn [app port] port)]
-            (is (= {:port 3000} (-main))))))
+  "Check the function zg.core/main."
+  (testing "the function zg.core/main."
+           ; use mock instead of jetty/run-jetty
+           (with-redefs [jetty/run-jetty (fn [app port] port)]
+             (is (= {:port 3000} (-main))))))

 (deftest test-main-2
-    "Check the function zg.core/main."
-    (testing "the function zg.core/main."
-        ; use mock instead of jetty/run-jetty
-        (with-redefs [jetty/run-jetty (fn [app port] port)]
-            (are [x y] (= x y)
-                {:port 2000} (-main "-p"     "2000")
-                {:port 2000} (-main "--port" "2000")))))
+  "Check the function zg.core/main."
+  (testing "the function zg.core/main."
+           ; use mock instead of jetty/run-jetty
+           (with-redefs [jetty/run-jetty (fn [app port] port)]
+             (are [x y] (= x y)
+                  {:port 2000} (-main "-p"     "2000")
+                  {:port 2000} (-main "--port" "2000")))))


Removing obsolete empty line

Removing obsolete empty line

--- src/vignette/util/query_options.clj
+++ src/vignette/util/query_options.clj
@@ -47,7 +47,6 @@
               running))
           {} (:query-params request)))

-
 (defn query-opts
   [data]
   (if (empty? (:options data))


update move to track movement stats

update move to track movement stats

--- src/wombats/game/decisions/move.clj
+++ src/wombats/game/decisions/move.clj
@@ -28,7 +28,11 @@

 (defn- apply-poison-effects
   [decision-maker-contents]
-  (update decision-maker-contents :hp #(- % (:poison-hp-damage game-parameters))))
+  (let [new-hp (- (:hp decision-maker-contents) (:poison-hp-damage game-parameters))]
+    ;; If the decision maker does not have enough health remaining, remove from arena
+    (if (pos? new-hp)
+      (assoc decision-maker-contents :hp new-hp)
+      (au/create-new-contents :open))))

 (defn update-decision-maker-with
   [decision-maker-contents
@@ -64,7 +68,9 @@
   (let [updated-decision-maker-contents (update-decision-maker-with decision-maker-contents
                                                                     desired-space-contents
                                                                     desired-space-metadata)
-        is-player? (gu/is-player? decision-maker-contents)]
+        is-player (gu/is-player? decision-maker-contents)
+        wombat-died (and is-player
+                         (not (gu/is-player? updated-decision-maker-contents)))]
     (-> game-state
         (update-in [:game/frame :frame/arena]
                    #(au/update-cell-contents %
@@ -75,8 +81,16 @@
                                              decision-maker-coords
                                              (au/create-new-contents :open)))
         (cond->
-            is-player? (update-player-stats decision-maker-contents
-                                            desired-space-contents)))))
+            is-player (update-player-stats decision-maker-contents
+                                           desired-space-contents)
+            ;; If a wombat died moving (without colliding) it died from poison
+            wombat-died (update-in [:game/players
+                                    (:uuid decision-maker-contents)
+                                    :player/stats]
+                                   (fn [stats]
+                                     (-> stats
+                                         (update :stats/deaths inc)
+                                         (update :stats/deaths-by-poison inc))))))))

 (defn- apply-collision-damage
   [contents]
@@ -91,17 +105,68 @@
    {collision-type :type}
    {self-type :type
     self-uuid :uuid}]
-
-  (if (= self-type :wombat)
-    (update-in game-state [:game/players self-uuid :player-stats]
-               (fn [stats]
-                 (case collision-type
-                   :wombat (update :stats/wombat-collisions inc)
-                   :zakano (update :stats/zakano-collisions inc)
-                   :steel-barrier (update :stats/steel-barrier-collisions inc)
-                   :wood-barrier (update :stats/wood-barrier-collisions inc)
-                   stats)))
-    game-state))
+  (update-in game-state [:game/players self-uuid :player/stats]
+             (fn [stats]
+               (case collision-type
+                 :wombat (update stats :stats/wombat-collisions inc)
+                 :zakano (update stats :stats/zakano-collisions inc)
+                 :steel-barrier (update stats :stats/steel-barrier-collisions inc)
+                 :wood-barrier (update stats :stats/wood-barrier-collisions inc)
+                 stats))))
+
+(defn- update-collision-death-stats
+  [game-state
+   {victim-type :type
+    victim-uuid :uuid}
+   {collision-type :type}]
+  (update-in game-state [:game/players victim-uuid :player/stats]
+             (fn [stats]
+               (-> stats
+                   (update :stats/deaths inc)
+                   (update (case collision-type
+                             :wombat :stats/deaths-by-wombat-collision
+                             :zakano :stats/deaths-by-zakano-collision
+                             :steel-barrier :stats/deaths-by-steel-barrier-collision
+                             :wood-barrier :stats/deaths-by-wood-barrier-collision)
+                           inc)))))
+
+(defn- update-move-stats
+  [game-state
+   desired-space-contents
+   updated-desired-space
+   decision-maker-contents
+   updated-decision-maker]
+
+  (let [decision-maker-type (:type decision-maker-contents)
+        updated-decision-maker-type (:type updated-decision-maker)
+        desired-space-type (:type desired-space-contents)
+        updated-desired-space-type (:type updated-desired-space)
+        decision-maker-is-wombat (= :wombat decision-maker-type)
+        desired-space-is-wombat (= :wombat desired-space-type)
+        decision-maker-wombat-died (and decision-maker-is-wombat
+                                        (not= updated-decision-maker-type :wombat))
+        victim-wombat-died (and desired-space-is-wombat
+                                (not= updated-desired-space-type :wombat))]
+    (cond-> game-state
+      ;; Update the decision makers collision stats
+      decision-maker-is-wombat
+      (update-collision-stats desired-space-contents
+                              decision-maker-contents)
+
+      ;; Update the reverse if wombat
+      desired-space-is-wombat
+      (update-collision-stats decision-maker-contents
+                              desired-space-contents)
+
+      ;; Update the decision makers death stats
+      decision-maker-wombat-died
+      (update-collision-death-stats decision-maker-contents
+                                    desired-space-contents)
+
+      ;; Update the victims death stats
+      victim-wombat-died
+      (update-collision-death-stats desired-space-contents
+                                    decision-maker-contents))))

 (defn- resolve-collision
   [game-state
@@ -113,26 +178,29 @@

   (let [updated-desired-space (apply-collision-damage desired-space-contents)
         updated-decision-maker (apply-collision-damage decision-maker-contents)
-        take-space? (can-safely-occupy-space? updated-desired-space)]
-    (cond-> (update-collision-stats game-state
-                                    desired-space-contents
-                                    decision-maker-contents)
-      take-space?
+        take-space (can-safely-occupy-space? updated-desired-space)]
+
+    (cond-> (update-move-stats game-state
+                               desired-space-contents
+                               updated-desired-space
+                               decision-maker-contents
+                               updated-decision-maker)
+      take-space
       (update-in [:game/frame :frame/arena]
                  #(au/update-cell-contents %
                                            desired-space-coords
                                            updated-decision-maker))
-      take-space?
+      take-space
       (update-in [:game/frame :frame/arena]
                  #(au/update-cell-contents %
                                            decision-maker-coords
                                            (au/create-new-contents :open)))
-      (not take-space?)
+      (not take-space)
       (update-in [:game/frame :frame/arena]
                  #(au/update-cell-contents %
                                            desired-space-coords
                                            updated-desired-space))
-      (not take-space?)
+      (not take-space)
       (update-in [:game/frame :frame/arena]
                  #(au/update-cell-contents %
                                            decision-maker-coords


fixed swap

fixed swap

--- src/grafter/tabular.clj
+++ src/grafter/tabular.clj
@@ -286,27 +286,26 @@

 (defn swap
-"Takes two column names and swaps each column"
+  "Takes two column names and swaps each column"

   ([dataset first-col second-col]
-  (let [swapper (fn [v i j]
-                  (-> v
-                      (assoc i (v j))
-                      (assoc j (v i))))
-        data (:rows dataset)
-        header (column-names dataset)]
-    (-> header
-        (swapper (col-position header first-col)
-                 (col-position header second-col))
-        (make-dataset data))))
+   (let [data (:rows dataset)
+         header (column-names dataset)
+         swapper (fn [v i j]
+                   (-> v
+                       (assoc i (v j))
+                       (assoc j (v i))))]
+     (-> header
+         (swapper (col-position header first-col)
+                  (col-position header second-col))
+         (make-dataset data))))
   ([dataset first-col second-col & more]
    (if (seq more)
      (reduce (fn [ds [f s]]
-               (apply swap f s more)) (swap dataset first-col second-col)
-             more)
-     (swap dataset first-col second-col))
-   )
-  )
+               (swap ds f s))
+             (swap dataset first-col second-col)
+             (partition 2 more))
+     (swap dataset first-col second-col))))

 (comment


grep works for fn, strings and regex but only if cols is given as an argument

--- src/grafter/tabular.clj
+++ src/grafter/tabular.clj
@@ -240,7 +240,9 @@

   [dataset f cols]
   (let [data (:rows dataset)
-        col-set (into #{} cols)]
+        col-set (into #{} (if (nil? cols)
+                            (column-names dataset)
+                            cols))]

      (make-dataset cols
                    (->> data
@@ -248,11 +250,11 @@
                                  (some f
                                        (cells-from-columns col-set row))))))))

-(defmethod grep java.lang.String [csv s & cols]
-  (apply grep csv #(.contains % s) cols))
-
-(defmethod grep java.util.regex.Pattern [csv p & cols]
-  (apply grep csv #(re-find p %) cols))
+(defmethod grep java.lang.String [dataset s cols]
+  (grep dataset #(.contains % s) cols))
+
+(defmethod grep java.util.regex.Pattern [dataset p cols]
+  (grep dataset #(re-find p %) cols))

 (defn- remove-indices [col & idxs]
   "Removes the values at the supplied indexes from the given vector."


Tidy imports

Tidy imports

--- src/inkspot/palette.clj
+++ src/inkspot/palette.clj
@@ -1,16 +1,11 @@
 (ns inkspot.palette
+  (:require [inkspot.color :as color])
   ^:clj
-  (:require
-    [inkspot.color :as color]
-    [inkspot.color-chart :as cc])
-  (:import
-    [java.io StringWriter]
-    [org.apache.batik.dom GenericDOMImplementation]
-    [org.apache.batik.svggen SVGGraphics2D]
-    [java.awt.image BufferedImage]
-    [java.awt.geom AffineTransform GeneralPath Ellipse2D$Double]
-    [java.awt Color Paint BasicStroke Rectangle Graphics2D
-              RenderingHints BasicStroke GraphicsEnvironment]))
+  (:import (java.awt Color Graphics2D GraphicsEnvironment RenderingHints)
+           (java.awt.image BufferedImage)
+           (java.io StringWriter)
+           (org.apache.batik.dom GenericDOMImplementation)
+           (org.apache.batik.svggen SVGGraphics2D)))

 (defprotocol IGraphics2DTarget
   (create-context [this width height])
@@ -57,7 +52,8 @@
                     (iterate inc 0)
                     (map pos)
                     (map cons color-swatch))
-        g2d       (create-context g2d-target width height)]
+        target    (g2d-target)
+        g2d       (create-context target width height)]

     (doto g2d
       (.setBackground Color/WHITE)
@@ -68,7 +64,7 @@
       (doseq [[c x y] generator]
         (draw-cell g2d x y w h (color/coerce c))))

-    (close g2d-target)))
+    (close target)))

 ^:clj
 (defn bitmap []
@@ -94,3 +90,4 @@
         (with-open [out (StringWriter.)]
           (.stream svg-generator out true)
           (.toString out))))))
+


specify an api uri with $API_URI when building

--- pedestal-app/app/src/semtag_web/tasks.clj
+++ pedestal-app/app/src/semtag_web/tasks.clj
@@ -19,24 +19,33 @@
   ;; load before any other js
   (string/replace-first html #"(<script id=)" (str capture-logs-js "$1")))

-(defn- modify-js
-  [app-file transform-fn]
-  (-> app-file
+; ensure relative js paths - hack until I can find out what set of compiler options works
+(defn- ensure-relative-paths [html]
+  (string/replace html #"/generated-js" "generated-js"))
+
+(defn- modify-file
+  [file transform-fn]
+  (-> file
       slurp
       transform-fn
-      ; ensure relative js paths - hack until I can find out what set of compiler options works
-      (string/replace #"/generated-js" "generated-js")
       (as-> new-body
-        (spit app-file new-body))))
+        (spit file new-body))))

 (defn build-app
-  "Builds an aspect, :test by default."
+  "Builds an aspect, :test if no argument is given. It also prepares it to be standalone html,
+  adds debugging for the test aspect and updates services/base-uri if $API_URI is set."
   [& args]
   (let [aspect (keyword (or (first args) "test"))
-        out-file (-> dev/config vals first :aspects aspect :uri)
-        transform-js-fn (if (= aspect :test) add-log-capturing identity)]
-    (when-not out-file (throw (ex-info "This aspect does not exist!" {:aspect aspect})))
+        {html-file :uri js-file :out-file} (-> dev/config vals first :aspects aspect)
+        transform-js-fn (if (= aspect :test) (comp ensure-relative-paths add-log-capturing) ensure-relative-paths)]
+    (when-not html-file (throw (ex-info "This aspect does not exist!" {:aspect aspect})))

     (println (format "Building %s app..." aspect))
     (time (build/build! (-> dev/config vals first) aspect))
-    (modify-js (str "out/public" out-file) transform-js-fn)))
+
+    (println "Writing" (str "out/public" html-file))
+    (modify-file (str "out/public" html-file) transform-js-fn)
+
+    (when-let [uri (System/getenv "API_URI")]
+      (println "Writing" (str "out/public/generated-js/" js-file))
+      (modify-file (str "out/public/generated-js/" js-file) #(string/replace-first % "http://localhost:3000/api" uri)))))


fixed issue with event triggering

fixed issue with event triggering

--- src/node/game/core.cljs
+++ src/node/game/core.cljs
@@ -99,7 +99,8 @@

 (defn trigger-event [state side event target]
   (doseq [e (get-in @state [:events event])]
-    (resolve-ability state side (:ability e) (get-card state (:card e)) [target])))
+    (let [card (get-card state (:card e))]
+      (resolve-ability state (:side card) (:ability e) card [target]))))

 (defn card-init [state side card]
   (let [cdef (card-def card)


Fix comment.

Fix comment.

--- src/oc/email/mailer.clj
+++ src/oc/email/mailer.clj
@@ -260,7 +260,7 @@
   (mailer/send-private-board-notification (assoc board-invite :user {:email "change@me.com"}))

   (def token-request (clojure.walk/keywordize-keys (json/decode (slurp "./opt/samples/token/apple.json"))))
-  (mailer/send-token :reset (assoc reset :to "change@me.com"))
-  (mailer/send-token :verify (assoc reset :to "change@me.com"))
+  (mailer/send-token :reset (assoc token-request :to "change@me.com"))
+  (mailer/send-token :verify (assoc token-request :to "change@me.com"))

 )


fixed 0.59s issue

fixed 0.59s issue

--- src/ontrail/formats.clj
+++ src/ontrail/formats.clj
@@ -8,7 +8,7 @@

 (defn to-human-pace-minkm [duration distance]
   (let [pace  (/ (/ duration 6000) (/ distance 1000))
-        secs (int (+ 0.49 (* 60.0 (- pace (int pace)))))]
+        secs (int (* 60.0 (- pace (int pace))))]
     (str (int pace) "." (format "%02d" secs) " min/km")))

 (defn to-human-pace-kmh [duration distance]


create new protocol IBus to store free-bus fn so that it works again with new AudioBus and ControlBus records

--- src/overtone/sc/bus.clj
+++ src/overtone/sc/bus.clj
@@ -14,13 +14,24 @@
 ;; but in SC they are implemented using a simple integer referenced
 ;; array of float values.

+(defonce ^{:private true} __PROTOCOLS__
+  (do
+    (defprotocol IBus
+      (free-bus [this]))))
+
 (defrecord AudioBus [id n-channels rate name]
   to-sc-id*
-  (to-sc-id [this] (:id this)))
+  (to-sc-id [this] (:id this))
+
+  IBus
+  (free-bus [this] (free-id :audio-bus (:id this) (:n-channels this))))

 (defrecord ControlBus [id n-channels rate name]
   to-sc-id*
-  (to-sc-id [this] (:id this)))
+  (to-sc-id [this] (:id this))
+
+  IBus
+  (free-bus [this] (free-id :control-bus (:id this) (:n-channels this))))

 (defmethod print-method AudioBus [b w]
   (.write w (format "#<audio-bus: %s %s %d>"
@@ -43,7 +54,6 @@
 (derive ControlBus ::bus)

 (defn bus?
-
   "Returns true if the specified bus is a map representing a bus (either control
   or audio) "
   [bus]
@@ -89,15 +99,6 @@
      (let [id (alloc-id :audio-bus n-channels)]
        (AudioBus. id n-channels :audio name))))

-(defn free-bus
-  "Free the id of specified bus for reuse."
-  [bus]
-  (assert (bus? bus))
-  (case (type bus)
-    ::audio-bus   (free-id :audio-bus (:id bus) (:n-channels bus))
-    ::control-bus (free-id :control-bus (:id bus) (:n-channels bus)))
-  :free)
-
 ; Reserve busses for overtone
 (defonce ___reserve-overtone-busses____
   (dotimes [i AUDIO-BUS-RESERVE-COUNT]


atomize fold-interval

atomize fold-interval

--- src/riemann/streams.clj
+++ src/riemann/streams.clj
@@ -595,15 +595,14 @@
   interval seconds."
   [interval event-key folder & children]
   (part-time-fast interval
-      (fn create [] (ref []))
+      (fn create [] (atom []))
       (fn add [r event]
-        (dosync
-          (if-let [ek (event-key event)]
-            (alter r conj event))))
+        (when-let [ek (event-key event)]
+          (swap! r conj event)))
       (fn finish [r start end]
-        (let [stat (dosync
-                    (folder (map event-key @r)))
-              event (assoc (last @r) event-key stat)]
+        (let [events @r
+              stat  (folder (map event-key events))
+              event (assoc (last events) event-key stat)]
           (call-rescue event children)))))

 (defn fold-interval-metric


UI tweaks

UI tweaks

--- src/set_solver/quil.clj
+++ src/set_solver/quil.clj
@@ -5,7 +5,7 @@
             [quil.core :as q]
             [quil.middleware :as m]
             [set-solver.core :refer :all]
-            [set-solver.util :refer [constrain]])
+            [set-solver.util :refer [constrain enumerate]])
   (:import [java.nio ByteBuffer ByteOrder]
            [org.opencv.core Mat Size Rect Point CvType]
            [org.opencv.imgcodecs Imgcodecs]
@@ -100,6 +100,7 @@
     ;; not typing
     (case (:key e)
       :c (update-in state [:show-cards] not)
+      :q (update-in state [:query-filter] not)
       :j (update-in state [:top] #(+ 15 %))
       :k (update-in state [:top] #(- % 15))
       :l (update-in state [:left] #(+ 15 %))
@@ -109,6 +110,9 @@
       :/ (assoc state :typing true :query "")
       :down (load-next-image state)
       :up (load-prev-image state)
+      :left (update-in state [:debug-offset] dec)
+      :right (update-in state [:debug-offset] inc)
+      :0 (assoc state :debug-offset 0)
       state)))

 (defn setup []
@@ -123,15 +127,25 @@
             :top 0
             :query ""
             :show-cards false
+            :query-filter true
             :debug (atom nil)
+            :debug-offset 0
             :debug-avail (atom [])
             :debug-selected (atom [])})))

 (defn debug [state f text]
-  (let [query (.toLowerCase (:query state))]
-    (swap! (:debug-avail state) conj text)
+  (let [query (.toLowerCase (:query state))
+        offset (->> (:debug-avail state)
+                    (deref)
+                    (filter #(.contains (.toLowerCase %) query))
+                    (count))]
+    (when (or (not (:query-filter state))
+            (.contains (.toLowerCase text) query))
+      (swap! (:debug-avail state) conj text))
+
     (when (and (not-empty query)
                (nil? (deref (:debug state)))
+               (= offset (:debug-offset state))
                (.contains (.toLowerCase text) query))
       (swap! (:debug-selected state) conj text)
       (reset! (:debug state) (.clone (f))))))
@@ -155,10 +169,10 @@
   (q/fill 0 0 0 192)
   (q/rect 0 0 300 60)
   (q/fill 255)
-  (q/text (str (select-keys state [:left :top :zoom :query])) 15 15)
+  (q/text (str (select-keys state [:left :top :zoom :query :show-cards :query-filter :debug-offset])) 15 15)
   (q/text (str (round (q/current-frame-rate)) "/" (q/target-frame-rate)) 15 45)

-  (doseq [[line i] (map vector (deref (:debug-avail state)) (range))
+  (doseq [[i line] (enumerate (deref (:debug-avail state)))
           :let [visible (some #{line} (deref (:debug-selected state)))]]
     (if visible
       (q/fill 0 255 0)


Proper ordering, time before date

Proper ordering, time before date

--- src/tick/alpha/api.cljc
+++ src/tick/alpha/api.cljc
@@ -74,13 +74,13 @@

 ;; Construction and coercion

+(defn time
+  ([] (core/time (now)))
+  ([v] (core/time v)))
+
 (defn date
   ([] (today))
   ([v] (core/date v)))
-
-(defn time
-  ([] (core/time (now)))
-  ([v] (core/time v)))

 (defn nanosecond [t] (core/nanosecond t))
 (defn microsecond [t] (core/microsecond t))


Prefer .foo Instance args

Prefer .foo Instance args

--- src/tile_game/grid.cljs
+++ src/tile_game/grid.cljs
@@ -129,6 +129,7 @@
     ;; Rebind onkeydown with set! so figwheel can always update
     (set! (.-onkeydown js/window) (handle-keydown command))
     (ui-event-loop command)
-    (r/render-component [(fn [] (tile-grid command))] (. js/document (getElementById "grid")))))
+    (r/render-component [(fn [] (tile-grid command))]
+                        (.getElementById js/document "grid"))))

 (init)


CMR-2341 Updated error message with better verbiage

--- spatial-lib/src/cmr/spatial/messages.clj
+++ spatial-lib/src/cmr/spatial/messages.clj
@@ -75,7 +75,8 @@

 (defn ring-contains-both-poles
   []
-  "The polygon boundary contains both the North and South Poles. A polygon can contain at most one pole.")
+"The polygon boundary contains both the North and South Poles. A polygon can contain at most one pole. Please check the order of your points.
+ You may have provided them in the wrong order (clockwise vs counter-clockwise)")

 (defn ring-points-out-of-order
   []


truncate long issue titles in doc

truncate long issue titles in doc

--- src-cljs/frontend/components/canvas.cljs
+++ src-cljs/frontend/components/canvas.cljs
@@ -21,6 +21,7 @@
             [frontend.svg :as svg]
             [frontend.utils :as utils :include-macros true]
             [goog.dom]
+            [goog.string :as gstring]
             [goog.style]
             [om.core :as om :include-macros true]
             [om.dom :as dom :include-macros true])
@@ -409,7 +410,7 @@
           (when-let [issue (issue-model/find-by-doc-id @issue-db document-id)]
             (dom/g nil
               (svg-element {:layer/type :layer.type/text
-                            :layer/text (str "Feature request -- " (:issue/title issue))
+                            :layer/text (str "Feature request -- " (gstring/truncate (:issue/title issue) 40))
                             :layer/start-x 100
                             :layer/end-x 100
                             :layer/start-y 100


hack to fix lines-in-progress

hack to fix lines-in-progress

--- src-cljs/frontend/components/canvas.cljs
+++ src-cljs/frontend/components/canvas.cljs
@@ -157,16 +157,29 @@
                                         el-type (cond
                                                  (= (:current-tool payload) :line) dom/line
                                                  :else dom/dom)]
-                                    (dom/rect
-                                     (clj->js (assoc (svg/layer->svg-rect (:camera payload) sel
-                                                                          false
-                                                                          cast!)
-                                                :fill "gray"
-                                                :fillOpacity "0.25"
-                                                :strokeDasharray "5,5"
-                                                :strokeWidth 1)))))
+                                    (if (= :line (:current-tool payload))
+                                      (let [l (cameras/camera-translated-rect (:camera payload) sel (- (:layer/current-x sel) (:layer/start-x sel))
+                                                                              (- (:layer/current-y sel) (:layer/start-y sel)))]
+                                        (dom/line (clj->js (merge
+                                                            (dissoc l :x :y :width :height :stroke-width :fill)
+                                                            {:x1          (:layer/start-x l)
+                                                             :y1          (:layer/start-y l)
+                                                             :x2          (:layer/current-x l)
+                                                             :y2          (:layer/current-y l)
+                                                             :fill "gray"
+                                                             :fillOpacity "0.25"
+                                                             :strokeDasharray "5,5"
+                                                             :strokeWidth 1}))))
+                                      (dom/rect
+                                       (clj->js (assoc (svg/layer->svg-rect (:camera payload) sel
+                                                                            false
+                                                                            cast!)
+                                                  :fill "gray"
+                                                  :fillOpacity "0.25"
+                                                  :strokeDasharray "5,5"
+                                                  :strokeWidth 1))))))
                                 #_(dom/text #js {:x 15
-                                               :y 15} (pr-str (dissoc payload :layers)))]
+                                                 :y 15} (pr-str (dissoc payload :layers)))]
                                [(when (cameras/guidelines-enabled? payload)
                                   ;; TODO: Render guidelines
                                   )]))))))


Fix run button...

Fix run button...

--- src-frontend/cljs/cljs_webrepl/core.cljs
+++ src-frontend/cljs/cljs_webrepl/core.cljs
@@ -305,7 +305,7 @@
   (let [ns           (:ns @state)
         is-init?     (some? ns)
         is-blank?    (str/blank? (:input @state))
-        is-disabled? (or (not is-init?) is-blank?)]
+        is-disabled? (or (not is-init?))]
     [:div.padding-left
      ^{:key is-disabled?}
      [mdl/upgrade


Test for the function clj-calendar.calendar/get-year

--- test/clj_calendar/calendar_test.clj
+++ test/clj_calendar/calendar_test.clj
@@ -27,7 +27,7 @@

 ;
-; Actual tests.
+; Actual tests that checks if all functions exists.
 ;

 (deftest test-get-calendar-existence
@@ -105,8 +105,8 @@
 ;

 (deftest test-get-calendar
-    "Check the function clj-calendar.calendar.calendar/get-calendar."
-    (testing "the function clj-calendar.calendar.calendar/get-calendar."
+    "Check the function clj-calendar.calendar/get-calendar."
+    (testing "the function clj-calendar.calendar/get-calendar."
         (is (not (nil? (get-calendar))))
         (is (or
             (=  (class (get-calendar)) java.util.Calendar)
@@ -126,8 +126,8 @@
 ))

 (deftest test-get-calendar-2
-    "Check the function clj-calendar.calendar.calendar/get-calendar."
-    (testing "the function clj-calendar.calendar.calendar/get-calendar."
+    "Check the function clj-calendar.calendar/get-calendar."
+    (testing "the function clj-calendar.calendar/get-calendar."
         (let [calendar (get-calendar)]
             (.set calendar 2000 01 01 10 20 30)
             (is (not (nil? calendar)))
@@ -143,8 +143,8 @@
 ))

 (deftest test-get-calendar-3
-    "Check the function clj-calendar.calendar.calendar/get-calendar."
-    (testing "the function clj-calendar.calendar.calendar/get-calendar."
+    "Check the function clj-calendar.calendar/get-calendar."
+    (testing "the function clj-calendar.calendar/get-calendar."
         (is (not (nil? (get-calendar))))
         (is (>= (.get (get-calendar) (java.util.Calendar/HOUR)) 0))
         (is (<= (.get (get-calendar) (java.util.Calendar/HOUR)) 11))
@@ -159,8 +159,8 @@
 ))

 (deftest test-format-date-using-desired-format
-    "Check the function clj-calendar.calendar.calendar/format-date-using-desired-format"
-    (testing "the function clj-calendar.calendar.calendar/format-date-using-desired-format."
+    "Check the function clj-calendar.calendar/format-date-using-desired-format"
+    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
         (let [calendar (get-calendar)]
             (.set calendar 2000 01 01 10 20 30)
             (is (= "2000" (format-date-using-desired-format calendar "yyyy")))
@@ -171,8 +171,8 @@
             (is (= "30"   (format-date-using-desired-format calendar "ss"))))))

 (deftest test-format-date-using-desired-format-2
-    "Check the function clj-calendar.calendar.calendar/format-date-using-desired-format"
-    (testing "the function clj-calendar.calendar.calendar/format-date-using-desired-format."
+    "Check the function clj-calendar.calendar/format-date-using-desired-format"
+    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
         (let [calendar (get-calendar)]
             (.set calendar 2000 01 01 10 20 30)
             (is (= "2000-02"    (format-date-using-desired-format calendar "yyyy-MM")))
@@ -181,8 +181,8 @@
             (is (= "2000-01"    (format-date-using-desired-format calendar "yyyy-dd"))))))

 (deftest test-format-date-using-desired-format-3
-    "Check the function clj-calendar.calendar.calendar/format-date-using-desired-format"
-    (testing "the function clj-calendar.calendar.calendar/format-date-using-desired-format."
+    "Check the function clj-calendar.calendar/format-date-using-desired-format"
+    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
         (let [calendar (get-calendar)]
             (.set calendar 2000 01 01 10 20 30)
             (is (= "10:20"      (format-date-using-desired-format calendar "hh:mm")))
@@ -192,37 +192,45 @@
             (is (= "2000-02-01 10:20:30"  (format-date-using-desired-format calendar "yyyy-MM-dd hh:mm:ss"))))))

 (deftest test-format-date-time-1
-    "Check the function clj-calendar.calendar.calendar/format-date-time"
-    (testing "the function clj-calendar.calendar.calendar/format-date-time"
+    "Check the function clj-calendar.calendar/format-date-time"
+    (testing "the function clj-calendar.calendar/format-date-time"
         (let [calendar (get-calendar)]
             (.set calendar 2000 01 01 10 20 30)
             (is (= "2000-02-01 10:20:30" (format-date-time calendar))))))

 (deftest test-format-date-time-2
-    "Check the function clj-calendar.calendar.calendar/format-date-time"
-    (testing "the function clj-calendar.calendar.calendar/format-date-time"
+    "Check the function clj-calendar.calendar/format-date-time"
+    (testing "the function clj-calendar.calendar/format-date-time"
         (let [calendar (get-calendar)]
             (.set calendar 2000 00 01 10 20 30)
             (is (= "2000-01-01 10:20:30" (format-date-time calendar))))))

 (deftest test-format-date-time-3
-    "Check the function clj-calendar.calendar.calendar/format-date-time"
-    (testing "the function clj-calendar.calendar.calendar/format-date-time"
+    "Check the function clj-calendar.calendar/format-date-time"
+    (testing "the function clj-calendar.calendar/format-date-time"
         (let [calendar (get-calendar)]
             (.set calendar 2000 00 31 10 20 30)
             (is (= "2000-01-31 10:20:30" (format-date-time calendar))))))

 (deftest test-format-date-time-4
-    "Check the function clj-calendar.calendar.calendar/format-date-time"
-    (testing "the function clj-calendar.calendar.calendar/format-date-time"
+    "Check the function clj-calendar.calendar/format-date-time"
+    (testing "the function clj-calendar.calendar/format-date-time"
         (let [calendar (get-calendar)]
             (.set calendar 2000 11 31 10 20 30)
             (is (= "2000-12-31 10:20:30" (format-date-time calendar))))))

 (deftest test-format-date-time-5
-    "Check the function clj-calendar.calendar.calendar/format-date-time"
-    (testing "the function clj-calendar.calendar.calendar/format-date-time"
+    "Check the function clj-calendar.calendar/format-date-time"
+    (testing "the function clj-calendar.calendar/format-date-time"
         (let [calendar (get-calendar)]
             (.set calendar 2000 00 01 00 00 00)
             (is (= "2000-01-01 00:00:00" (format-date-time calendar))))))

+(deftest test-get-year
+    "Check the function clj-calendar.calendar/get-year"
+    (testing "the function clj-calendar.calendar/get-year"
+        (let [calendar (get-calendar)]
+            (doseq [year (range 1 9999)]
+                (.set calendar year 00 01 00 00 00)
+                (is (= year (get-year calendar)))))))
+


Fixes test

Fixes test

--- test/hundred_pushups/core_test.cljc
+++ test/hundred_pushups/core_test.cljc
@@ -47,7 +47,7 @@
     (let [ts #inst "2016-01-01"]
       (is (= {:exr/circuit
               {:exr/pushup-reps 7 :exr/plank-reps 10}
-              :exr/sets 5}
+              :exr/sets 4}
              (let [test-log [{:exr/pushup-reps 10 :exr/plank-reps 15}]
                    circuit-log []]
                (->> circuit-log


Oops had a tab in there.

Oops had a tab in there.

--- src/clj/backtype/storm/daemon/nimbus.clj
+++ src/clj/backtype/storm/daemon/nimbus.clj
@@ -1034,7 +1034,7 @@
         (to-json (try-read-storm-conf conf id)))

       (^StormTopology getTopology [this ^String id]
-	(system-topology! (try-read-storm-conf conf id) (try-read-storm-topology conf id)))
+        (system-topology! (try-read-storm-conf conf id) (try-read-storm-topology conf id)))

       (^StormTopology getUserTopology [this ^String id]
         (try-read-storm-topology conf id))


Generic button component in the navbar

Generic button component in the navbar

--- src/cljs/my_money/components/navbar.cljs
+++ src/cljs/my_money/components/navbar.cljs
@@ -47,6 +47,14 @@
       [nav-item [login-button]]
       [nav-item [registration-button]]])])

+(def button-styles ["btn" "btn-outline-info" "ml-1"])
+
+
+;; TODO: MOVE ELSEWHERE, CREATE A GENERAL BUTTON COMPONENT
+(defn button [props child]
+  (let [props-with-default-styles (update props :class concat button-styles)]
+    [:button props-with-default-styles child]))
+
 (defn navbar [e!]
   (r/with-let [collapsed? (r/atom true)]
     [:nav.mb-2.relative.flex.md:flex-row.md:flex-nowrap.md:justify-start.items-center.px-4.py-2.bg-black.bg-opacity-75
@@ -60,6 +68,9 @@
       [:ul.flex.pl-0.mb-0.list-none
        (when (session/get :identity)
          [:<>
-          [:button.btn.btn-outline-info.fa.fa-cog.fa-inverse.ml-1 {:on-click #(routes/navigate! :config)}]
-          [:button.btn.btn-outline-info.ml-1 {:on-click #(routes/navigate! :upload)} "Upload"]])]
+          [button {:class ["fa" "fa-cog" "fa-inverse"]
+                   :on-click #(routes/navigate! :config)}]
+          [button {:on-click #(routes/navigate! :upload)}
+           "Upload"]])]
       [user-menu e!]]]))
+


creating instance of working database is woriking, next is to read and write and some queries

--- src/clojure/my/company/superapp/main.clj
+++ src/clojure/my/company/superapp/main.clj
@@ -227,10 +227,8 @@

     ;; setup the couchbase database
     ;; the problem is that i can not create an instance of AndroidContext due to illeagal agrument.
-    (log/i "testing androidContext")
-    (.AndroidContext (*a))
     (log/i "creating manager")
-    (def manager (.Manager (.AndroidContext this) (.getField Manager "DEFAULT_OPTIONS")))
+    (def manager (Manager. (AndroidContext. (*a)) (.get (.getField Manager "DEFAULT_OPTIONS") nil)))
     (log/i "creteing database")
     (def db-name "hello")
     (def database (.getDatabase manager db-name))


Allow overrides of other params in create-db

--- src/cavm/h2.clj
+++ src/cavm/h2.clj
@@ -814,12 +814,16 @@
            probemap_sources :probemaps_id pmid files)
          (dorun (map add-probe probes)))))))

-(defn create-db [file]
-  (kdb/create-db  {:classname "org.h2.Driver"
-                   :subprotocol "h2"
+(defn create-db [file & [{:keys [classname subprotocol delimiters make-pool?]
+                          :or {classname "org.h2.Driver"
+                               subprotocol "h2"
+                               delimiters "`"
+                               make-pool? true}}]]
+  (kdb/create-db  {:classname classname
+                   :subprotocol subprotocol
                    :subname file
-                   :delimiters "`"
-                   :make-pool? true}))
+                   :delimiters delimiters
+                   :make-pool? make-pool?}))

 (defmacro with-db [db & body]
   `(kdb/with-db ~db ~@body))


finish every?

finish every?

--- src/chartem.clj
+++ src/chartem.clj
@@ -14,11 +14,11 @@
 ;;  a match is a map with pass? and message, message will be a string
 ;;  if pass? if false

-(defn equals
+(defn =
   "matches based on equality of the value given

-  (run-match (equals 1) 1) ; => passes
-  (run-match (equals 1) 2) ; => fails "
+  (chartem/run-match (chartem/= 1) 1) ; => passes
+  (chartem/run-match (chartem/= 1) 2) ; => fails "
   [a]
   {:match (fn [b] (= a b))
    :description (str "(= " (pr-str a) ")")
@@ -32,17 +32,25 @@
        "\n     but: "
        (:was result)))

+(defn describe-list [call xs]
+  (str "(" call " " (clojure.string/join " " xs) ")"))
+
 (defn every?
   "matches if all of the matchers given pass:

-  (run-match (every? (equals 1) (equals 1)) 1) ; => passes
-  (run-match (every? (equals 1) (equals 1)) 2) ; => fails"
+  (chartem/run-match (every? (chartem/= 1) (chartem/= 1)) 1) ; => passes
+  (chartem/run-match (every? (chartem/= 1) (chartem/= 1)) 2) ; => fails"
   [ms]
-  {:match (fn [a] (reduce (fn [x y] (and x y))
+  {:match
+   (fn [a] (reduce (fn [x y] (and x y))
                           (map #((:match %) a) ms)))
-   :description (str "(every? " (clojure.string/join " "
-                                                     (map :description ms)) ")")
-   :describe-mismatch })
+   :description
+   :describe-mismatch
+   (describe-list "every?" (map :description ms))
+   (fn [a]
+     (->> ms
+       (filter #(not ((:match %) a)))
+       (map #((:describe-mismatch %) a))))})

 (defn run-match
   "runs a matcher, given a value to match against.


We want the metadata.

We want the metadata.

--- src/cljs/go.clj
+++ src/cljs/go.clj
@@ -209,7 +209,8 @@
            (println "compiling" (str resource))
            (io/make-parents src)
            (spit src (with-out-str
-                       (binding [*ns* (find-ns ('{cljs.go.core cljs.core cljs.go.compiler cljs.compiler} ns ns))]
+                       (binding [*ns* (find-ns ('{cljs.go.core cljs.core cljs.go.compiler cljs.compiler} ns ns))
+                                 *print-meta* true]
                         (doseq [f (read-string (str "[" (slurp resource) "]"))]
                           (pp/pprint ((fn expander [f]
                                          (w/prewalk


add autotest

add autotest

--- parinfer-lib/dev/build.clj
+++ parinfer-lib/dev/build.clj
@@ -33,3 +33,18 @@
   (-> (test-setup)
       (node/execute-all-tests!))
   :done)
+
+(defn autotest
+  [& args]
+  (-> (test-setup)
+      (cljs/watch-and-repeat!
+        (fn [state modified]
+          (-> state
+              (cond->
+                ;; first pass, run all tests
+                (empty? modified)
+                (node/execute-all-tests!)
+                ;; only execute tests that might have been affected by the modified files
+                (not (empty? modified))
+                (node/execute-affected-tests! modified))
+              )))))


logging and comments

logging and comments

--- src/babel/parse.cljc
+++ src/babel/parse.cljc
@@ -9,7 +9,7 @@

 ;; for now, using a language-independent tokenizer.
 (def tokenizer #"[ ']")
-
+(declare over)
 (declare toks2)

 (defn toks [s lexicon lookup]
@@ -20,7 +20,9 @@
     (vec tokens2)))

 (defn toks2 [tokens lexicon lookup]
-  "like (toks), but use lexicon to consolidate two initial tokens into one. may consolidate larger groups than two in the future."
+  "take a list of strings and looks up each in lexicon, as well as
+  looking up sub-lists of two tokens in the lexicon as well. May
+  consolidate larger-than-two sub-lists in the future."
   (cond (nil? tokens) nil
         (empty? tokens) nil
         (> (count tokens) 1)
@@ -47,12 +49,17 @@
      (create-unigram-map args (+ 1 index)))))

 (defn create-bigram-map [args index grammar]
+  (log/debug (str "create-bigram-map: args count: " (count args)))
   (if (< (+ 1 index) (count args))
     (let [left-side (subvec args index (+ 1 index))
           right-side (subvec args (+ 1 index) (+ 2 index))]
+      (log/debug (str "create-bigram-map: size of left-side: " (count left-side)))
+      (log/debug (str "create-bigram-map: size of right-side: " (count right-side)))
       (merge
        {[index (+ 2 index)]
-        (over/over grammar left-side right-side)}
+        (over grammar
+              (list (first left-side))
+              (list (first right-side)))}
        (create-bigram-map args (+ index 1) grammar)))
     (create-unigram-map args 0)))

@@ -82,6 +89,7 @@

 (defn over [grammar left right]
   "opportunity for additional logging before calling the real (over)"
+  (log/debug (str "parse/over: grammar: " (count grammar) " left: " (type left) "; right: " (type right)))
   (over/over grammar left right))

 (defn create-ngram-map [args left ngrams grammar split-at x]
@@ -99,7 +107,24 @@
 (defn create-xgram-map [args x index grammar & [nminus1grams runlevel]]
   (cond (= x 0) {}
         (= x 1) (create-unigram-map args index)
-        (= x 2) (create-bigram-map args index grammar)
+        (= x 2) (let [bigram-map (create-bigram-map args index grammar)]
+                  (log/trace (str "create-xgram-map: bigram-map: " bigram-map))
+                  (log/debug (str "create-xgram-map: keys: " (keys bigram-map)))
+                  (log/debug (str "create-xgram-map: vals: "
+                                  (string/join ";"
+                                               (map
+                                                (fn [val]
+                                                  (string/join ","
+                                                               (map (fn [x]
+                                                                      (cond
+                                                                        (map? x)
+                                                                        (:rule x)
+                                                                        true (str
+                                                                              "not map:"
+                                                                              (type x))))
+                                                                    val)))
+                                                (vals bigram-map)))))
+                  bigram-map)

         true (let [nminus1grams (if nminus1grams nminus1grams
                                     (create-xgram-map args (- x 1) 0 grammar))]
@@ -128,7 +153,9 @@
 (defn parse [arg lexicon lookup grammar]
   "return a list of all possible parse trees for a string or a list of lists of maps (a result of looking up in a dictionary a list of tokens from the input string)"
   (cond (string? arg)
-        (parse (toks arg lexicon lookup) lexicon lookup grammar)
+        (let [tokens (toks arg lexicon lookup)]
+          (log/debug (str "tokens: " (count tokens)))
+          (parse tokens lexicon lookup grammar))

         (and (vector? arg)
              (empty? (rest arg)))


turn down logging

turn down logging

--- src/babel/writer.clj
+++ src/babel/writer.clj
@@ -183,7 +183,7 @@
       (log/error (str "SQL error: " (.printStackTrace (.getNextException(.getSQLException e))))))))

 (defn insert-lexeme [canonical lexeme language]
-  (log/info (str "insert-lexeme: canonical=" canonical ",lexeme=" (strip-refs lexeme) ",language=" language))
+  (log/debug (str "insert-lexeme: canonical=" canonical ", language=" language))
   (if (fail? lexeme)
     (let [message (str "Refusing to enter a :fail for canonical form: " canonical)]
       (log/error message)


Establish a bound on the maximum number of samples an agent will attempt to post to a vault.

--- metlog-agent/src/metlog_agent/core.clj
+++ metlog-agent/src/metlog_agent/core.clj
@@ -8,6 +8,8 @@
             [cognitect.transit :as transit]
             [clj-time.format :as time-format]
             [clj-time.coerce :as time-coerce]))
+
+(def update-size-limit 200)

 (defn pr-transit [ val ]
   (let [out (java.io.ByteArrayOutputStream. 4096)
@@ -73,7 +75,8 @@
   (try
     ((:sensor-fn sensor-def))
     (catch Exception ex
-      (log/error "Error polling sensor" (:sensor-name sensor-def) (str ex))
+      (log/error (str "Error polling sensor: " (:sensor-name sensor-def)
+                      " (" (.getMessage ex) ")"))
       false)))

 (defn process-sensor-reading [ sensor-name ts-sensor-reading ]
@@ -105,10 +108,11 @@
     (doseq [ ts-sensor-reading (->timestamped-readings (poll-sensor sensor-def)) ]
       (process-sensor-reading (:sensor-name sensor-def) ts-sensor-reading))))

-(defn take-result-queue-snapshot [ ]
+(defn take-result-queue-snapshot [ snapshot-size-limit ]
   (let [ snapshot (java.util.concurrent.LinkedBlockingQueue.) ]
     (locking sensor-result-queue
-      (.drainTo sensor-result-queue snapshot))
+      (log/info "Taking snapshot queue with n:" (.size sensor-result-queue) ", limit:" snapshot-size-limit)
+      (.drainTo sensor-result-queue snapshot snapshot-size-limit ))
     (seq snapshot)))

 (def update-queue (java.util.concurrent.LinkedBlockingQueue.))
@@ -119,17 +123,38 @@
 (defn post-readings [ url readings ]
   (log/debug "Posting" (count readings) "reading(s) to" url)
   (let [post-response
-        (http/post url {:content-type "application/transit+json"
-                        :body (pr-transit readings)}) ]
+        (try
+          (http/post url {:content-type "application/transit+json"
+                          :body (pr-transit readings)})
+          (catch java.net.ConnectException ex
+            ;; Pretend connection errors are HTTP errors
+            (log/error (str "Error posting readings to " url " (" (.getMessage ex) ")"))
+            {:status 400})) ]
     (= (:status post-response) 200)))

+(defn snapshot-to-update-queue []
+  (locking update-queue
+    (let [snapshot (take-result-queue-snapshot
+                    (min update-size-limit
+                         (- update-size-limit (.size update-queue)))) ]
+      (when snapshot
+        (.addAll update-queue snapshot))
+      snapshot)))
+
+(defn post-update []
+  (locking update-queue
+    (or (.isEmpty update-queue)
+        (and (post-readings vault-url (clean-readings (seq update-queue)))
+             (do
+               (.clear update-queue)
+               true)))))
+
 (defn update-vault []
-  (locking update-queue
-    (when-let [ snapshot (take-result-queue-snapshot) ]
-      (.addAll update-queue snapshot))
-    (unless (.isEmpty update-queue)
-            (when (post-readings vault-url (clean-readings (seq update-queue)))
-              (.clear update-queue)))))
+  (loop []
+    (let [snapshot (snapshot-to-update-queue)]
+      (when (and (post-update)
+                 (> (count snapshot) 0))
+        (recur)))))

 (defn maybe-load-config-file [ filename ]
   (binding [ *ns* (find-ns 'metlog-agent.core)]


Add max-density and max-coverage functions.

--- src/clj/c2/ticks.clj
+++ src/clj/c2/ticks.clj
@@ -36,8 +36,38 @@
                     (sq (- d-min l-min)))
                  (sq (* 0.1 (- d-max d-min)))))))

+(defn max-coverage
+  "When the label range is centered on the data range"
+  [d-min d-max span]
+  (let [d-range (- d-max d-min)]
+    (if (> span d-range)
+      (- 1 (sq (/ (- span d-range)
+                  (* 0.2 d-range))))
+      1)))
+
 (defn density
   "Objective function for a candidate density r and desired density rt (e.g. labels-per-cm)"
   [r rt]
   ;;Note the formula should be 2-, not 1- as in the paper.
   (- 2 (max (/ r rt) (/ rt r))))
+
+(defn max-density [r rt]
+  (if (>= r rt)
+    (- 2 (/ r rt))
+    1))
+
+(defn- w
+  "Balance the relative merits of different metrics"
+  [[simplicity coverage density legibility]]
+  (let [w [0.2 0.25 0.5 0.05]]
+    (+ (* simplicity (w 1))
+       (* coverage (w 2))
+       (* density (w 3))
+       (* legibility (w 4)))))
+
+
+
+(defn search
+  "Find best ticks for the data range (dmin, dmax) and target label density m"
+  [dmin dmax m]
+  )