Fork me on GitHub
#clojure
<
2020-02-20
>
tstout01:02:46

When using clojure -Spom, is there a way to specify the version number generated for the project? It seems to be a constant of '0.1.0'.

alexmiller02:02:09

The whole idea is that if there is a pom, it updates in place. Just change it to whatever you want.

alexmiller02:02:49

Otherwise there would need to be 100 flags for every piece of data

alexmiller02:02:22

It only updates dependencies, repostories, and source paths

seancorfield02:02:09

@tstout In case it's helpful for the next project you create, if you use clj-new to create a (library) project, it generates a pom.xml that is "complete" and you can specify the initial version to use (and other things) via command-line arguments when you create the project: https://github.com/seancorfield/clj-new#the-generated-pomxml-file

4
seancorfield02:02:10

clojure -A:new lib tstout/myapp -e version=1.0.0 -e developer="Mr Stout"

seancorfield02:02:48

Produces

<groupId>tstout</groupId>
  <artifactId>myapp</artifactId>
  <version>1.0.0</version>
  <name>myapp</name>
  ...
  <developers>
    <developer>
      <name>Mr Stout</name>
    </developer>
  </developers>

tstout03:02:00

Thanks for the responses. My use case is invoking clojure -Spom and then depstar in a Dockerfile so that the manifest in the uberjar will have a version. My employer has a standard such that all services have an /about endpoint which responds with various useful bits of info, including the build version. I am attempting to get the build version from the uberjar manifest in order to properly respond to the /about request at runtime using the functionality of java.util.jar.Manifest. Perhaps there is an easier path to supply this information to the docker image.

seancorfield04:02:32

@tstout What I tend to do in such situations is to have the version in a file that is both part of the application itself and also used to build the application, so it would require some process to read the version file, modify the pom.xml, and then invoke depstar to build the uberjar.

seancorfield04:02:48

At work, we specifically bake in a git-related version: we use last tag + commits + SHA which we get with git describe --tags and our wrapper around invoking depstar runs that commands and then writes the value to the pom.xml and also to an EDN file in the resources of the app -- and then runs depstar.

seancorfield04:02:11

That way our apps can report their actual "build" version easily.

introom03:02:17

I have a lein question.

introom03:02:52

why in this file the profile :session-example is specified as a list instead of a map as in this line: https://github.com/funcool/buddy-auth/blob/ec454fecd3a84746c8e7b9e3af942cb1a692fdbd/profiles.clj#L16

hkupty06:02:10

Just wanted to share this for those (like me) who have to deal with protobuf from clojure, as it might be handy: https://gist.github.com/hkupty/783a89820fdc10d9a525cdf7cd2abac2 The one thing though I'd like is to avoid the runtime reflection, but I guess (from what I rad from protobuf's docs) that's probably not possible if class is not known beforehand...

amalantony09:02:17

How do I get access to the ring request object inside a Compojure API handler. My handler looks like this: (GET "/me" [] :summary "Get current User object" (user-handler)) Inside the user-handler function definition I want access to the Ring request object, so that I can read the user object from the session details. Thanks!

MC10:02:16

“request” is available in endpoint definitions via the request var, you can define your method as follows

(GET "/me" request (user-handler request))

👍 4
Henry10:02:28

How would I go about sorting by dates in different directions? for example - sorting by :start-time ascending and :end-time descending (using java-time). The solution I have right now is:

(compare [(:start-time thing-1) (:end-time thing-2)]
         [(:start-time thing-2) (:end-time thing-1)])

Henry10:02:13

but that doesn’t seem ideal

grounded_sage12:02:21

How do I set jvm-opts for a deps.edn project where it runs without using -O argument? I am using Calva so I can set a jackInEnv. However I want it to work for any environment.

Eamonn Sullivan12:02:54

Do deps.edn projects know to read the project-specific .jvmopts file, maybe?

dominicm12:02:44

You can't define jvm opts at the top level, you always need an alias loaded

delaguardo12:02:51

but you can wrap clj executable into your own script wich will try to detect local .jvmopts file or will use any other logic to get jvm options and run clj/clojure binary with a set of -J%java opt% arguments

pez12:02:58

Also: Calva has a setting named jackInEnv that can be used for setting JVM options. (EDIT: And now I read the OP more carefully... never mind me...)

dominicm12:02:04

Wrapping clj wouldn't make it work for everyone

delaguardo12:02:36

placing wrapper into preject-related bin directory should work for everyone

delaguardo12:02:09

but I agree that this feature could be implemented in clojure executable. It will be handy in many cases

dominicm12:02:16

But you would need to configure emacs, etc to look in there.

dominicm12:02:22

It's a lot of fiddling

dominicm12:02:03

I don't think activating an alias for development is that big of a deal.

grounded_sage13:02:59

Am I missing something?

{:deps {......}
 :aliases {:dev 
           {:jvm-opts ["-Djdk.attach.allowAttachSelf"]}}}

grounded_sage13:02:35

I’m looking for use this library https://github.com/clojure-goes-fast/clj-memory-meter. But also was wanting to experiment with heap size

grounded_sage13:02:14

Suddenly started working. Didn’t change anything lol

otfrom13:02:38

does anyone know of a good library for accessing google docs, specifically google sheets? I'd love to find something like docjure

otfrom13:02:50

I suppose what might be nice is something that hits the JSON http directly rather than wrapping the java, but idk

benoit15:02:16

I have been using the Java SDK and it works well (`com.google.apis/google-api-services-sheets`)

otfrom16:02:55

@U963A21SL cool. thx for the recommendation

Nico16:02:37

I want to write a parser for a simple text file format that's read line-by-line, so the parser really only has to parse a line and then put the data into datascript. The two main options I see for parsing are instaparse and using clojure.spec's conform to parse, which is the better option?

Nico16:02:36

or parser combinators like parsatron

seancorfield16:02:30

For parsing, use instaparse. Spec is not intended to be used for parsing.

borkdude16:02:31

instaparse is nice to get something quickly, but if you need to process loads of data, you might get into performance issues. spec is not designed to work with text, although you can get it working. don't expect superb performance. hand-rolling a parser is imo the best way long term

borkdude16:02:01

@nihilazo to see what I mean, check out this advent of code puzzle which I solved using 4 different parsers, including instaparse and spec: https://github.com/borkdude/aoc2017/blob/0f5bce5e496d65d0e53a8983e71ea3462aa0569c/src/day16.clj#L241-L244

8
borkdude16:02:40

of course it will depend on your specific domain and workload what makes sense

borkdude16:02:59

if you need to parse clojure-ish code, use tools.reader etc.

Nico16:02:24

what I'm parsing is a very simple text file format (that's also changable to make parsing easier, if I need to) so writing my own parser using string tools wouldn't be too difficult

Nico16:02:17

also, I'm storing a bunch of data (basically, a file name and the tags assocated with it, that I then filter by tags) and I'm thinking of using datascript to keep this data during runtime, but there might tens or hundreds of thousands of files. I don't want to use a database server, but is datascript up to that task or not?

borkdude16:02:50

is this server side or in the browser?

Nico16:02:10

this is a CLI application (which already is not ideal clojure territory, I know)

borkdude16:02:13

datahike might also be an option (#datahike).

borkdude16:02:35

@nihilazo Imo Clojure is very good for creating CLI applications.

borkdude16:02:15

or sqlite. just try it out, if it doesn't scale, try something else. 🙂

Nico16:02:19

main issue is startup time, although I'm looking into graal to try and help with that

borkdude16:02:39

@nihilazo fwiw I'm using transit in clj-kondo (also a CLI compiled with graalvm) to do a database-like thing for storing arities, etc. about clojure functions

borkdude16:02:48

it's not really a database, but it is a dataset

borkdude16:02:42

@nihilazo Another idea: you can write a script with babashka (fast startup while still having access to much of the JVM Clojure ecosystem) and access a sqlite database by shelling out: https://github.com/borkdude/babashka/blob/master/examples/sqlite.clj

Nico16:02:58

(sorry, I keep just saying thanks, but thanks)

Nico16:02:26

I'll try using datahike first, it seems like about what I need, and then I'll try sqlite if that doesn't work out

johnj16:02:43

golang is nice for CLIs.

Nico16:02:43

I was going to write this in rust, but I decided to stick with what I was familiar with (this is for a tool that me and maybe 4 other people might use, so it's not a massive deal)

borkdude17:02:56

@nihilazo This just got announced: https://github.com/wandersoncferreira/mamulengo in #announcements. Might also be interesting for you.

Guillermo Ithier21:02:18

Hello Clojurians, I'm having a problems getting access to a zero-token through a POST so that I can use it in my buffer to perform an authentication request. Now the URL here's the link ; following along a video 'Microservices with CLojure'.  I'm lost on how to use this site to create a way to well, access to a zero-token through a POST so that I can use it in my buffer to perform an authentication request. Here is the relevant functions that calls the outdated api: (defn auth0-token []
  (let [ret
        (client/post ""
                     {:debug false
                      :content-type :json
                      :form-params {:client_id (System/getenv "AUTH0_CLIENT_ID")
                                    :client_secret (System/getenv "AUTH0_SECRET")
                                    :grant_type "client_credentials"}})]
                                  (json/parse-string (ret :body))))
Can someone help me with this? Thank you in advance 🙂

seancorfield21:02:57

@guillermoithier Please don't cross-post the same question here as #beginners -- just be patient and wait for someone to respond.

mmeix21:02:07

Hi! Has someone a EBNF for XML, that I could just plug into Instaparse?

hiredman21:02:32

why not just use an xml parser?

mmeix22:02:24

just to try for learning; (what are the recommended xml parsers for Clojurescript?)

borkdude22:02:34

probably some JavaScript library?

borkdude22:02:26

maybe the browser already has what you need (if that's your target)? https://www.w3schools.com/xml/xml_parser.asp

mmeix22:02:44

ok, thanks

caio22:02:34

any tips on how to solve this reflection warning? > Reflection warning, /blabla/notification/ports/emailer.clj:79:7 - call to method withToAddresses on com.amazonaws.services.simpleemail.model.Destination can't be resolved (argument types: clojure.lang.IPersistentVector). the code that generates it:

(defn- ^Destination notification->destination
  [{::spec.notification/keys [^String destination]}]
  (-> (Destination.)
      (.withToAddresses [destination])))
and the method signature:
com.amazonaws.services.simpleemail.model.Destination/withToAddresses
 [this java.util.Collection]
 [this java.lang.String[]]
I tried annotating it with everything already :man-facepalming:

caio22:02:22

aha! nvm. I was trying to annotate the vector but TIL that it doesn't work. annotating a symbol and passing it to the method works

unbalanced23:02:12

I really like the thought process behind datafy/nav but I'm having trouble understanding the intuition behind the v argument of nav (i.e.,

(nav coll k v)
(nav coll k) I would understand, but I don't really understand the v. Is it just usually omitted in most case and it's just there if you need it?

unbalanced23:02:53

To put it another way, if I already have the value v, what do I need nav for?

seancorfield23:02:23

@goomba (nav coll k v) returns v in a lot of cases.

seancorfield23:02:44

But it is a consistent API for navigating from "data" to "things".

seancorfield23:02:51

For example, in next.jdbc (and the experimental datafy/`nav` support in clojure.java.jdbc), if you (nav row :foo_id 42) it will fetch the row from table foo that corresponds to id = 42 -- so it needs both k and v.

unbalanced23:02:14

ahh that makes sense

seancorfield23:02:15

(there's an optional schema behind next.jdbc that lets you override the default conventions)

seancorfield23:02:01

And in many cases, you'd end up calling (nav data nil v) because there's no index/key association for the v part of data (such as a sequence)

unbalanced23:02:44

Aha. So if there's no index/key association, we'd use nil for k. I would've thought v would be nil but I wasn't thinking about it in terms of index == value I was thinking in terms of (get coll k). That's an excellent explanation @seancorfield, much appreciated

seancorfield23:02:56

For others here thinking about datafy/`nav`, maybe this chapter of the next.jdbc docs helps https://cljdoc.org/d/seancorfield/next.jdbc/1.0.13/doc/datafy-nav-and-schema