Fork me on GitHub
#beginners
<
2023-02-10
>
Muhammad Hamza Chippa01:02:00

How to replicate this in the reagent ?

const {
    project,
    setCenter,
    zoomIn,
    zoomOut,
    fitView,
    addNodes,
    setNodes: setNodesHook,
    addEdges,
    getNodes,
    getEdges,
    deleteElements
  } = 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
dumrat04:02:42

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 []}
 :via
 [{: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 [slingshot.support$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
dumrat04:02:39

Wow, this works

dumrat04:02:53

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
slk50010:02:28

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 https://github.com/clojure-emacs/refactor-nrepl/issues/206 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.

agile_geek10:02:13

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
agile_geek10:02:53

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. https://clojure-lsp.io/

👍 2
slk50011:02:14

or maybe with newer solution -> tree-sitter ?

practicalli-johnny15:02:38

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
slk50015:02:49

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

👍 2
Nick16:02:59

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 (https://github.com/seancorfield/next-jdbc/blob/develop/deps.edn#L10-L27) 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 (DuckDBNative.java:-2).
; 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?

seancorfield16:02:37

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

seancorfield16:02:41

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

seancorfield17:02:22

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

seancorfield17:02:06

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

seancorfield17:02:03

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!

seancorfield17:02:49

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

Nick17:02:27

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]>"})?

seancorfield17:02:52

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

Nick18:02:12

Thanks so much 🙂 I'm up and running

2
👍 2
Gerome19:02:43

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

phronmophobic19:02:17

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?

ander19:02:40

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

Gerome19:02:41

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.

Gerome19:02:58

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.

hiredman19:02:19

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

Gerome20:02:05

#namespace[user]

Gerome20:02:06

This is a different state. Let me try something

Gerome20:02:27

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

hiredman20:02:34

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

hiredman20:02:01

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

Gerome20:02:06

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

hiredman20:02:22

That doesn't matter

hiredman20:02:34

Do you have a user.clj?

hiredman20:02:51

Are you using any nrepl plugins or whatever

hiredman20:02:40

Are you using any kind of automatic code reloader thing?

Gerome20:02:02

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.

hiredman20:02:39

Likely just restarting the repl did it

👆 2
Gerome20:02:10

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

Gerome20:02:25

Hm, can't reproduce it though.

Gerome20:02:50

Well! Thanks for helping though 😄

hiredman20:02:32

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

Gerome20:02:51

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

hiredman20:02:05

There is nrepl

Gerome20:02:06

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

hiredman20:02:10

There is calva

hiredman20:02:44

Both of those are complex pluggable bits of tooling

hiredman20:02:26

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

Gerome20:02:12

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.

phronmophobic20:02:02

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

phronmophobic20:02:48

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).

phronmophobic20:02:14

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

Gerome20:02:51

Thanks! I'll read this article.

kennytilton20:02:02

Many including moiself got a good start from https://www.braveclojure.com/. 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!

Gerome23:02:09

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

Gerome10:02:53

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!

Gerome10:02:56

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

Gerome10:02:51

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

Gerome10:02:08

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.

2
joshcho22:02:39

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...

phronmophobic22:02:09

what have you tried?

joshcho22:02:37

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))
               split-s)))

phronmophobic22:02:38

I think

#"(?<!\\)\$"
Does what you want.

phronmophobic22:02:17

using zero-width negative lookbehind

phronmophobic22:02:35

It's listed under the special constructs on https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/regex/Pattern.html, but not really described anywhere

phronmophobic22:02:06

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

skylize23:02:05

> 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
phronmophobic23:02:40

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

skylize23:02:56

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

😆 2