Fork me on GitHub
Muhammad Hamza Chippa01:02:00

How to replicate this in the reagent ?

const {
    setNodes: setNodesHook,
  } = useReactFlow();

Mario Trost13:02:32

Perhaps you find better help in the #reagent channel

Mario Trost13:02:25

Coming from React newly to Reagent myself, I'm interested too

Mario Trost13:02:07

I investigate 5 minutes as an after lunch break 😄

😂 2

Using clj-http for a post request, I get an exception:

#error {
 :cause "clj-http: status 429"
 :data {:cached nil, :request-time 639, :repeatable? false, :protocol-version {:name "HTTP", :major 1, :minor 1}, :streaming? true, :http-client #object[org.apache.http.impl.client.InternalHttpClient 0x4601ca42 "org.apache.http.impl.client.InternalHttpClient@4601ca42"], :chunked? false, :type :clj-http.client/unexceptional-status, :reason-phrase "Too Many Requests", :headers {"Date" "Fri, 10 Feb 2023 04:21:27 GMT", "Content-Type" "application/json; charset=utf-8", "Content-Length" "206", "Connection" "close", "Vary" "Origin", "X-Request-Id" "d1abab911af92f48069057acf0ec2e6d", "Strict-Transport-Security" "max-age=15724800; includeSubDomains"}, :orig-content-encoding nil, :status 429, :length 206, :body "{\n    \"error\": {\n        \"message\": \"You exceeded your current quota, please check your plan and billing details.\",\n        \"type\": \"insufficient_quota\",\n        \"param\": null,\n        \"code\": null\n    }\n}\n", :trace-redirects []}
 [{:type clojure.lang.ExceptionInfo
   :message "clj-http: status 429"
   :data {:cached nil, :request-time 639, :repeatable? false, :protocol-version {:name "HTTP", :major 1, :minor 1}, :streaming? true, :http-client #object[org.apache.http.impl.client.InternalHttpClient 0x4601ca42 "org.apache.http.impl.client.InternalHttpClient@4601ca42"], :chunked? false, :type :clj-http.client/unexceptional-status, :reason-phrase "Too Many Requests", :headers {"Date" "Fri, 10 Feb 2023 04:21:27 GMT", "Content-Type" "application/json; charset=utf-8", "Content-Length" "206", "Connection" "close", "Vary" "Origin", "X-Request-Id" "d1abab911af92f48069057acf0ec2e6d", "Strict-Transport-Security" "max-age=15724800; includeSubDomains"}, :orig-content-encoding nil, :status 429, :length 206, :body "{\n    \"error\": {\n        \"message\": \"You exceeded your current quota, please check your plan and billing details.\",\n        \"type\": \"insufficient_quota\",\n        \"param\": null,\n        \"code\": null\n    }\n}\n", :trace-redirects []}
   :at [$stack_trace invoke "support.clj" 201]}]
Now, if I call ex-cause on this exception, I get nil. Why? How do I get the :cause of this error?

Alex Miller (Clojure team)04:02:40

it's a little hard to know this, but the Throwable->map data you're seeing above focuses on the root cause of an exception chain, where as ex-cause is called on the top cause in the chain

Alex Miller (Clojure team)04:02:20

so I suspect that (-> *e Throwable->map :cause) will give you what you see above

clapping 2

Wow, this works


yikes though

Alex Miller (Clojure team)04:02:17

it's not obvious - you're also seeing the effect of printers, here a printer that is custom to your IDE (which I assume is CIDER)

👍 2

I would like to start using clj-refactor-mode. Just simple rename function refactoring. But emacs just freeze here: To perform this op the project needs to be evaluated. Analyzing a large project might take a while: hit C-g to abort. (Set cljr-warn-on-eval to nil to analyze the project without warning) Do you want to proceed? (y or n) y Fetching symbol occurrences... Anyone had similar problems? Here some similar issue but it's with java version 8 I got 11. Anyway I'm using clojurescript. Does this mode work with clojurescript? I don;t see any information about it.


I suggest re-posting this question in the #C0617A8PQ channel as clj-refactor is packaged in with cider now and you're more likely to get targeted advice.

👍 2

However, I think there are a number clj-refactor fn's that aren't supported in ClojureScript. You could try clojure-lsp which will work with ClojureScript as it relies on static analysis.

👍 2

or maybe with newer solution -> tree-sitter ?


As I understand it, treesitter will still require an LSP server. Unfortunately Clj-refactor gets much less attention than clojure-lsp, so unless you are able to help clj-refactor gain better ClojureScript support I'd suggest Clojure LSP (I use Clojure LSP for renaming and other refactor actions using Neovim & treesitter, Emacs Doom / Spacemacs and VSpaceCode & Clava)

👍 2

@U05254DQM thank you for the clarification. I will try with clojure lsp then. btw. love your site.

👍 2

Hi Everyone -- I'm trying to create and then connect to DuckDB database from Clojure. We are using TechML dataset (so I tried the TMDucken library but couldn't get it figured out and it seems very early stage). So now I am trying to use next.jdbc to get up and running. I have the duckdb binary downloaded an available on my path (on windows). I went to the drivers deps.edn in next.jdbc ( and didn't see any info for duckdb, so I made a guess at it below. (Maybe it's not possible?) I have this in my deps.edn file

{:paths ["src" "resources"]
 :deps {
        com.github.seancorfield/next.jdbc {:mvn/version "1.3.847"}
        org.duckdb/duckdb_jdbc {:mvn/version "0.6.1"}
 :aliases {:test {:extra-paths ["test"]
                  :extra-deps {}}}}
and I have this in my clj file:
(ns spinnakersca.duckdb.core
  (:require [tech.v3.dataset :as ds]
            [tablecloth.api :as tc]
            [next.jdbc :as jdbc] 
I followed the next.jdbc getting started tutorial and put together the following:
(def db
  {:classname "org.duckdb.DuckDBDriver"
   :dbtype    "duckdb"
   :host      :none
   :dbname    "db/duckdb.db"})

(def datasource (jdbc/get-datasource db))

 (jdbc/execute! datasource ["
create table address (
  name varchar(32),
  email varchar(255)

(jdbc/execute! datasource ["SELECT * FROM address"])
This progresses as I evaluate each form in the repl. When I eval the last form, I get:
(jdbc/execute! datasource ["SELECT * FROM address"])
; Execution error (SQLException) at org.duckdb.DuckDBNative/duckdb_jdbc_prepare (
; Catalog Error: Table with name address does not exist!
; Did you mean "pg_class"?
; LINE 1: SELECT * FROM address
So obviously 1 or all of the previous steps weren't done correctly. Does any one have any pointers, blogs/tutorials to read, etc.. to get the DB connection established?


Does that db/duckdb.db database file exist and does it contain a table called address?


i.e., are you sure the create table command succeeded?


OK, I just tried this at home and I think the key issue is that you specified :dname "db/duckdb.db" but you don't have a db folder in your project. I tried the above without a db folder and got an error. I created a db folder in the project and tried again and it worked. @U04A1LVBBPU


(the create table command gives the same response in both the error and non-error cases which is less than helpful 😞 )


Here's my REPL session:

(def db
    {:classname "org.duckdb.DuckDBDriver"
     :dbtype    "duckdb"
     :host      :none
     :dbname    "db/duckdb.db"}) ;;=> #'duck.quack/db
  (def datasource (jdbc/get-datasource db)) ;;=> #'duck.quack/datasource
  (jdbc/execute! datasource ["
create table address (
  name varchar(32),
  email varchar(255)
)"]) ;;=> [#:next.jdbc{:update-count -1}]
  (jdbc/execute! datasource ["SELECT * FROM address"]) ;;=> []
  (sql/insert! datasource :address {:name "Sean" :email ""}) ;;=> #:next.jdbc{:update-count -1}
  (jdbc/execute! datasource ["SELECT * FROM address"]) ;;=> [{:name "Sean", :email ""}]
DuckDB's responses to non-`ResultSet` execution are not helpful: most drivers return a count of successful operations, not -1!


If you need additional help with next.jdbc, feel free to join #C1Q164V29 and ask questions there!


Hi Sean -- Thanks so much for the detailed and helpful response. I was able to get the connection to the empty db. If I could ask one more question, What library are you using for the "sql" alias in the statement (sql/insert! datasource :address {:name "Sean" :email "<mailto:[email protected]|[email protected]>"})?


next.jdbc.sql -- the "friendly functions" namespace.


Thanks so much 🙂 I'm up and running

👍 2

Hello! I have serious troubles getting started with the repl. Sometimes, everything works fine but sometimes really weird stuff happens and suddenly I have no clojure.repl tools or even map or -> are missing. Is there some article or book I can read to understand how to use repls and namespaces properly?

Sam Ritchie19:02:58

The questions you’ll get almost always are What did you do What did you see What did you expect

Sam Ritchie19:02:10

So, what did you type, where, to open the REPL… etc


The description makes it seem like it's either the repl or some expectation for the how the repl is supposed to work. Which repl are you using?


I believe this can happen if you use in-ns to create/move into a another namespace. in-ns does not automatically load clojure.core


I did not change namespace. Give me a minute, I'm answering the above questions. If anyone has a book or article, I'd be happy to read that at some point.


Alright, I'm using VSCode with Calva and Calva is firing up cider-nrepl. I used CMD+SHIFT+P > "Start or Connect to Clojure REPL". I did not change the namespace. I typed (require '[babashka.fs :as fs]) which worked. I was able to use (fs/directory? ".") which returned true. Then I tried (dir fs) to explore the fs namespace and that returned Unable to resolve symbol: dir in this context. So, I did (require '[clojure.repl :refer [dir doc source]) which worked fine. However, then I tried (-> "some-path" fs/exists? fs/directory?) and that returned Unable to resolve symbol: -> in this context and that made me a think that something fundamental is broken. I can share the entire history if you want.


what does *ns* show when you type it in the calva repl?




This is a different state. Let me try something


Hm, could it be that root is a var that exists in clojure?e


The behavior above is consistent with the user namespace having clojure.core/require refered but nothing else


Which is not the state the user namespace is created in by default


I just realized that I also did (def root "some-path")


That doesn't matter


Do you have a user.clj?


Are you using any nrepl plugins or whatever


Are you using any kind of automatic code reloader thing?


It must have something to with defining a variable named root. I just restarted the repl and changed the name of the binding and now everything works again.


Likely just restarting the repl did it

👆 2

Of course I restarted the repl and retried all of the commands I used.


Hm, can't reproduce it though.


Well! Thanks for helping though 😄


The repl is a stateful thing, likely some bit of tooling or something you are using messed with the state in some way (all kinds of ways this can happen) and restarting a new repl gets you a new pristine state


This is a fresh project. There is literally no tooling except fs


There is nrepl


This is my deps.edn {:deps {babashka/fs {:mvn/version "0.2.16"}}}


There is calva


Both of those are complex pluggable bits of tooling


You may also have other stuff in your user level deps.edn, etc


The reason why I asked for a book or something is that behavior like this happens regularly and kind of spoils the whole interactive development experience for me. The repl that runs for weeks is kind of something that I can't relate to because I have to restart the repl frequently to get rid of some weird state.


We're trying to understand a little bit more about your current setup to recommend the most relevant resources.


Also, based on the symptoms of your problem, it might not be the type of thing that's covered in any particular book (unless that book happens to use the same setup).


A general resource might be something like, but there are other options that might be a better fit depending on what you're looking for.


Thanks! I'll read this article.


Many including moiself got a good start from But it sounds like you are doing fine, over all. So we are looking for some unknown action that sends you or Clojure off the rails too often. Just learning more will alone keep us from going off the rails, and also lets us notice sooner when sth goes wrong. Noticing sooner will make it more likely we remember what we recently did that (prolly) caused the trouble. Then start a new sesssion and confirm all is well again. Now try that suspect operation again. Rinse. Repeat, but yes, start a new session each time once things are confused. This was an incredibly long way of saying, yeah, the REPL is a variable, for good and bad. hth!


Alright, if it comes up again, I’ll provide more details. Thanks everyone for being so patient!


I was able to reproduce it and of course @U0NCTKEV8 and others were right. It seems to be a tooling problem. Here's my repl output. It looks like I only get an error if I try to send stuff from the editor to the repl. If I paste the exact same code to the repl it works just fine!


And once I get the error, the REPL is completely broken.


I just noticed that in my second snippet, the namespace has changed.


So, when I send stuff from the original dependencies.core namespace, it is sent to the repl, even though I'm not using ALT + ENTER. If I send the same code from an empty file without a namespace, the namespace is changed to user. I think, I might be getting closer to why this is breaking.


How do I perform a regex split where I split on "$" but not on "\\$"? So

(my-split "$one$two$20\\$ $four") => ["" "one" "two" "20\\$ " "four"]
I have been making several unsuccessful attempts...


what have you tried?


Here's my attempt...

(defn my-split [s]
           (let [split-s (str/split s #"[^\\\\]\$")]
             (if (str/starts-with? s "$")
               (concat [""] [(subs (first split-s) 1)] (rest split-s))


I think

Does what you want.


using zero-width negative lookbehind


It's listed under the special constructs on, but not really described anywhere


and it's probably harder to google than it is to use 🤷


> and it's probably harder to google than it is to use I don't know about that. I remember feeling like lookbehinds were kind of mind bending when I first tried to use them. I think it was mainly just the god-awful syntax, though. Makes it seem more confusing than it is.

👍 2

Although, if you try to search for the provided syntax, (?<!X) , it basically ignores everything except for the letter X


But googling for "X" has gotta get you pretty close. Right? 😄

😆 2