четверг, 23 февраля 2017 г.

netstat analog for mac os


lsof -iUDP

lsof -i4 -sTCP:LISTEN

lsof -i6 -sTCP:LISTEN

вторник, 21 февраля 2017 г.

clojure.spec for any namespace on the fly

(create-ns 'com.mycompany)
(alias 'a 'com.mycompany)
(s/def ::a/keyword keyword?)
(s/exercise ::a/keyword)

четверг, 9 февраля 2017 г.

java Date to LocalDate

(defn inst2local-date
  "convert java.util.Date to java.time.LocalDate"  [^Date date]
  (-> date .toInstant (.atZone (ZoneId/systemDefault)) .toLocalDate))

четверг, 2 февраля 2017 г.

Joda to LocalDate in Clojure

(def joda-local-date (t/local-date-time year month day))
(-> joda-local-date tc/to-long Instant/ofEpochMilli (.atZone (ZoneId/systemDefault)) .toLocalDate)

воскресенье, 29 января 2017 г.

clojurescript + reagent = track mouse example

Here is pretty simple example of mouse tracking app

(ns hello-world-cljs.core
  (:require [reagent.core :as r]))

(println "Hello App is started!")
(defonce app-state (r/atom {:mouse-trac? false :pointer {:x 0 :y 0}}))
(defn mouse-coords [e] {:x (.-pageX e) :y (.-pageY e)})
(defn mouse-handler [e] (swap! app-state assoc-in [:pointer] (mouse-coords e)))
(defn start-mouse-listen [handler] (js/document.addEventListener "mousemove" handler))
(defn stop-mouse-listen [handler] (js/document.removeEventListener "mousemove" handler))

(defn trac-mouse-button []
  [:div   [:button {:type "button" :class "btn btn-default" :on-click (fn [e] (swap! app-state update-in [:mouse-trac?] not))}
    "Mouse track?"]])

(defn trac-button-state-label [] [:div [:label (str (:mouse-trac? @app-state))]])

(defn mouse-coords-label [] [:div [:label (str "Pointer moved to: " (str (:pointer @app-state)))]])

(defn mouse-changer
  "this fn called every time when state of :mouse-trac? is changed"  []
  [:div   (if (:mouse-trac? @app-state)
     (start-mouse-listen mouse-handler)
     (stop-mouse-listen mouse-handler))])

(defn app-hello [] [:div [trac-mouse-button] [trac-button-state-label] [mouse-coords-label] [mouse-changer]])

(r/render-component [app-hello]
                    (.getElementById js/document "app"))

Here is result:

понедельник, 12 декабря 2016 г.

transfer via netcat slowly

cat book.txt | pv -L 100k | nc -l 3005

вторник, 6 декабря 2016 г.

clojure milliseconds to date or time

(.toLocalDate (.atZone (Instant/ofEpochMilli 1481042602526) (ZoneId/systemDefault)))

(.toLocalTime (.atZone (Instant/ofEpochMilli 1481042602526) (ZoneId/systemDefault)))