воскресенье, 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]))

(enable-console-print!)
(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)))

воскресенье, 30 октября 2016 г.

enable automount for RHEL 7 and FreeIPA

  sudo ipa-client-automount --server=ipasrv01.mydomain.com
  sudo authconfig --enablemkhomedir --update

среда, 26 октября 2016 г.

clojure remote repl

In order to debug remote app we can start it with remote repl, if version of clojure 1.8+

java -Dclojure.server.repl="{:address \"0.0.0.0\" :port 5555 :accept clojure.core.server/repl}" -jar mywebapp.jar

вторник, 25 октября 2016 г.

Kerberos SPNEGO Checksum failed problem

I made SPNEGO authentication for my web apps. During development I met a problem authenticating users using keytab file for HTTP services:

Caused by: org.ietf.jgss.GSSException: Failure unspecified at GSS-API level (Mechanism level: Checksum failed)

I've found solution how to resolve a problem. I've used RHEL 7 on servers and clients, and FreeIPA as a KDC/LDAP server:

1. Open /etc/krb5.conf on web app server and add into section [libdefaults] one line

[libdefaults]
default_tkt_​enctypes = arcfour-hmac-md5

This is most important thing. This line resolves "Checksum failed" problem

2. On a client:
kinit username
Password for username@MYSERVICE.COM: 

after successful authentication in Kerberos domain we can access Kerberized web apps using curl:
curl -v -k --negotiate -u :  --cacert /etc/ipa/ca.crt  https://myservice.com:8090/krb

3. In FireFox, print about:config in address bar -> I promise -> then find
network.negotiate-auth.delegation-uris​     value     http://,https://
network.negotiate-auth.trusted-uris           value     .myservice.com​



вторник, 27 сентября 2016 г.

Clojure ClassCastException error

If error occured like this Caused by: java.lang.ClassCastException: bla.bla.bla cannot be cast to [Lbla.bla.bla it means that you need (into-array [bla.bla.bla]) or (into-array BlaClass [])