This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-03
Channels
- # announcements (15)
- # babashka (143)
- # babashka-sci-dev (2)
- # beginners (35)
- # biff (11)
- # calva (5)
- # cider (8)
- # clerk (4)
- # clj-kondo (58)
- # cljdoc (6)
- # clojure (88)
- # clojure-denmark (1)
- # clojure-europe (77)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-uk (1)
- # clojurescript (19)
- # clr (32)
- # code-reviews (158)
- # datahike (5)
- # datomic (10)
- # deps-new (3)
- # fulcro (12)
- # graalvm (20)
- # honeysql (23)
- # hyperfiddle (32)
- # jobs (1)
- # kaocha (10)
- # membrane (6)
- # observability (1)
- # other-languages (2)
- # pathom (5)
- # practicalli (12)
- # reagent (4)
- # reitit (7)
- # releases (1)
- # remote-jobs (1)
- # sci (25)
- # shadow-cljs (52)
Is the 'granularity' for pmap
the lazy sequence chunk? i.e. if there's an outsized item in a chunk and all other tasks have completed, no new tasks will be started until that item completes?
https://clojurians.slack.com/archives/CHY97NXE2/p1670867548096929?thread_ts=1670867548.096929&cid=CHY97NXE2 has some discussion about pmap at the end of thread
Hello, I am looking for a function to find the index of a subvector inside a vector:
(my-index [100 20 8] [0 13 8 100 20 8 9 14]) ; 3
So far I just managed this using
(java.util.Collections/indexOfSubList (apply list [0 13 8 100 20 8 9 14]) (apply list [100 20 8]))
Is this an efficient way? Is there an alternative way to do this using vectors?You don't have to convert:
(java.util.Collections/indexOfSubList [0 13 8 100 20 8 9 14] [100 20 8])
=> 3
Thanks! I don’t know how I missed that!
As I dont like to delve back to java (the documentation drives me crazy). I tried a Clojure only which criterium showed gave same speed as java indexOf. Evaluation count : 3541492380 in 60 samples of 59024873 calls. Execution time mean : 15.004989 ns Execution time std-deviation : 0.082944 ns Execution time lower quantile : 14.851435 ns ( 2.5%) Execution time upper quantile : 15.212629 ns (97.5%) Overhead used : 2.011556 ns Found 2 outliers in 60 samples (3.3333 %) low-severe 1 (1.6667 %) low-mild 1 (1.6667 %) Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
I'm getting user input like so:
(print "User: ")
(flush)
(read-line)
Because I want the terminal to output:
User: <what the user input after hitting enter>
But what is happening is it first prints out User:
and then waits for the input but then after the user presses Enter
it changes too:
<what the user input>
without the "User: " part at the beginning. Do you know how I can fix that. I don't want to use println
without the flush
because I want the "User: " to appear on the same line as their input.I just tried it out in a standalone repl (calva) and it worked like this:
(do (print "User: ")
(flush)
(read-line))
(defn -main []
(println "Welcome to ChatGPT CLI")
(print "Please enter a prompt: ")
(flush)
(loop [prompt (read-line)]
(let [resp (response (request prompt))
resp (:content (last @messages))]
(println)
(println "ChatGPT response:" resp)
(println)
(print "User: ")
(flush)
(recur (read-line)))))
And you have tried just the example code that we discussed? And that didn't work either?
Yep:
λ ~/projects/clojure/chatgpt-cli : clj -M -m chatgpt-cli.core
User:
After input:
λ ~/projects/clojure/chatgpt-cli : clj -M -m chatgpt-cli.core
My input
λ ~/projects/clojure/chatgpt-cli :
I am about to switch to trying babashka so I will see if I have the same behavior there
https://ask.clojure.org/index.php/9021/reading-standard-input-one-character-at-a-time
This is a terminal or rlwrap issue I think...?
That's not what Chase is trying to do @U04V4KLKC
I remember this coming up before and someone suggesting a change to .inputrc
I think?
I am interacting with an API endpoint that sends Content-Type
= binary/octet-stream
😱 First time working with that kind of thing. I’m realizing, oh yeah, I’m trying to automate something where if I were doing it manually, I would click a download button, but I’m trying to avoid doing that 1400 times.
Goal: Get the data from the :body of the response, ✌️spit ✌️ it to a file with a filename “artifact-:id”
Obstacle: Some of those artifacts are probably missing so I better handle 404 errors
I’ve been using dakrone’s clj http kinda like this:
(defn call-with-token [url]
(http/get url {:headers {"PRIVATE-TOKEN" private-token}}))
and I guess I need to wrap an exception handler to catch the 404sthere’s a whole lot I don’t understand on this page: https://github.com/clojure-cookbook/clojure-cookbook/blob/master/04_local-io/4-19_handle-binary-files.asciidoc
maybe will help http://www.prodevtips.com/2011/02/26/downloading-binary-files-with-clojure/