This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-05
Channels
- # announcements (13)
- # aws (1)
- # bangalore-clj (4)
- # beginners (66)
- # boot (11)
- # calva (27)
- # cider (27)
- # clj-kondo (76)
- # cljdoc (6)
- # cljs-dev (38)
- # clojars (3)
- # clojure (143)
- # clojure-dev (2)
- # clojure-europe (6)
- # clojure-greece (10)
- # clojure-italy (10)
- # clojure-nl (5)
- # clojure-norway (2)
- # clojure-sweden (1)
- # clojure-uk (19)
- # clojurescript (49)
- # cursive (13)
- # datomic (14)
- # duct (6)
- # figwheel-main (3)
- # fulcro (31)
- # funcool (7)
- # jobs (3)
- # keechma (142)
- # liberator (1)
- # off-topic (15)
- # om (2)
- # reagent (1)
- # reitit (2)
- # remote-jobs (1)
- # rewrite-clj (73)
- # shadow-cljs (21)
- # spacemacs (18)
- # sql (5)
- # tools-deps (10)
- # yada (1)
I have following composure-api code, is there any way to wrap CORS around routes with ring-cors lib?
@scalphunter How are you verifying that that behavior? ring-cors
only does anything for :options
requests. Everything else just passes through untouched I think.
If I hit one of our APIs with curl
I don't see CORS headers for regular requests. I only see CORS headers in a browser's dev tools when it sends OPTIONS ahead of an operation...
(admittedly, we're using plain Compojure with ring-cors
but I wouldn't expect compojure-api
to behave that differently)
I use postman , and it shows headers. but i coudn't see the headers from composure-api generated response.
See what you get by calling bean
on it @haiyuan.vinurs
Hmm, bean
can be called on a lot of Java objects. Can you share the code you tried?
I see snsapi and accessToken there. is this something that should be taken down and all access revoked from AWS?
I'm having issues with migratus, which are I think related to the jdbc library, Not sure if the connectoin data for the database is correct, but I'm getting
java.sql.SQLException: No suitable driver found for jdbc:
wihh the data
:db {:classname "org.postgresql.Driver"
:subprotocol "postgesql"
:subname "//localhost/parrot"
}
First off, don't use that form of map, use the modern, well-supported form
Second, put an r
in it.
@theeternalpulse {:dbtype "postgres" :dbname "parrot" ...}
There's no such database as postgesql
π
ah, I'll see about the modern form, the migratus seems to only have the type I posted as the data to use
If Migratus is passing the db-spec through to clojure.java.jdbc
, it totally doesn't care what's in it.
That classname/subprotocol/subname is horrible and error-prone. I wish people would stop using it π
That's why next.jdbc
does not support it!
does this look better
:db {:dbtype "postgresql"
:dbname "parrot"
:host "127.0.0.1"
:user "postgres"
:password "<real pw>"}
You can omit :host
-- it will default to localhost.
The :dbtype
can be "postgres"
if you prefer to use the short name.
still getting
SEVERE: Error creating DB connection for {:dbtype "postgresql", :dbname "parrot", :host "127.0.0.1", :user "postgres", :password "d<censored>"}
java.sql.SQLException: No suitable driver found for jdbc:
I'm using a docker istance of postgres if that matters
Then in that case you don't have the JDBC driver for PostgreSQL as a dependency in your project I expect.
ah, I was curious about if that was in the library itself or if I depend on i
let me add that
org.postgresql/postgresql {:mvn/version "42.2.2.jre7"}
(or similar)
The documentation says "You must specify the appropriate JDBC driver dependency in your project -- these drivers are not included with java.jdbc." @theeternalpulse
(and the next.jdbc
docs say "In addition, you will need to add dependencies for the JDBC drivers you wish to use for whatever databases you are using.")
yeah, my kickoff point was migratus, should have read through java.jdbc first
I just downloaded postgresql drive jar file and put it into resources-path. it automatically loads driver then.
btw, i solved issue of CORS, i just manually added headers. seems like my ring-cors wrapper doesn't work. I think i have to make my own middleware on this for my own study.
@scalphunter You should never need to download JAR files -- just put the dependencies in your project.clj
, build.boot
, or deps.edn
file.
he's referencing the different systems to load dependencies, lein,boot,and tools.deps. Not sure if there are other tools that are as popular as those though.
@U0VQ4N5EE project.clj if you use leiningen, build.boot if you use boot and deps.edn if you use tools deps.
thanks @U883WCP5Z
The ring-cors
wrapper works just fine. We use it heavily in production.
@seancorfield Yeah, you're right. ring-cors hides headers. I checked out and finally it works now. I missed regex in :access-control-allow-origin. Thanks!
(since there are lots more Java developers than Clojure developers)
Thereβs a reddit thread with discussion and some excellent thoughts (as always) from Alex Miller
Can you share link of reddit thread.
https://www.reddit.com/r/Clojure/comments/bvvnx0/storm_drops_clojure_for_java/
Any rewrite can take advantage of a lot of previous experience and knowledge.
https://www.reddit.com/r/Clojure/comments/bvvnx0/storm_drops_clojure_for_java/
how is if
implemented? having hard time to find it in source codeβ¦
its a special form recognized by the compiler.
special forms are generally implemented in the host language. eg Java, JS, C# etc
Source code for the JVM version is here: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java
thanks!
Or at least it starts there, Iβm still tracking it down myself.
π i understand you
Ah, thereβs the parser class, looks like itβs all in that same file, cool.
Iβve often wondered that myself but this is the first time Iβve actually tracked it down.
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L43
thanks!
The meat of it is in a class called IfExpr, defined farther down in that same file.
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L2710 yep, found thanks!
one interesting detail about clojure's if, is it doesn't use the value of false
but rather the canonical interned identity
in Java, you can create a new boolean of value false, and if recognizes it as a false value for dispatch
in Clojure, Boolean/FALSE is checked for identity, your own new false won't be identical, so will be treated as non-false (true)
(cmd)user=> (identical? Boolean/FALSE false)
true
(ins)user=> (identical? (Boolean. "FALSE") false)
false
(ins)user=> (if (Boolean. "FALSE") :OK :no)
:OK
(ins)user=> (= (Boolean. "FALSE") false)
true
riemann is written in clojure and can export to prometheus - probably not the simplest example, I haven't looked at the implementation myself
prometheus is a TCP connection right?
oh, even easier, it's http https://github.com/riemann/riemann/blob/0.3.3/src/riemann/prometheus.clj
there are no deps on other riemann namespaces in that code, which is a good sign for reusability / example purposes
I'd be slightly suspicious of what makers of an official java client for an http API consider "useful" :D
my graduate advisor name was rieman (but not the Riemann) and my last project name was prometheus.
it's important to clarify
I wouldn't trust someone who had a ghost as a graduate advisor for example
Regarding Γ prometheus exporter, basically it creates an API where the prometheus scrape from
So it doesn't push, looking at riemann example there. It might be that example use not usual conf
that's a host that code will push to - it's not getting pulls
Yep, imho afaik I need to build a server which respect the prometheus api of metrics, this will then scraped by prometheus
hi, anyone here use compojure-api
?
ahh, so the way riemann uses prometheus is abnormal then
i'm trying one of the basic examples and I get
Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/fn did not conform to spec.
#:clojure.spec.alpha{:problems ({:path [:fn-tail :arity-1 :params], :pred clojure.core/vector?, :val clojure.core.unify/var-unify, :via [:clojure.core.specs.alpha/params+body :clojure.core.specs.alpha/param-list :clojure.core.specs.alpha/param-list], :in [0]} {:path [:fn-tail :arity-n], :pred (clojure.core/fn [%] (clojure.core/or (clojure.core/nil? %) (clojure.core/sequential? %))), :val clojure.core.unify/var-unify, :via [:clojure.core.specs.alpha/params+body :clojure.core.specs.alpha/params+body], :in [0]}), :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x224b4d61 "clojure.spec.alpha$regex_spec_impl$reify__2509@224b4d61"], :value (clojure.core.unify/var-unify [G__1829 G__1830 G__1831 G__1832] (clojure.core/if-let [vb__1822__auto__ (G__1832 G__1830)] (clojure.core.unify/garner-unifiers G__1829 vb__1822__auto__ G__1831 G__1832) (clojure.core/if-let [vexpr__1823__auto__ (clojure.core/and (G__1829 G__1831) (G__1832 G__1831))] (clojure.core.unify/garner-unifiers G__1829 G__1830 vexpr__1823__auto__ G__1832) (if (clojure.core.unify/occurs? G__1829 G__1830 G__1831 G__1832) (throw (java.lang.IllegalStateException. (clojure.core/str "Cycle found in the path " G__1831))) (clojure.core.unify/bind-phase G__1832 G__1830 G__1831))))), :args (clojure.core.unify/var-unify [G__1829 G__1830 G__1831 G__1832] (clojure.core/if-let [vb__1822__auto__ (G__1832 G__1830)] (clojure.core.unify/garner-unifiers G__1829 vb__1822__auto__ G__1831 G__1832) (clojure.core/if-let [vexpr__1823__auto__ (clojure.core/and (G__1829 G__1831) (G__1832 G__1831))] (clojure.core.unify/garner-unifiers G__1829 G__1830 vexpr__1823__auto__ G__1832) (if (clojure.core.unify/occurs? G__1829 G__1830 G__1831 G__1832) (throw (java.lang.IllegalStateException. (clojure.core/str "Cycle found in the path " G__1831))) (clojure.core.unify/bind-phase G__1832 G__1830 G__1831)))))}
:thinking_face:@andrea.imparato that looks like your fn definition didn't have a vector arglist
@andrea.imparato feel free to ask in beginners channel.. And post you code
which is the beginners channel? π
#beginners
@darioszr going back to your original question - I linked riemann because I have a lot of respect for the author's code, but clearly it's not what you need - but there is a wrapper from the soundcloud company as well https://github.com/soundcloud/prometheus-clj
this one is likely worth checking out as well https://github.com/xsc/iapetos
Thx! the SoundCloud I saw it. The 2nd didn't know. Imho since the 1st SoundCloud is kind outdated, I was reflecting if it is worth perhaps to just pick the Java official one and then wrap it directly in my exporter
But I don't have much experience with Java but it could motivated me to a least try:grin:
you could use either of those as a template and use your own interop even - I doubt they are much different from one another under the hood
I learned java (to the extent I know it) via clojure interop - once you figure out how to read javadoc it's not so bad
as long as the API you are using doesn't mandate annotations and concrete inheritance, that's when things get kind of ugly
oh - javadoc is good enough that you shouldn't need to read the java code to do interop
and it's derived from the source, so even if docstrings are bad, args and arg types, and return values which is what really matters will be right
Hey Folks, I'm trying to generate some specs and write them to a file. When I pretty print them, they look like so...
(s/def
::addresses
(s/keys
:req-un
[:addresses/addressable-id
:addresses/addressable-type
:addresses/city
Is there any way I can convince the pretty-printer to get the ::addresses
to come out on the same line as the s/def
?yes, there are some tricks if you use the "code" modes of the pretty printer
let me find you a link to an example
this is dark arts :)
user=> (require '[clojure.spec.alpha :as s] '[clojure.pprint :as pp])
nil
(def c `(s/def
:user/addresses
(s/keys
:req-un
[:addresses/addressable-id
:addresses/addressable-type
:addresses/city])))
#'user/c
user=> (binding [pp/*code-table* (assoc @#'pp/*code-table* 'clojure.spec.alpha/def #'pp/pprint-hold-first)] (pp/with-pprint-dispatch pp/code-dispatch (pp/pprint c)))
(clojure.spec.alpha/def :user/addresses
(clojure.spec.alpha/keys
:req-un
[:addresses/addressable-id
:addresses/addressable-type
:addresses/city]))
not that here c is your code (as data) - it's important that you fully namespace the symbols (I'm using back tick to get that)
then you you want to pprint, with specialized dispatch, using the code-dispatch which already knows how to handle most clojure code, and extend the code-table to understand how to handle s/def
you can look at the pprint code to see more about the default code table and how things like pprint-hold-first are defined (which is, again, another dark arts subset of this dark art) :)
undoubtedly, but this is "in the box" with both clj and cljs
and this is an extensible system so you can do other customized things with your own macros or whatever
like you could tweak this to put the req keys next to the :req-un if you were determined enough (see pprint-let for something probably similar)
I've also heard about https://github.com/gnl/ghostwheel
We might add something like this in spec 2 (although itβs prob going to involve some other things that donβt exist yet)
I just tried nightcode. Seems cool but I do not see a way to reorganize code with the keyboard