This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-01
Channels
- # aleph (7)
- # bangalore-clj (1)
- # beginners (89)
- # boot (5)
- # clara (21)
- # cljs-dev (2)
- # cljsrn (57)
- # clojure (58)
- # clojure-austin (1)
- # clojure-conj (1)
- # clojure-italy (5)
- # clojure-losangeles (3)
- # clojure-russia (4)
- # clojure-sanfrancisco (4)
- # clojure-spec (31)
- # clojure-uk (67)
- # clojurebridge (4)
- # clojurescript (56)
- # cursive (92)
- # data-science (4)
- # datomic (15)
- # emacs (23)
- # events (1)
- # fulcro (121)
- # gorilla (2)
- # jobs-discuss (1)
- # juxt (1)
- # lambdaisland (6)
- # lumo (13)
- # off-topic (11)
- # om (1)
- # onyx (17)
- # overtone (5)
- # parinfer (9)
- # planck (3)
- # re-frame (21)
- # reagent (95)
- # ring-swagger (7)
- # spacemacs (58)
- # vim (13)
- # yada (2)
Is there anybody here that is familiar with the buddy auth library? I am trying to create access rules for some endpoints in my restful api, but I am having some troubles with regex matching
@noisesmith Finally got Netica running with lein by copying .dll
and .lib
files to C:\Windows\System32
. For some reason, the direct java
call we were using also stopped working, started giving the same error as the lein approach. (I did reboot with a BIOS update, but...) Clojure kept reporting No <file>.dll in java.library.path
, even when using the -XshowSettings:properties
option clearly showed java.library.path
was set to <file>.dll
's directory. Seems like it shouldn't be this hard. š
Anyway, I'm now happily bumbling through translating Netica's Java demo into Clojure. Question (for anyone):
How should I translate an expression like tuberculosis.setCPTable("visit", 0.05, 0.95)
, where tuberculosis
is a successfully created instance of type norsys.netica.Node
? I have tried...
edit-server.core> (.setCPTable tuberculosis '("visit", 0.05, 0.95))
ClassCastException clojure.lang.PersistentList cannot be cast to [F edit-server.core/eval10884 (form-init256107752130466048.clj:53)
I gather .setCPTable
is a method on Node
, and it seems like that part is working.
It looks like the error is about the list. Tried changing that to vector, got vector version of same error.
Thanks for any insight.Iām 99% sure that the right form for that is simpler: (.setCPTable tuberculosis "visit" 0.05 0.95)
Does anyone know how to get clojure.java.jdbc
to accept a string in the parameter value and cast it to postgres timestamp with time zone
?
So far I have this:
clojure
(extend-type java.lang.String
jdbc/ISQLParameter
(set-parameter [v ^java.sql.PreparedStatement stmt ^long idx]
(let [conn (.getConnection stmt)
meta (.getParameterMetaData stmt)
type-name (.getParameterTypeName meta idx)]
(prn type-name)
(prn stmt))
(.setObject stmt idx v)))
whenever the string parameter is meant for a timestamptz
column the type-name
variable will contain timestamptz
.
So I would need to do something like (if (= type-name "timestamptz") (.setObject stmt idx (str v "::timestamp with time zone")) (elseā¦)
But that doesnāt work
What do I replace (.setObject stmt idx v)
with so v is cast to timestamptz
For the time being I resorted to jusing datetimes from clj-time
.
well if youāre already using clj-time
donāt forget to require clj-time.jdbc
it wraps some of the protocols for JDBC timestamp interop
@chris_johnson Looks like I was wrong about the method definition being ok:
edit-server.core> (let [tuberculosis (norsys.netica.Node. "VisitAsia" "visit,no_visit" (norsys.netica.Net.))]
(.setCPTable tuberculosis "visit" 0.05 0.95))
IllegalArgumentException No matching method found: setCPTable for class norsys.netica.Node clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:53)
I see byte code for setCPTable
in Node.class
, in NeticaJ.jar
(and the Java demo I am trying to translate works). Am I missing something in the translation?@eggsyntax @chris_johnson - Thanks again. As predicted, I slept, went back to debugging, and found the answer in two minutes. And, of coures, it was not where I had guessed. The real problem was that I had somehow put a dependency on re-frame/trace into all my builds. Duh! I'm still fighting other issues now, but they look straightforward. Gotta love the power of sleep, at least in hindsight!
Hey, are there any data validation lib with just predicates? Example (v/email?) So that I can just use the predicates with Clojure spec when defining my types.
Not that Iāve seen, but in my experience itās not too bad to put them together on the fly. Although email, of course, can be a bit tricky š
I bet someoneās done a thorough job of that one ā Iād try searching for (s/def email
on one of the code search websites.
Couple of the latter from a quick search on CrossClj: https://crossclj.info/fun/schema-contrib.core/email%3F.html https://crossclj.info/fun/valip.predicates/email-address%3F.html
So, given a function like
(defn maybe-change [p val] (if p (assoc val :foo :bar) val))
The thing I want to achieve is that if the predicate is true, I do some changes to the value, otherwise I return it untouched, so to speak.
thatās exactly what cond->
is for
So, one thing that can be a bit of a trap, is that Clojure is so concise, you start to lose touch of what is unnecessary small, amd what just is. There's not a lot of languages where a simple if/else would be considered too small. But Clojure treats you so well you start to expect everything to be one function.
(cond-> {}
true (assoc :key :val))
Will return the map with :key :val associated on it. But cond-> is always thread first, and wouldn't work if assoc didn't take the map as first argument, you also have cond->> for things that take thw target data as the last argument. There is no cond-as->, so you can't mix and match with itThat said, I find cond-> a little confusing on the readability side, and your if/else approach isn't really any less concise, so I'd say it's just as fine a choice.
how to do with-redef for java instance methods ?
You proxy the instance where the methods you call are overridden with a mock implementation, then you pass in the proxied instance instead
How could I define global variable from this let loop (like atom?)
update (fn [comp]
(let [{:keys [smth]} (reagent/props comp)]
(reset! gchart smth)
))
When I reset! the atom.. nothing happens.. outside.. inside the loop I can read the value.
Frontend control flow always confuses me... The first time that prn
is called, update
will not have been executed, so I would expect it to be nil, yesno? But you're saying even after the update, when the function should have run, it still displays nil? Are you sure the function is actually being called?
Also why are you defining the gchart atom at the top in a def and then within the let as well?
Actually, surely that prn
only runs during first initialisation, so it would always be nil. On update the update function is called, but the inside of the let with the create-class etc is not re-called is it?
I know, that is a little bit difficult in first view therefore I shared in first time just a little part from this code.
and it would never be updated by line 15, because the component hasn't been mounted at that point (and thus update
hasn't been called)
No-no, both was useful.. just when @sundarj said.. I try to use the atom in the wrong place.. I got the āahaā moment.. true. š
I usually write my functions in order [most-general -> most-specific]
The dependencies usually also run in that order
e.g. [parse-response-item parse-item-priceā¦.]
I come from javascript where we have function hoisting
In clojure this causes an exception.
Should I use declare
all around
Or should I bite the bullet and reverse my ordering?