Fork me on GitHub
#beginners
<
2019-07-03
>
jason poage00:07:13

i found this here but of course, i still cant get it to work. https://shadow-cljs.github.io/docs/UsersGuide.html#_access_cljs_from_js

Ian Fernandez01:07:21

hey guys, I'm new to spec instrumentation

Ian Fernandez01:07:58

I'm having this error:

:sym ..../position-gen,
  :failure #error {
 :cause nil
 :via
 [{:type java.lang.IndexOutOfBoundsException
   :message nil
   :at [clojure.lang.RT nthFrom "RT.java" 928]}]

Ian Fernandez01:07:10

for these:

(defn position-gen [len]
  (rand-nth (range (dec (or len 50)))))

(s/fdef position-gen
  :args (s/cat :len int?)
  :ret ::sc/length
  :fn  #(>= (% :args) (% :ret)))

Ian Fernandez01:07:22

mine s/fdef as "a too open definition"?

Alex Miller (Clojure team)01:07:25

your spec is not restrictive enough to accurately describe the valid inputs

Ian Fernandez01:07:11

(s/fdef position-gen
  :args (s/cat :len pos-int?)
  :ret nat-int?  
  :fn  #(>= (% :args) (% :ret)))
isn't restrictive too =<

Alex Miller (Clojure team)01:07:41

like what if len is -5 ?

Alex Miller (Clojure team)01:07:07

user=> (rand-nth (range -5))
Execution error (IndexOutOfBoundsException) at user/eval3 (REPL:1).

👍 4
clj 4
Ian Fernandez01:07:35

pos-int? / nat-int?

Ian Fernandez01:07:08

there's a way to pass a function that

s/fdef
has 0 arguments?

Alex Miller (Clojure team)01:07:30

usually :args (s/cat) is best

clj 4
Ian Fernandez01:07:22

i've not found that

Ian Fernandez01:07:11

(s/fdef position-gen
  :args (s/cat :len pos-int?)
  :ret nat-int?  
  :fn  #(>= (% :args) (% :ret)))
isn't restrictive too =<

okwori03:07:19

So am having issue starting lein. lein repl or lein --version or any...

seancorfield03:07:59

@simon What's in your .lein/profiles.clj file?

seancorfield03:07:11

Comment out the :plugins and :dependencies lines and see if that fixes your problem.

4
okwori04:07:34

Yeah, it does. Thanks. Btw, the issue started when I upgraded lein. Bumping up the deps all works...

seancorfield03:07:12

Also, does this happen just in a particular project directory, or also when there is no project.clj file present?

Casey11:07:52

i'm calling an api that returns a collection of results, but the response is paged, which means multiple calls to get the whole dataset. what's a good technique for processing the entire collection?

Casey11:07:28

lazy sequences seems like a trick-gimmick that would work, but lazy-sequences with side effects isn't a good idea

Casey11:07:48

i only want to fetch the pages i need, rather then fetch it all up front and then process it

otwieracz11:07:41

How do you know which pages you need?

Casey11:07:53

each record has a timestamp, and i process the records in descending order (by timestamp) until i encounter a record i've already seen (from a previous execution)

Casey11:07:05

the api doesn't let me filter out only the records i need

andy.fingerhut11:07:33

So if you had an API call that returned a lazy sequence (I am not yet saying I know that is possible and/or easy to do), you could do a take-while on it?

manutter5111:07:42

This actually sounds like one of the specific use cases that core.async was designed for. Create a blocking channel that can hold twice as many records as you get in a single API call, and then, inside a go loop, get a page of data and put it on the channel. If the channel is full, wait for it to have enough room before going to get the next page.

manutter5111:07:13

Caveat: I haven’t worked that much with core.async so I may not know all the gotchas, but I’m looking at the docs and it seems like this should be the “right” way to go.

Casey12:07:29

@manutter51 how does the producer know when to stop/exit cause the consumer is finished?

manutter5112:07:14

I would put the test for “I’ve seen this one already” inside the loop that makes the actual API calls. Once the “seen” record shows up again, just close the channel. I believe that there’s a way for the publish side of the channel to mark it as closed without losing the data that’s still in the buffer.

manutter5112:07:11

I don’t have code for how to do this (and I have to go afk for a bit), but that’s the direction I’d explore.

Casey12:07:27

interesting tips, thanks, i'll investigate

Alex Miller (Clojure team)12:07:32

don't use lazy sequences when you need control over an external source

Alex Miller (Clojure team)12:07:55

you probably also don't need core.async (and if you do use it, don't use a go loop for the IO - put that in a thread)

Alex Miller (Clojure team)12:07:31

or use pipeline-blocking

Alex Miller (Clojure team)12:07:55

but really, I'd probably just use a loop/recur for exercising the api

4
manutter5112:07:16

That’s good for me to know too.

Noah Bogart14:07:25

quick java-related question: when i run lein uberjar for a specific project, it'll produce the same jar file on my machine as it will on another machine, provided we both have the same versions of java, clojure, and lein installed, right?

ghadi14:07:23

but there are other factors that may make it unreproducible @nbtheduke

ghadi14:07:57

like stray files in the git repo, stale files in the AOT directory (target/classes I believe for lein)

Alex Miller (Clojure team)14:07:08

lein plugins / profiles

Noah Bogart14:07:24

I have an app deployed on a digital ocean box, and it sometimes runs out of space when i run lein uberjar, so i was thinking of running it locally and then scp-ing it over, but I don't wanna break things in the mean time if that's not gonna work

ghadi14:07:13

@nbtheduke if you can create the uberjar in the same conditions that it's usually created (profiles, versions, clean checkout) then it's probably fine

Noah Bogart14:07:19

cool, that's encouraging. I'll try it out! thanks

FiVo14:07:29

Hey, I am having issues with lein swank. My ~/.lein/profiles.clj looks as follows {:user {:plugins [[lein-swank "1.4.5"] ]}}.

FiVo14:07:27

When I use 1.9.0 everything works as expected, but with 1.10 I get Call to clojure.core/ns did not conform to spec..

FiVo14:07:03

Let me know if you want me to paste the whole stacktrace somewhere.

ghadi14:07:27

that's a super old dependency that probably has issues

ghadi14:07:55

you can set a JVM property to prevent spec macro checking

ghadi14:07:01

which is where it is failing

ghadi14:07:16

but I haven't even heard the word swank in 5 years

FiVo14:07:17

can I prevent the spec macro checking just for that dependency

ghadi14:07:37

no, it's a jvm wide setting

ghadi14:07:43

-Dclojure.spec.skip-macros=true

Renan Oliveira15:07:25

Hi Guys, I have a doubt, what do you using to response in json in pedestal?

ghadi15:07:47

io.pedestal.http/json-body interceptor

Mario C.15:07:18

I am looking for something like cond-> but not sure if its provided by clojure. Basically I want to test a value/expression for true or false if its true then apply a transformation and pass it to the next test. If its false skip it. Until a final value/expression is reached. In others words, cond-> but with the ability to use the result in the true case of the previous clause in the next condition. Does that make sense?

ghadi15:07:17

collection operations don't need to check if things are empty

ghadi15:07:31

(filter whatever empty-list) -> returns an empty list

ghadi15:07:44

also, note the documentation for empty?:

ghadi15:07:04

user=> (doc empty?)
-------------------------
clojure.core/empty?
([coll])
  Returns true if coll has no items - same as (not (seq coll)).
  Please use the idiom (seq x) rather than (not (empty? x))

Mario C.16:07:41

@U050ECB92 That was just examples I threw out there for the sake of making an example. But you're right

Mario C.16:07:05

@UHK8B8STX I guess I could use as-> and make a series if-elses but I was trying to avoid that

Mario C.16:07:22

Unless there is something I am not seeing

Mario C.16:07:16

@U04V70XH6 Yes, its exactly what I was looking for

seancorfield16:07:54

Yeah, I use those a lot at work and I see people ask for them fairly regularly, that's why we open sourced that little library.

Mario C.16:07:29

yea it looks really useful

Mario C.15:07:08

(cond-> initial-value 
  (not (empty? initial-value)) (map + initial-value) 
  (empty? (filter even? <result-of-previous-mapping>)) true)

Mario C.15:07:38

I guess I would need a short circuit too

Ahmed Hassan15:07:06

How can I do something like this in aliases of CLI Deps? ["trampoline" "run" "-m" "app.server/run-dev"]

Ahmed Hassan15:07:43

I mean running a function other than -main.

credulous16:07:01

Hi. I’m trying to get my head around browser vs. server routing, I’m messing things up in my app. I’m using bidi and pushy on the client, and am successfully processing the requested url:

(defn- dispatch-route
  [matched-route]
  (log/info "Matched route" matched-route)
  (let [route (:handler matched-route) ]
    (condp = route
      :edit-feature (rf/dispatch [:editing-feature 
                                  (get-in matched-route :route-params :id) ])
      :alexandria-home (do (log/info "In home dispatch") (rf/dispatch [:editing-feature "home"]))
      nil)))

credulous16:07:43

In that code, clicking a link with href=“/editfeature/123” works to set the :editing-feature key in the app-db.

credulous16:07:01

However my browser then navigates to /editfeature/123 which is a 404.

credulous16:07:31

I don’t want it to navigate away from the displayed page, I intend to use that key in the app-db to bring up a modal edit dialog.

credulous16:07:02

I assume it has something to do with my serverside routing, which uses Compojure

credulous16:07:37

(compojure/defroutes app
  (-> (compojure/routes
        (compojure/GET "/" [] (slurp (io/resource "public/index.html")) 
                       )
        (route/resources "/")
        api/routes )
      reload/wrap-reload))

Ville Vuorinen16:07:50

clojure + lein + java11, WARNING: Illegal reflective access by clojure.lang.InjectedInvoker/0x0000000800232040 (file:/Users/idk/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar) to method sun.net.www.protocol.https.HttpsURLConnectionImpl.getServerCertificates()

Ville Vuorinen16:07:53

“Perhaps the best is to provide type hints to the exported types so the call is no longer reflective:”

seancorfield17:07:58

@ville I suspect the actual reflective access is coming from elsewhere and the message is misleading. Clojure 1.10.1 is tested on JDK11 so it should be fine. What version of Leiningen are you using?

Ville Vuorinen17:07:02

Leiningen 2.9.1 on Java 11.0.3 Java HotSpot(TM) 64-Bit Server VM

ghadi17:07:11

it's unclear from the warning whether it's the lein jvm or the project jvm that's causing the issue. If it's the project, add --illegal-access=debug to :jvm-opts, if it's lein, add it to an environment variable LEIN_JVM_OPTS

ghadi17:07:48

if you add --illegal-access=debug you'll get a bit better trace about what is reflecting specifically

ghadi17:07:22

right now it points to the clojure.jar itself, because that's where clojure's reflection mechanism lives

ghadi17:07:49

but the root of the warning is user code that is triggering the reflection mechanism

theeternalpulse19:07:53

If I'm creating a tools.deps based project and want certain folders excluded from the classpath (say my src/migrations dependencies excluded from a container that only hosts the web or service portion of my app) would it be better to just copy the subfolders when creating the environment, and include the deps in :extra-deps. I've been experimenting with having any non-app related clojure code on top-level folders for example migratus for my migration code that won't be loaded unless you explicitly call the alias that adds that folder. For people that actually deployed code that has a lot of this type of support code, or multi-enviroment setup, do you care if extra dependencies are even loaded, am I overthinking this?

seancorfield20:07:58

If it isn't source code, don't put it in src, use resources or a folder under that.

seancorfield20:07:10

If it is source code, and you still want some control, use src/clj for your Clojure code (and src/migrations for the migration code) and then use :paths ["src/clj"] by default and aliases to bring in :extra-paths ["src/migrations"] as needed.

theeternalpulse20:07:23

I like that route

felipebarros23:07:24

I'm looking for a resource (book chapter, article, tutorial, blog post, video, etc) on interacting with API's through ClojureScript.

mfikes23:07:38

@anantpaatra Are you interested in writing ClojureScript that interacts with JavaScript APIs? (In other words, are you interested in JavaScript interop from ClojureScript?)

mfikes23:07:07

Or, are you perhaps interested in how to call a JSON-based HTTP API?

mfikes23:07:33

Hah, the 2nd one? (JSON-based HTTP API)?

felipebarros23:07:01

I'm interested in both actually hehe

felipebarros23:07:10

Sorry for the ambiguous answer.

mfikes23:07:16

No problem 🙂

pvillegas1223:07:04

I’m trying to add [org.apache.wss4j/wss4j "2.2.3" :extension "pom"] to my lein project, but I am unable to use java classes from that library

pvillegas1223:07:40

I want (import '[org.apache.wss4j.dom.message WSSecHeader]) to work but intellij appears to not find the classes correctly