Fork me on GitHub

Hi, I keep getting this strange error about file uploads


I guess somebody is trying to upload a file to my box? i don't understand, it's a GET /


any pointers (that are not null) would be appreciated

😆 3

you could probably replace wrap-params or whichever middleware that calls wrap params with a version that tries to wrap-params, catches errors, logs more info about the request, and then re throws the error


How to import java.sql ? I tried following but does not seem to work.

[java.sql :refer [Timestamp]]


for java classes:

(ns my.ns
  (:import java.sql.Timestamp))


or from the repl:

(import java.sql.Timestamp)


yup that works, thanks


If you want to import multiple Java classes from a package

(ns my.ns
  (:import [java.sql Connection DataSource Timestamp]))


Thanks guys import was what I needed.


How do I do Select * from Users where id in (1, 2, 3); in toucan[]?


You probably won't get answer in any channel but #toucan (and I see you've already posted this question there).


I suspect not many people use Toucan -- it kind of looks very ORM-ish and that's not how folks deal with databases in Clojure.


(hmm, only 23 people in #toucan which also speaks to it not being widely used)


Looking at the docs, I suspect you can do (db/select User :id [:in [1 2 3]]) depending on what you've defined as the "model" for your users table.


I followed some articles which mentioned the usage of Toucan in production. The documentation has pointers on how to write queries for common scenarios but couldn't find an example that dealt with the question I asked. Reference: Article:

clj::Twitter.core=> (db/select Tweet :id [:in 1 2 3])
; Execution error (PSQLException) at org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse (
; ERROR: syntax error at or near "$1"


That isn't what I suggested you try. Check what I suggested again.


(you're missing [ ... ] around the sequence of IDs)


Yup, fixed that and it works. Thanks! Also, I'll look into HoneySQL. > that's not how folks deal with databases in Clojure What's the recommended way?


Just plain data -- hash maps and vectors of hash maps.


We don't have "objects" so "ORM" makes no sense.


The other thing that's bad about Toucan is that it relies on a global database connection behind the scene -- global singletons are an anti-pattern.


It's better to pass the DB connection/datasource into code that accesses the DB so that it is easier to test code and also to reuse code across multple datasources.


Any examples I can refer to see how that's done? Came across this:


next.jdbc is the replacement for and the documentation is better -- unfortunately the clojure-doc server hasn't been updated in ages (I have a number of java.jdbc doc updates committed that haven't been published)


Yeah, hasn't been republished since mid-2018 😞 but a lot of changes have been committed to the repo since then.


(I maintain HoneySQL and next.jdbc -- and I've maintained since 2011)


There are #honeysql and #sql channels if you get stuck with either HoneySQL or any more general SQL-related issues. And those channels are fairly active.


That's great! I'll go through the doc and try out some HoneySql on new projects. I'll post the solution in #toucan too. Thank you for your help.


can i describe a n*n matrix with spec? so all vectors should have the same length — [[1 2] [3 4]] would be fine but [[1 2] [ 3]] and [[1 2]] are not

Ben Sless09:09:42

You can write your own predicate functions. This is a starting point you can experiment around

(defn square?
  (let [n (count m)]
    (every? #(== n (count %)) m)))

  (square? [[1 2]])
  (square? [[1 2] [3 4]])
  (square? [[1 2] [3 4] [5 6]]))

(s/def ::square?
  (s/and sequential? square?))

👍 3

ah, right, makes sense. thank you


What is the recommended way to filter maps from a vector of maps based on the value of specific keys?

existing-ids => [1 2 32 24]
api-response => [{:id 1, :text "abcd"},{:id 2 :text "efgh"},{:id 3 :text "asdf"}, {:id 4 :text "gsdsd"}]
result => [{:id 3 :text "asdf"}, {:id 4 :text "gsdsd"}] ;;api-response with ids present in existing-ids are removed.


I'm relatively new to Clojure myself but I would do this:

(let [existing-ids (set [1 2 32 24])
      api-response [{:id 1, :text "abcd"},{:id 2 :text "efgh"},{:id 3 :text "asdf"}, {:id 4 :text "gsdsd"}]]
  (remove #(existing-ids (:id %)) api-response))


an extra dep, but i found medley useful

(m/filter-keys #{:a :b} {:a 1 :c 2 :b 3})

Old account12:09:09

Hi, What would be the best way to transform such map {:a "text" :bb "more -text"} to {:a "text" :bb 9} so that :bb value is the length of the previous map's :bb value?

Stas Makarov12:09:21

(update m :bb #(count %)) or just (update m :bb count)

💪 3
💯 3
misto quente13:09:48

When i cider-jack-in to a lein project, the repl environment is set up with env var conf="./dev-config.edn" where is this configured? How can I achieve this when using deps.edn ?


that sounds like it is configured in code in your project. certainly lein doesn't set any kind of environmental variable called conf.

misto quente14:09:39

I think cider reads the :jvm-opts key in my project.clj dev profile. I think i would need something similar in a deps.edn alias… any example would be appreciated


CIDER doesn't but yes lein will certainly start up the jvm with those options. running clj --help i see > The dep-opts are used to build the java-opts and classpath: > -Jopt Pass opt through in java_opts, ex: -J-Xmx512m which sounds like it might be what you are looking for


or, that's a way to pass jvm options. that doesn't sound like how you are setting an environmental var though

Alex Miller (Clojure team)14:09:08

you can't set env vars from inside a jvm, so this would need to be something around the invocation (clj / deps.edn does not have anything like this)


clj -J-Dconfig="dev"
Clojure 1.10.1
user=> (System/getProperty "config")


what's the best way to do defaults in a library so (def api-url "http://api/") but then allow the user to pull in the library but replace the default ?


ah good point.


just env the value ?


although env tends not to work so well with frontend libraries

misto quente14:09:14

Sorry, i was mistaken when i said env var, i meant passing a system prop in jvm opts, what I’m looking for is is to have cider-jack-in use my dev alias like: clj -A:dev , where dev is something like…

 {:dev {:jvm-opts ["-Dconf=dev-config.edn"]}}


As an aside, is a great project for managing configuration.


your example there works. Does that mean your problem is solved?


or is your question now how to jack in with that profile?

misto quente14:09:19

yes, trying jack-in with that profile


you can use a prefix argument before cider-jack-in and add -A:dev to the jack in string. alternatively, you can set the variable cider-clojure-cli-global-options to "-A:dev" to have this by default


in .dir-locals.el you can paste:

((nil . ((cider-clojure-cli-global-options     . "-A:dev:test"))))


I am fairly sure the JVM options are part of the cider-clojure-cli-global-options

misto quente14:09:11

problem solved

Old account15:09:49

How to iterate every [key value] of a deeply nested map?


have a look at clojure.walk namespace


I am new to programming. I have started to learn C++ and even some python My background is Economics. I have strong quantitative background (Math and Econ) and I know STATA. In general, I would like to use programming (1) for ML/AI in economics topics+other utilities such as webcraping, and other data driven analyses (2) for it, fintech matchmaking platforms In particular, I just recently discovered I love programming. I am old (35) as a beginner but I have set a goal to become a fully capable programmer by 40...Hopefully I can learn 2 languages well enough by then. If jobs opportunities are present then, I can switch careers although I still like my career path. I could always use my programming skills for either my job, a start up, or become a full-fledge prgrammer. Online research has led me to think that Clojure might be an excellent language to focus on because they say it is an excellent for rapid development (If I want to use it for a start up, lone developer), data-driven (econ and ML), and provide a path to be a great programmer. My Apprehension is that Clojure doesn't seem widely used so might issues with doing ML projects with few libraries (compare to Python for ex), and future job prospects, etc... Anyway, I welcome any insights/advice, tips. Thanks in advance, Baye


Being a Clojure enthusiast, I do not want to dissuade you from learning it, but whether it is a good language for you to learn does depend upon your goals, and the goals you have described lead me to recommend that you might try asking in the #data-science channel here to better learn the strengths vs. weaknesses Clojure has relative to more widely used platforms like Python for such tasks.


Thanks for your reply. I have posted the question at #data-science channel. But my interest, in programming is not limited to data science/ML...I am potentially interested in building apps (web/desktop, etc) for potential future projects in education, health etc...

Jim Newton16:09:44

The documentation for defn- says it generates a non-public def. What does that mean? Does it mean that the symbol does not get imported when I use :refer :all in a namespace :require ?


correct. that var can only be referenced from that namespace. you can of course get around this with #'the-var but it's "private"

Jim Newton17:09:33

that's cool. I've been naming such functions with funny names. I think this could be useful.


@jimka.issy another common thing is to make a namespace with "impl" in the name, and treat it as private (by convention)



Noah Bogart20:09:25

quick macro question: i want to define a method on a multimethod, from within a macro

Noah Bogart20:09:32

i have (defmulti defcard-multi (fn [title] title)) as the base. and then i have the macro

(defmacro defcard [title] `(defmethod defcard-multi ~title [_] {}))

Noah Bogart20:09:46

and then calling (defcard "anything") throws a large spec error

Noah Bogart20:09:14

i've reduced it to still happening if i leave the multimethod out of the picture, just using defn instead

Noah Bogart20:09:16

as simple as:

(defmacro defcard [title] `(defn temp [_] ~title))

Noah Bogart20:09:16

what am I missing?

Jan K20:09:27

that _ will become namespace-qualified and cause the problem, use ~'_

☝️ 3

both defmethod and defcard-multi will be qualified as well

Noah Bogart20:09:09

ah, thank you

Old account20:09:18

how to put a string into a vector? I tried (into [] "jfjfjgjgjf") but this one breaks string into symbols. I need it as a whole...


(conj [] "foo") or with into it has to be a seq (into [] ["foo" "bar"])

✔️ 3

(vector "string")

✔️ 3

to be pedantic, that doesn't break it into symbols (symbols are a specific type, used for looking up variables and local bindings most often), it breaks it up into characters

👍 3