Focus management #38 - corrected focus traversal order calculation

--- flatguicore/src/flatgui/focus.clj
+++ flatguicore/src/flatgui/focus.clj
@@ -12,7 +12,8 @@
             [flatgui.inputchannels.awtbase :as inputbase]
             [flatgui.inputchannels.mouse :as mouse]
             [flatgui.inputchannels.keyboard :as keyboard]
-            [flatgui.util.matrix :as m])
+            [flatgui.util.matrix :as m]
+            [flatgui.util.rectmath :as rect])
   (:import (java.awt.event KeyEvent)
            (java.util Comparator)))

@@ -38,12 +39,28 @@
 (def component-comparator
   (reify Comparator
     (compare [_this o1 o2]
-      (let [by-x (- (m/mx-x (:position-matrix o1)) (m/mx-x (:position-matrix o2)))]
-        (if (= by-x 0)
-          (- (m/mx-y (:position-matrix o1)) (m/mx-y (:position-matrix o2)))
-          by-x)))))
-
-(defn- sort-lines [lines] (map (fn [l] (sort component-comparator l)) lines))
+      (let [x1 (m/mx-x (:position-matrix o1))
+            x2 (m/mx-x (:position-matrix o2))]
+        (if (< x1 x2)
+          -1
+          (if (> x1 x2)
+            1
+            (let [y1 (m/mx-y (:position-matrix o1))
+                  y2 (m/mx-y (:position-matrix o2))]
+              (if (< y1 y2) -1 (if (> y1 y2) 1 0)))))))))
+
+(defn- sort-each-line-by-x [lines] (mapv (fn [l] (sort component-comparator l)) lines))
+
+(def line-comparator
+  (reify Comparator
+    (compare [_this o1 o2]
+      (if (< (:line-y1 o1) (:line-y1 o2))
+        -1
+        (if (> (:line-y1 o1) (:line-y1 o2)) 1 0)))))
+
+(defn- sort-lines-by-y [lines line-y1]
+  (let [line-maps (map (fn [i] {:line (nth lines i) :line-y1 (nth line-y1 i)}) (range 0 (count lines)))]
+    (mapv #(:line %) (sort line-comparator line-maps))))

 (fg/defaccessorfn group-by-lines [component accepting-children]
   (let [cnt (count accepting-children)]
@@ -53,21 +70,21 @@
            i 0]
       (if (< i cnt)
         (let [c (nth accepting-children i)
-              cy (m/mx-y (get-property component [:this (:id c)] :position-matrix))
+              cy1 (m/mx-y (get-property component [:this (:id c)] :position-matrix))
+              cy2 (+ cy1 (m/y (get-property component [:this (:id c)] :clip-size)))
               line-index (if-let [matching (some
-                                             #(if (<= (nth line-y1 %) cy (nth line-y2 %)) %)
+                                             (fn [j] (if (rect/line& cy1 cy2 (nth line-y1 j) (nth line-y2 j)) j))
                                              (range 0 (count lines)))]
                            matching
                            (count lines))
               existing-line (< line-index (count lines))
-              line (if existing-line (nth lines line-index) #{})
-              cy2 (+ cy (m/y (get-property component [:this (:id c)] :clip-size)))]
+              line (if existing-line (nth lines line-index) #{})]
           (recur
-            (if existing-line line-y1 (assoc line-y1 line-index cy))
+            (assoc line-y1 line-index (if existing-line (min cy1 (nth line-y1 line-index)) cy1))
             (assoc line-y2 line-index (if existing-line (max cy2 (nth line-y2 line-index)) cy2))
             (assoc lines line-index (conj line c))
             (inc i)))
-        (sort-lines lines)))))
+        (sort-lines-by-y (sort-each-line-by-x lines) line-y1)))))

 ;;; Sorts focusable components so that they are traversed in left->right, up->down direction.
 ;;; To make such ad order, arranges components in a vector of horizontal "lines"


change out the cljs config with docker hostname

--- frontend/src/cruncher/config.cljs
+++ frontend/src/cruncher/config.cljs
@@ -1,6 +1,6 @@
 (ns cruncher.config)

-(def api {:host "http://0.0.0.0:5000/"
+(def api {:host "http://backend:5000/"
           :init "api/init/"
           :base "api/"
           :login "api/login"


Remove side effect on workspace initialization.

--- frontend/uxbox/data/projects.cljs
+++ frontend/uxbox/data/projects.cljs
@@ -127,7 +127,7 @@
       (let [s {:project projectid
                :toolboxes #{}
                :page pageid}]
-        (update state :workspace merge s)))
+        (assoc state :workspace s)))

     IPrintWithWriter
     (-pr-writer [mv writer _]
@@ -159,7 +159,7 @@
          (let [pages (project-pages state projectid)
                pageid (:id (first pages))]
            (rs/emit! (r/navigate :workspace/page {:project-uuid projectid
-                                             :page-uuid pageid})))))
+                                                  :page-uuid pageid})))))
      IPrintWithWriter
      (-pr-writer [mv writer _]
        (-write writer "#<event:u.s.p/go-to-project")))))


fix my provided? code

fix my provided? code

Signed-off-by: Chris Granger <5654cde260ae99bc4d30054171b8bcd902efd19a@gmail.com>

--- src/lt/util/load.cljs
+++ src/lt/util/load.cljs
@@ -54,12 +54,12 @@
   (count (.filter (js/Object.keys provided) #(> (.indexOf % parent) -1))))

 (defn only-ancestors? [cur s]
-  (= (.-length (js/Object.keys cur)) (provided-ancestors s)))
+  (<= (.-length (js/Object.keys cur)) (provided-ancestors s)))

 (defn provided? [s]
   (let [res (if (aget provided s)
               true
               (when-let [cur (obj-exists? s)]
-                (only-ancestors? cur s)))]
+                (not (only-ancestors? cur s))))]
     (aset provided s true)
     res))


Lift start-up-time out of the /info handler function (#712)

--- scheduler/src/cook/mesos/api.clj
+++ scheduler/src/cook/mesos/api.clj
@@ -1141,13 +1141,14 @@
       (-> instance
           (assoc :job (select-keys job [:uuid :name :status :state :user]))))))

+;; We store the start-up time (ISO-8601) for reporting on the /info endpoint
+(def start-up-time (tf/unparse iso-8601-format (t/now)))
+
 (defn cook-info-handler
   "Handler for the /info endpoint"
   [settings]
   (let [auth-middleware (:authorization-middleware settings)
-        auth-scheme (str (or (-> auth-middleware meta :json-value) auth-middleware))
-        ;; We store the start-up time (ISO-8601) for reporting on the /info endpoint
-        start-up-time (tf/unparse iso-8601-format (t/now))]
+        auth-scheme (str (or (-> auth-middleware meta :json-value) auth-middleware))]
     (base-cook-handler
       {:allowed-methods [:get]
        :handle-ok (fn get-info-handler [_]


Event names are now links.

Event names are now links.

--- src/vertigo/core.clj
+++ src/vertigo/core.clj
@@ -1,5 +1,6 @@
 (ns views
-  (:use [hiccup.core]))
+  (:use [hiccup.core]
+        [hiccup.page-helpers]))

 (defn layout [content]
   (html [:html
@@ -9,7 +10,7 @@
               content]]]))

 (defn render-show [show]
-  [:div (:title show)])
+  [:div (link-to (str "/shows/" (:event-id show)) (:title show))])

 (defn show-table [shows]
   [:table
@@ -52,7 +53,7 @@
 (defn parse-shows-and-group-by-genre [xz]
   (let [shows (for [show (xml-> xz :Shows :Show)]
           (Show.
-            (xml1-> show :EventId text)
+            (xml1-> show :EventID text)
             (xml1-> show :OriginalTitle text)
             (xml1-> show :TheatreAndAuditorium text)
             (into #{} (split (xml1-> show :Genres text) #", "))
@@ -70,7 +71,8 @@
   (let [formatted-date (unparse (formatter "dd.MM.yyyy") date)
         cached-shows   (get @shows-db formatted-date)]
     (if cached-shows
-      [formatted-date cached-shows]
+      {:date           formatted-date
+       :shows-by-genre cached-shows}
       (let [new-shows (parse-shows-and-group-by-genre
                         (zip/xml-zip
                           (xml/parse


handle unknown task

handle unknown task

--- server/src/gratefulplace/app.clj
+++ server/src/gratefulplace/app.clj
@@ -15,4 +15,5 @@
    (= cmd "db/reload") (final (println (db-tasks/reload)))
    (= cmd "db/seed") (final (println (db-tasks/seed)))
    (= cmd "db/install-schemas") (final (println (db-tasks/install-schemas)))
-   (= cmd "config/print-config") (final (config/print-config))))+   (= cmd "config/print-config") (final (config/print-config))
+   :else (final (println "unrecognized task"))))


Add docstring to util/mapply

Add docstring to util/mapply

--- src/overtone/util.clj
+++ src/overtone/util.clj
@@ -172,5 +172,9 @@
   [m]
   (apply hash-map (interleave (vals m) (keys m))))

-(defn mapply [f coll-coll]
+(defn mapply
+  "Takes a fn and a seq of seqs and returns a seq representing the application of the fn on each sub-seq
+
+   (mapply + [[1 2 3] [4 5 6] [7 8 9]]) ;=> [6 15 24]"
+  [f coll-coll]
   (map #(apply f %) coll-coll))


Cosmetic changes to time demo.

Cosmetic changes to time demo.

--- src/re_demo/time.cljs
+++ src/re_demo/time.cljs
@@ -29,20 +29,20 @@
    :children [[:div.h4 "General notes:"]
               [:div {:style {:font-size "small"}}
                [:p "Accepts input of a time. The callback is triggered when the input loses focus. If the entered value is invalid it will be ignored."]
-               [:p "Times are passed to the component and returned in the callback as integers e.g. 1830 is '18:30'."]
+               [:p "Times are passed to the component and returned in the callback as integers e.g. '18:30' is 1830."]
                [:p "If invalid data is provided in the model or other parameters, an exception will be thrown."]
                [:div.h4 "Parameters"]
                [:label {:style {:font-variant "small-caps"}} "required"]
                 [:ul
-                 [:li.spacer [:strong ":model"] " - an integer time e.g. 930"]]
+                 [:li.spacer [:code ":model"] " - an integer time e.g. 930"]]
                [:label {:style {:font-variant "small-caps"}} "optional"]
                 [:ul
-                  [:li.spacer [:strong ":minimum"] " - min time as an integer e.g.  930 - will not allow input less than this time - default 0."]
-                  [:li.spacer [:strong ":maximum"] " - max time as an integer e.g. 1400 - will not allow input more than this time - default 2359."]
-                  [:li.spacer [:strong ":on-change"] " - function to call upon change."]
-                  [:li.spacer [:strong ":disabled"] " - true if the component should be disabled - default false"]
-                  [:li.spacer [:strong ":show-time-icon"] " - true if the clock icon should be displayed - default false"]
-                  [:li.spacer [:strong ":style"] " - css style"]]]]])
+                  [:li.spacer [:code ":minimum"] " - min time as an integer e.g.  930 - will not allow input less than this time - default 0."]
+                  [:li.spacer [:code ":maximum"] " - max time as an integer e.g. 1400 - will not allow input more than this time - default 2359."]
+                  [:li.spacer [:code ":on-change"] " - function to call upon change."]
+                  [:li.spacer [:code ":disabled"] " - true if the component should be disabled - default false"]
+                  [:li.spacer [:code ":show-time-icon"] " - true if the clock icon should be displayed - default false"]
+                  [:li.spacer [:code ":style"] " - css style"]]]]])

 ;; TODO write a macro to convert the demo source to actual code - see time-input-demo and time-input-code in each demo

@@ -58,9 +58,9 @@
                      [:label "Usage -"]
                      [:pre [:code time-input-code]]
                      [:ul
-                       [:li [:strong ":model"] " - atom on nil"]
-                       [:li [:strong ":minimum"] " - nil - (default 0)"]
-                       [:li [:strong ":maximum"] " - nil - (default 2359)"]]
+                       [:li [:code ":model"] " - atom on nil"]
+                       [:li [:code ":minimum"] " - nil - (default 0)"]
+                       [:li [:code ":maximum"] " - nil - (default 2359)"]]
                      [:label "Demo -"]
                      time-input-demo]]])))

@@ -77,10 +77,10 @@
                    [:label "Usage -"]
                    [:pre [:code time-input-code]]
                    [:ul
-                     [:li [:strong ":model"] " - atom on 600"]
-                     [:li [:strong ":style"] " - map with: {:border \"none\"}"]
-                     [:li [:strong ":minimum"] " - nil - (default 0)"]
-                     [:li [:strong ":maximum"] " - nil - (default 2359)"]]
+                     [:li [:code ":model"] " - atom on 600"]
+                     [:li [:code ":style"] " - map with: {:border \"none\"}"]
+                     [:li [:code ":minimum"] " - nil - (default 0)"]
+                     [:li [:code ":maximum"] " - nil - (default 2359)"]]
                    [:label "Demo -"]
                    time-input-demo]]])))

@@ -96,10 +96,10 @@
                    [:label "Usage -"]
                    [:pre [:code time-input-code]]
                    [:ul
-                     [:li [:strong ":model"] " - atom on nil"]
-                     [:li [:strong ":disabled"] " - true"]
-                     [:li [:strong ":minimum"] " - nil -(default 0)"]
-                     [:li [:strong ":maximum"] " - nil - (default 2359)"]]
+                     [:li [:code ":model"] " - atom on nil"]
+                     [:li [:code ":disabled"] " - true"]
+                     [:li [:code ":minimum"] " - nil -(default 0)"]
+                     [:li [:code ":maximum"] " - nil - (default 2359)"]]
                    [:label "Demo -"]
                    time-input-demo]]])))

@@ -119,10 +119,10 @@
                    [:label "Usage -"]
                    [:pre [:code time-input-code]]
                    [:ul
-                     [:li [:strong ":model"] " - atom on 900"]
-                     [:li [:strong ":on-change"] " - update the model with the new value"]
-                     [:li [:strong ":minimum"] " - (default) 0"]
-                     [:li [:strong ":maximum"] " - (default) 2359"]]
+                     [:li [:code ":model"] " - atom on 900"]
+                     [:li [:code ":on-change"] " - update the model with the new value"]
+                     [:li [:code ":minimum"] " - (default) 0"]
+                     [:li [:code ":maximum"] " - (default) 2359"]]
                    [:label "Demo -"]
                    time-input-demo]]])))

@@ -147,10 +147,10 @@
                    [:label "Usage -"]
                    [:pre [:code time-input-code]]
                    [:ul
-                     [:li [:strong ":model"] " - atom on 900"]
-                     [:li [:strong ":on-change"] " - update the model with the new value"]
-                     [:li [:strong ":minimum"] " - 600"]
-                     [:li [:strong ":maximum"] " - 2159"]]
+                     [:li [:code ":model"] " - atom on 900"]
+                     [:li [:code ":on-change"] " - update the model with the new value"]
+                     [:li [:code ":minimum"] " - 600"]
+                     [:li [:code ":maximum"] " - 2159"]]
                    [:label "Demo -"]
                    [:p "Try typing a value outside the range."]
                    time-input-demo]]])))


Add some docs and assert

Add some docs and assert

--- src/reagent/core.cljs
+++ src/reagent/core.cljs
@@ -154,7 +154,23 @@

 (defn wrap
+  "Provide a combination of value and callback, that looks like an atom.
+
+  The first argument can be any value, that will be returned when the
+  result is deref'ed.
+
+  The second argument should be a function, that is called with the
+  optional extra arguments provided to wrap, and the new value of the
+  resulting 'atom'.
+
+  Use for example like this:
+
+  (wrap (:foo @state)
+        swap! state assoc :foo)
+
+  Probably useful only for passing to child components."
   [value reset-fn & args]
+  (assert (ifn? reset-fn))
   (util/make-wrapper value reset-fn args))

@@ -169,10 +185,20 @@
     ... @c ;; equivalent to (get-in @ra [:nested :content])
     ... (reset! c 42) ;; equivalent to (swap! ra assoc-in [:nested :content] 42)
     ... (swap! c inc) ;; equivalence to (swap! ra update-in [:nested :content] inc)
-    )"
+    )
+The third argument may be a function, that is called with
+optional extra arguments provided to cursor, and the new value of the
+resulting 'atom'. If such a function is given, it should update the
+given Reagent atom.
+"
   ([path] (fn [ra] (cursor path ra)))
-  ([path ra] (ratom/cursor path ra))
-  ([path ra reset-fn & args] (ratom/cursor path ra reset-fn args)))
+  ([path ra]
+   (assert (satisfies? IDeref ra))
+   (ratom/cursor path ra))
+  ([path ra reset-fn & args]
+   (assert (satisfies? IDeref ra))
+   (assert (ifn? reset-fn))
+   (ratom/cursor path ra reset-fn args)))

 ;; Utilities


CMR-6087: Fix failing test.

CMR-6087: Fix failing test.

--- system-int-test/test/cmr/system_int_test/health_test.clj
+++ system-int-test/test/cmr/system_int_test/health_test.clj
@@ -85,7 +85,8 @@
 (deftest search-health-test
   (s/only-with-real-database
     (is (= [200 {:echo {:ok? true}
-                 :internal-metadata-db good-metadata-db-health}]
+                 :internal-metadata-db good-metadata-db-health
+                 :indexer good-indexer-health}]
            (get-app-health (url/search-health-url))))))

 (deftest bootstrap-health-test


Keep the char in stencil.utils/html-escape unboxed, makes a difference in html-escape runtime.

--- src/stencil/utils.clj
+++ src/stencil/utils.clj
@@ -8,7 +8,7 @@
     (loop [idx 0]
       (if (>= idx (count s))
         (.toString sb)
-        (let [c (.charAt s idx)]
+        (let [c (char (.charAt s idx))]
           (case c
             \& (.append sb "&")
             \< (.append sb "<")


Remove ellipsis.

Remove ellipsis.

--- src/via/endpoint.cljs
+++ src/via/endpoint.cljs
@@ -122,7 +122,7 @@
                                     backoff-sq
                                     (exponential-seq 2 max-reconnect-interval))
                        interval (first backoff-sq)]
-                   (js/console.info (str "Disconnected from via endpoint. Reconnecting in " (str interval "ms...")))
+                   (js/console.info (str "Disconnected from via endpoint. Reconnecting in " (str interval "ms.")))
                    (<! (timeout interval))
                    (recur (rest backoff-sq))))))
            (close! control-ch)


Mark relevant-cljs-edn fn private

Mark relevant-cljs-edn fn private

--- src/adzerk/boot_reload.clj
+++ src/adzerk/boot_reload.clj
@@ -66,7 +66,7 @@
         pr-str
         ((partial spit out-file))))))

-(defn relevant-cljs-edn [fileset ids]
+(defn- relevant-cljs-edn [fileset ids]
   (let [relevant  (map #(str % ".cljs.edn") ids)
         f         (if ids
                     #(b/by-path relevant %)


use keyword for ids

use keyword for ids

--- src-cljc/tourney_nerd/teams.cljc
+++ src-cljc/tourney_nerd/teams.cljc
@@ -54,7 +54,8 @@
                                      :name (str "Team " (inc idx))
                                      :seed (inc idx)}))
                      (range 0 num-teams))]
-    (zipmap (map :id teams-list) teams-list)))
+    (zipmap (map #(-> % :id keyword) teams-list)
+            teams-list)))

 (defn reset-team
   "Resets the values of a Team for a new Event."


constraints on VPs: complement must not be a pronoun to avoid over generation e.g. *"loro alzeranno si"

--- src/babel/italiano/grammar.cljc
+++ src/babel/italiano/grammar.cljc
@@ -154,6 +154,9 @@
 ;; </TODO: move to ug>
 ;; -- END SCHEMA DEFINITIONS

+(def vp-non-pronoun
+  {:comp {:synsem {:pronoun false}}})
+
 (def grammar (list (unifyc h21
                            {:rule "adjective-phrase"
                             :synsem {:cat :adjective}})
@@ -300,6 +303,7 @@
                    ;; Note use of :reflexive below.
                    (unifyc h22
                            root-is-comp
+                           vp-non-pronoun
                            (let [obj-agr (atom :top)]
                              {:head {:phrasal false}
                               :rule "vp-aux-22"
@@ -316,26 +320,34 @@
                            {:rule "vp-future"
                             :synsem {:aux false
                                      :infl :future
-                                     :cat :verb}})
+                                     :cat :verb}}
+                           vp-non-pronoun)
+
                    (unifyc h21
                            root-is-head
                            {:rule "vp-imperfect"
                             :synsem {:aux false
                                      :infl :imperfect
-                                     :cat :verb}})
+                                     :cat :verb}}
+                           vp-non-pronoun)
+
                    (unifyc h21
                            root-is-head
                            {:rule "vp-past"
                             :synsem {:aux false
                                      :infl :past
-                                     :cat :verb}})
+                                     :cat :verb}}
+                           vp-non-pronoun)
+
                    (unifyc h21
                            root-is-head
                            {:rule "vp-present"
                             :synsem {:aux false
                                      :infl :present
                                      :sem {:tense :present}
-                                     :cat :verb}})
+                                     :cat :verb}}
+                           vp-non-pronoun)
+
                    (unifyc c21
                            root-is-head-root
                            {:head {:phrasal true}


re-enable article-less casa

re-enable article-less casa

--- src/babel/italiano/lexicon.cljc
+++ src/babel/italiano/lexicon.cljc
@@ -550,12 +550,12 @@
                            :place true}}})

     ;; in the sense of "a casa": no article needed.
-;    {:synsem {:cat :noun
-;              :sem {:city false
-;                    :place true
-;                    :animate false
-;                    :pred :casa}
-;              :subcat '()}}
+    {:synsem {:cat :noun
+              :sem {:city false
+                    :place true
+                    :animate false
+                    :pred :casa}
+              :subcat '()}}
     ]

     "cattivo"


+lexical constraints on {:cat :adverb}

+lexical constraints on {:cat :adverb}

--- src/babel/italiano/lexicon.cljc
+++ src/babel/italiano/lexicon.cljc
@@ -373,14 +373,24 @@
                                          :2 '()}}}}}))
       ;; </adjective default rules>

-      ;; <adverb default rules>
+      ;; <sent-modifier default rules>
       (default
        (let [sentential-sem (atom :top)]
          {:synsem {:cat :sent-modifier
                    :sem {:subj sentential-sem}
                    :subcat {:1 {:sem sentential-sem}}}}))
+      ;; </sent-modifier default rules>
+
+      ;; <adverb default rules>
+      (default
+       (let [verb-sem (atom :top)]
+         {:synsem {:cat :adverb
+                   :sem verb-sem
+                   :subcat {:1 {:cat :verb
+                                :sem verb-sem}
+                            :2 '()}}}))
       ;; </adverb default rules>
-
+
       ;; <determiner default rules>
       (default
        (let [def (atom :top)]


added diventare

added diventare

--- src/babel/italiano/lexicon.cljc
+++ src/babel/italiano/lexicon.cljc
@@ -898,6 +898,13 @@
              (unify shared-part-of-dire
                     {:synsem {:sem {:pred :tell}}})])

+      "andare"
+
+      "diventare" {:italiano {:italiano "diventare"
+                :essere true
+                {:synsem {:cat :verb
+                          :sem {:pred :become}}}
+
       "divertirsi" (let [subject-semantics (atom {:human true})
                          subject-agr (atom :top)]
                      {:synsem {:cat :verb


Style searchbutton with bg color.

Style searchbutton with bg color.

--- src/beebster_clj/views.clj
+++ src/beebster_clj/views.clj
@@ -54,7 +54,7 @@
       [:p "Enter Search term:"]
       [:input.form-control {:type "text" :name "searchvalue" }]]
      [:div.sbut
-      [:input {:type "submit" :value "Search" :class "btn btn-default"}]]]]))
+      [:input {:type "submit" :value "Search" :class "searchbutton"}]]]]))

 (defn about-page
   []
@@ -103,6 +103,8 @@
             [:div.imgtitle
              (str desc)]]]])]))))

+
+
 (defn category-page
   [category]
   (html


add essere + PP

add essere + PP

--- src/babel/italiano/lexicon.cljc
+++ src/babel/italiano/lexicon.cljc
@@ -1047,20 +1047,23 @@
          ;; essere: prepositional phrase
          (let [gender (atom :top)
                number (atom :top)
-               obj (atom {:pred :top})]
+               obj (atom {:pred :top})
+               pred (atom :top)]
            (unify
             essere-common
             {:notes "essere-prepositional-phrase"
              :synsem {:cat :verb
                       :aux false
-                      :sem {:pred :top
-                            :subj :top
+                      :sem {:pred pred
                             :obj obj}
+                      ;; TODO: should not need agreement: should be covered by
+                      ;; essere-common.
                       :subcat {:1 {:cat :noun
                                    :agr {:gender gender
                                          :number number}}
                                :2 {:cat :prep
-                                   :sem obj}
+                                   :sem {:pred pred
+                                         :obj obj}}
                                :3 '()}}}))

          ;; TODO: do we need this? maybe remove?


Clean up with new param? predicate.

Clean up with new param? predicate.

--- src/afterglow/effects/params.clj
+++ src/afterglow/effects/params.clj
@@ -97,6 +97,11 @@
   ([value type-expected name]
    `(when (some? ~value) (check-type ~value ~type-expected ~name))))

+(defn param?
+  "Checks whether the argument is an [[IParam]]."
+  [arg]
+  (satisfies? IParam arg))
+
 (defn head-param?
   "Checks whether the argument is an [[IParam]] which also
   satisfies [[IHeadParam]]."
@@ -181,7 +186,7 @@
   (validate-param-type default type)
   (let [key (keyword variable)
         current (get @(:variables *show*) key)]
-    (if (and (some? current) (satisfies? IParam current))
+    (if (and (some? current) (param? current))
       ;; Found a parameter at the named variable, try to bind now.
       (do (validate-param-type current type key)
           current)  ; Binding succeeded; return underlying parameter
@@ -260,7 +265,7 @@
   (let [min (bind-keyword-param min Number 0)
         max (bind-keyword-param max Number 255)
         metronome (bind-keyword-param metronome Metronome (:metronome *show*))]
-    (if-not (some (partial satisfies? IParam) [min max metronome])
+    (if (not-any? param? [min max metronome])
       ;; Optimize the simple case of all constant parameters
       (let [range (- max min)
             dyn (boolean frame-dynamic)
@@ -452,7 +457,7 @@
         adjust-hue (bind-keyword-param adjust-hue Number 0)
         adjust-saturation (bind-keyword-param adjust-saturation Number 0)
         adjust-lightness (bind-keyword-param adjust-lightness Number 0)]
-    (if-not (some (partial satisfies? IParam) [c r g b h s l adjust-hue adjust-saturation adjust-lightness])
+    (if (not-any? param? [c r g b h s l adjust-hue adjust-saturation adjust-lightness])
       ;; Optimize the degenerate case of all constant parameters
       (let [result-color (atom c)]
         (if (seq (filter identity [r g b]))
@@ -563,7 +568,7 @@
   (let [x (bind-keyword-param x Number 0)
         y (bind-keyword-param y Number 0)
         z (bind-keyword-param z Number 1)]
-    (if-not (some (partial satisfies? IParam) [x y z])
+    (if (not-any? param? [x y z])
       ;; Optimize the degenerate case of all constant parameters
       (Vector3d. x y z)
       ;; Handle the general case of some dynamic parameters
@@ -644,7 +649,7 @@
   {:pre [(some? *show*)]}
   (let [pan (bind-keyword-param pan Number 0)
         tilt (bind-keyword-param tilt Number 0)]
-    (if-not (some (partial satisfies? IParam) [pan tilt])
+    (if (not-any? param? [pan tilt])
       ;; Optimize the degenerate case of all constant parameters
       (vector-from-pan-tilt (make-radians pan radians) (make-radians tilt radians))
       ;; Handle the general case of some dynamic parameters
@@ -703,7 +708,7 @@
   {:pre [(some? *show*)]}
   (let [pan (bind-keyword-param pan Number 0)
         tilt (bind-keyword-param tilt Number 0)]
-    (if-not (some (partial satisfies? IParam) [pan tilt])
+    (if (not-any? param? [pan tilt])
       ;; Optimize the degenerate case of all constant parameters
       (Vector2d. (make-radians pan radians) (make-radians tilt radians))
       ;; Handle the general case of some dynamic parameters
@@ -752,7 +757,7 @@
   (let [x (bind-keyword-param x Number 0)
         y (bind-keyword-param y Number 0)
         z (bind-keyword-param z Number 2)]
-    (if-not (some (partial satisfies? IParam) [x y z])
+    (if (not-any? param? [x y z])
       ;; Optimize the degenerate case of all constant parameters
       (Point3d. x y z)
       ;; Handle the general case of some dynamic parameters
@@ -799,7 +804,7 @@
   now, for fast lookup as each DMX frame is rendered. If scaling is
   requested, scale the results so they fall in the specified range."
   [results scaling start target-range]
-  (if-not (some (partial satisfies? IParam) (vals results))
+  (if (not-any? param? (vals results))
     ;; Optimize the case of all constant results
     (let [precalculated (if scaling
                           (let [smallest (apply min (vals results))


Slope one algoritham..

Slope one algoritham..

Helper function in case if the map (formatted data) is nested.

--- src/blog/routes/helper.clj
+++ src/blog/routes/helper.clj
@@ -106,6 +106,15 @@
              (assoc! m k (f k v)))
            (transient m) m)))

+(defn map-nested-vals
+  "applyed map-vals for sublevel fo map, nested map in this case"
+  [f m]
+  (map-vals
+   (fn [k1 inner-map]
+     (map-vals
+      (fn [k2 val] (f [k1 k2] val)) inner-map)) m))
+
+

 (defn social-button
   "Rendering social buttons for footer, for better maintenace"


Improved code style on cats.monad.either namespace source.

- Rename proto/ to p/ namespace alias.
- Fix indentation issues.

--- src/cats/monad/either.cljc
+++ src/cats/monad/either.cljc
@@ -37,7 +37,7 @@
       (either/left 1)
       ;; => #<Left [1]>
   "
-  (:require [cats.protocols :as proto]))
+  (:require [cats.protocols :as p]))

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Type constructor and functions
@@ -46,10 +46,10 @@
 (declare either-monad)

 (deftype Right [v]
-  proto/Context
+  p/Context
   (get-context [_] either-monad)

-  proto/Extract
+  p/Extract
   (extract [_] v)

   #?(:clj clojure.lang.IDeref
@@ -67,17 +67,17 @@
          (with-out-str (print [v])))])

   #?@(:cljs
-       [cljs.core/IEquiv
-        (-equiv [_ other]
-                (if (instance? Right other)
-                  (= v (.-v other))
-                  false))]))
+      [cljs.core/IEquiv
+       (-equiv [_ other]
+         (if (instance? Right other)
+           (= v (.-v other))
+           false))]))

 (deftype Left [v]
-  proto/Context
+  p/Context
   (get-context [_] either-monad)

-  proto/Extract
+  p/Extract
   (extract [_] v)

   #?(:clj clojure.lang.IDeref
@@ -95,11 +95,11 @@
          (with-out-str (print [v])))])

   #?@(:cljs
-       [cljs.core/IEquiv
-        (-equiv [_ other]
-                (if (instance? Left other)
-                  (= v (.-v other))
-                  false))]))
+      [cljs.core/IEquiv
+       (-equiv [_ other]
+         (if (instance? Left other)
+           (= v (.-v other))
+           false))]))

 (alter-meta! #'->Right assoc :private true)
 (alter-meta! #'->Left assoc :private true)
@@ -130,8 +130,8 @@
   "Return true in case of `v` is instance
   of Either monad."
   [v]
-  (if (satisfies? proto/Context v)
-    (identical? (proto/get-context v) either-monad)
+  (if (satisfies? p/Context v)
+    (identical? (p/get-context v) either-monad)
     false))

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -141,22 +141,22 @@
 (def ^{:no-doc true}
   either-monad
   (reify
-    proto/Functor
+    p/Functor
     (fmap [_ f s]
       (if (right? s)
         (right (f (.-v s)))
         s))

-    proto/Applicative
+    p/Applicative
     (pure [_ v]
       (right v))

     (fapply [m af av]
       (if (right? af)
-        (proto/fmap m (.-v af) av)
+        (p/fmap m (.-v af) av)
         af))

-    proto/Monad
+    p/Monad
     (mreturn [_ v]
       (right v))

@@ -165,15 +165,15 @@
         (f (.-v s))
         s))

-    proto/Foldable
+    p/Foldable
     (foldl [_ f z mv]
       (if (right? mv)
-        (f z (proto/extract mv))
+        (f z (p/extract mv))
         z))

     (foldr [_ f z mv]
       (if (right? mv)
-        (f (proto/extract mv) z)
+        (f (p/extract mv) z)
         z))))

@@ -185,19 +185,19 @@
   "The Either transformer constructor."
   [inner-monad]
   (reify
-    proto/Monad
+    p/Monad
     (mreturn [_ v]
-      (proto/mreturn inner-monad (right v)))
+      (p/mreturn inner-monad (right v)))

     (mbind [_ mv f]
-      (proto/mbind inner-monad
-                   mv
-                   (fn [either-v]
-                     (if (left? either-v)
-                       (proto/mreturn inner-monad either-v)
-                       (f (proto/extract either-v))))))
-
-    proto/MonadTrans
+      (p/mbind inner-monad
+               mv
+               (fn [either-v]
+                 (if (left? either-v)
+                   (p/mreturn inner-monad either-v)
+                   (f (p/extract either-v))))))
+
+    p/MonadTrans
     (base [_]
       either-monad)

@@ -205,10 +205,10 @@
       inner-monad)

     (lift [m mv]
-      (proto/mbind inner-monad
-                   mv
-                   (fn [v]
-                     (proto/mreturn inner-monad (right v)))))))
+      (p/mbind inner-monad
+               mv
+               (fn [v]
+                 (p/mreturn inner-monad (right v)))))))

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Utility functions
@@ -221,8 +221,8 @@
   [e lf rf]
   {:pre [(either? e)]}
   (if (left? e)
-    (lf (proto/extract e))
-    (rf (proto/extract e))))
+    (lf (p/extract e))
+    (rf (p/extract e))))

 (defn branch-left
   "Given an either value and a function, if the either is a
@@ -241,7 +241,7 @@
   [e rf]
   {:pre [(either? e)]}
   (let [context either-monad]
-    (proto/mbind context e rf)))
+    (p/mbind context e rf)))

 (def lefts
   "Given a collection of eithers, return only the values that are left."
@@ -264,5 +264,5 @@
   [e]
   {:pre [(either? e)]}
   (if (left? e)
-    (right (proto/extract e))
-    (left (proto/extract e))))
+    (right (p/extract e))
+    (left (p/extract e))))


Only password protect the merits, leaderboard is fine.

--- src/clj/made_merits/handler.clj
+++ src/clj/made_merits/handler.clj
@@ -21,7 +21,6 @@
   (routes
     (-> #'merits-routes
         (wrap-routes middleware/wrap-csrf)
-        (wrap-basic-authentication authenticated?)
         (wrap-routes middleware/wrap-formats))
     (-> #'leaderboard-routes
         (wrap-basic-authentication authenticated?)


Dump game logic from client

Dump game logic from client

--- src/cljs/puertorico/client.cljs
+++ src/cljs/puertorico/client.cljs
@@ -25,133 +25,12 @@
 (defn vp [text]
   [:span.vp text])

-(def common-state
-  {:roles (set (keys common/role-descriptions))
-   :buildings common/initial-buildings
-   :trader []
-   :governor 0
-   :turns '()
-   :log []
-   :quarry 8
-   :fields {:coffee 8 :tobacco 9 :corn 10 :sugar 11 :indigo 12}})
-
-(defn bank-buildings []
-  (into {}
-        (for [[bname bdesc] common/initial-buildings]
-          [bname (select-keys bdesc [:vp :count :cost :column])])))
-
-(swap! estream conj
-       [:good :bank :coffee 9]
-       [:good :bank :tobacco 9]
-       [:good :bank :corn 10]
-       [:good :bank :sugar 11]
-       [:good :bank :indigo 11]
-
-       [:field :bank :quarry 8]
-       [:field :bank :coffee 8]
-       [:field :bank :tobacco 9]
-       [:field :bank :corn 10]
-       [:field :bank :sugar 11]
-       [:field :bank :indigo 12]
-
-       [:building :bank (bank-buildings)]
-
-       )
-
 (defn next-player [current-picker sstate]
   (mod (inc current-picker) (:nplayers sstate)))
-
-(defmulti transition identity)
-(defmethod transition :good [etype state [dest good-type amount]]
-  (update-in state [dest etype good-type] + amount))
-(defmethod transition :field [etype state [dest good-type amount]]
-  (update-in state [dest etype good-type] + amount))
-(defmethod transition :worker [etype state [dest amount]]
-  (update-in state [dest etype] + amount))
-(defmethod transition :vp [etype state [dest amount]]
-  (update-in state [dest etype] + amount))
-(defmethod transition :gold [etype state [dest amount]]
-  (update-in state [dest etype] + amount))
-(defmethod transition :building [etype state [dest buildings]]
-  (assoc-in state [dest :building] buildings))
-(defmethod transition :add-player [etype state [pname]]
-  (-> state
-      (update-in [:order] conj pname)
-      (update-in [:nplayers] inc)
-      (assoc-in [pname] {:name pname :worker 0 :gold 0 :vp 0 :field {} :building {}})))
-
-(defmethod transition :rolepick [etype state [role]]
-  (-> state
-      (assoc-in [((:order state) (:role-picker state)) :role] role)
-      (assoc :current-role role)))
-
-(defmethod transition :actiondone [etype state]
-  (update-in state [:action-picker] next-player state))
-
-(defmethod transition :default [etype state]
-  state)
-
-
-(defn calc-state []
-  (let [estream @estream]
-    (reduce
-      (fn [acc [etype & eargs]]
-        (transition etype acc eargs))
-      {:order []
-       :nplayers 0
-       :governor 0
-       :role-picker 0
-       :current-role nil
-       :action-picker 0
-       :bank {:vp 0
-              :field-count 0
-              :building nil}}
-        estream)))

 (defn get-players [state]
   (into {}
         (remove (fn [[k v]] (keyword? k)) state)))
-
-(defn create-game
-  ([p1 p2 p3]
-   (swap! estream conj
-          [:vp :bank 75]
-          [:worker :bank 55]
-
-          [:worker :worker-ship 3]
-          [:worker :bank -3]
-
-          [:ship 0 4]
-          [:ship 1 5]
-          [:ship 2 6]
-
-          [:add-player p1]
-          [:gold p1 2]
-          [:field p1 :indigo 1]
-
-          [:add-player p2]
-          [:gold p2 2]
-          [:field p2 :indigo 1]
-
-          [:add-player p3]
-          [:gold p3 1]
-          [:field p3 :corn 1]
-          )
-
-   (merge common-state
-          {})))
-
-(def game (atom (apply create-game ["Kanwei" "Lauren" "Ted"])))
-
-(defn randomize-fields [state]
-  (->> (for [[field-type field-num] (:fields @game)]
-         (repeat field-num field-type))
-       flatten
-       shuffle
-       (take (inc (:n-player @game)))
-       vec))
-
-(swap! game update-in [:available-fields] randomize-fields)

 ;;;;;;;;;;;;;;;;;;;;;
@@ -311,14 +190,9 @@
      [:div.col-md-3
       (player-board player)])])

-(defn game-log []
-  [:div
-   (for [event (:log @game)]
-     [:div (pr-str event)])])
-
 (defn render-roles [sstate]
   [:div
-   (for [role (:roles @game)]
+   (for [role (keys common/role-descriptions)]
      [:button.btn.btn-default.rolecard {:on-click #(player-pick-role role sstate)}
       (name role)
       [:span " - " (role common/role-descriptions)]])])
@@ -366,7 +240,6 @@

       (player-boards sstate)

-      (game-log)
       (game-state)

       ]))


fix getting the client ip when behind a load balancer

--- src/clojure_web_app/handler.clj
+++ src/clojure_web_app/handler.clj
@@ -15,7 +15,7 @@
             [environ.core :refer [env]]
             [ring.middleware.defaults :refer [wrap-defaults site-defaults]]))

-(def production (or (env :production) false))
+(def production true)

 (defn location-by-ip [ip]
   (json/read-str ((client/get (format "http://freegeoip.net/json/%s" ip)) :body) :key-fn keyword))


Fixed.

Fixed.

--- src/clojurefx/controllergen.clj
+++ src/clojurefx/controllergen.clj
@@ -164,7 +164,7 @@

 (defn gen-fx-controller [fxmlzip fxmlpath [clj-ns clj-fn] [pkg classname]]
   (let [fxid-elems (get-fxid-elems fxmlzip)
-        handler-fns (get-handler-fns fxmlzip)
+        handler-fns (get-handler-fns fxmlzip)
         import-classes (build-imports fxmlpath)
         inited-class (init-class pkg classname import-classes)
         propped-class (gen-props inited-class fxid-elems import-classes)
@@ -172,8 +172,6 @@
         handled-class (gen-handlers initializer-class handler-fns clj-ns)]
     (debug (pr-str handler-fns))
     (.visitEnd handled-class)
-    (with-open [out (io/output-stream (io/file "/home/zilti/Test.class"))]
-      (.write out (.toByteArray handled-class)))
     (.toByteArray handled-class)))

 ;; ;; Plumber


Minor cleanup

Minor cleanup

--- src/com/akr/ez_patcher/core.clj
+++ src/com/akr/ez_patcher/core.clj
@@ -16,8 +16,6 @@
  :name com.pro.akr.ezPatcher.Comparator
  :methods [[isSame [Object] Boolean]])

-
-(defn is-class? [x] (instance? (class x) Class))

 (defn param-type [x]
   (cond


Set the EC2 instance timeout to sane values.

--- src/circle/backend/ec2.clj
+++ src/circle/backend/ec2.clj
@@ -277,8 +277,9 @@

 (defn block-until-running
   "Blocks until AWS claims the instance is running"
-  [instance-id & {:keys [timeout]
-                  :or {timeout 600}}]
+  [instance-id & {:keys [timeout sleep-interval]
+                  :or {timeout 30
+                       sleep-interval 10}}]
     (infof "block-until-running: waiting for instance %s to start" instance-id)
   (loop [timeout timeout]
     (let [inst (try
@@ -290,8 +291,7 @@
                    (when (not= "InvalidInstanceID.NotFound" (.getErrorCode e))
                      (throw e))))
           state (-?> inst :state :name (keyword))
-          ip (-> inst :publicIpAddress)
-          sleep-interval 5]
+          ip (-> inst :publicIpAddress)]
       (infof "block-until-running: %s %s" instance-id state)
       (cond
        (= state :running) true


day 21 refactor win?

day 21 refactor win?

--- src/adventofcode/day21.clj
+++ src/adventofcode/day21.clj
@@ -29,15 +29,8 @@
                    {:name "defence +3" :cost 80  :damage 0 :armor 3}]})

 (defn win? [me boss]
-  (let [my-damage (max 1 (- (:damage me) (:armor boss)))
-        boss-damage (max 1 (- (:damage boss) (:armor me)))]
-    (loop [my-hp (:hp me)
-           boss-hp (:hp boss)]
-      (if (>= 0 (- boss-hp my-damage))
-        true
-        (if (>= 0 (- my-hp boss-damage))
-          false
-          (recur (- my-hp boss-damage) (- boss-hp my-damage)))))))
+  (<= (inc (Math/floor (/ (:hp boss) (max 1 (- (:damage me) (:armor boss))))))
+      (Math/ceil (/ (:hp me) (max 1 (- (:damage boss) (:armor me)))))))

 (defn apply-items [items]
   (reduce #(-> %1


Replace task wrap macros with middleware function

--- src/adzerk/boot_reload.clj
+++ src/adzerk/boot_reload.clj
@@ -106,16 +106,16 @@
                                  :open-file open-file})]
     (set-env! :source-paths #(conj % (.getPath src)))
     (write-cljs! out url on-jsload)
-    (comp
-      (with-pre-wrap fileset
+    (fn [next-task]
+      (fn [fileset]
         (doseq [f (relevant-cljs-edn fileset ids)]
           (let [path     (tmp-path f)
                 in-file  (tmp-file f)
                 out-file (io/file tmp path)]
             (add-init! in-file out-file)))
-        (-> fileset (add-resource tmp) commit!))
-      (with-post-wrap fileset
-        (send-changed! @pod asset-path (changed @prev fileset))
-        (doseq [f (relevant-cljs-edn fileset ids)]
-          (send-visual! @pod (:adzerk.boot-cljs/messages f)))
-        (reset! prev fileset)))))
+        (let [fileset (-> fileset (add-resource tmp) commit!)
+              fileset (next-task fileset)]
+          (send-changed! @pod asset-path (changed @prev fileset))
+          (doseq [f (relevant-cljs-edn fileset ids)]
+            (send-visual! @pod (:adzerk.boot-cljs/messages f)))
+          (reset! prev fileset))))))