@jr0cket Unfortunately, no. :main-opts ["-m" "antq.core" "--error-format='::error file={{file}}::{{message}}'"]
is interpreted as ["-m" "antq.core" "--error-format='::error" "file={{file}}::{{message}}'"]
@jason358 Unfortunately, neither \\
nor "--param='{:a 1}'"
worked for main-opts
Hi, I keep getting this strange error about file uploads https://pastebin.com/VxY2Z4N3
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
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]]
Thanks guys import
was what I needed.
for java classes:
(ns my.ns
(:import java.sql.Timestamp))
or from the repl:
(import java.sql.Timestamp)
How do I do
Select * from Users where id in (1, 2, 3);
in toucan[https://github.com/metabase/toucan]?
yup that works, thanks
If you want to import multiple Java classes from a package
(ns my.ns
(:import [java.sql Connection DataSource Timestamp]))
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.
It looks like it builds some queries on top of HoneySQL, based on https://github.com/metabase/toucan/blob/master/docs/db-functions.md#more-advanced-key-value-args
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: https://github.com/metabase/toucan/blob/master/docs/db-functions.md Article: https://www.demystifyfp.com/clojure/blog/restful-crud-apis-using-compojure-api-and-toucan-part-1/
clj::Twitter.core=> (db/select Tweet :id [:in 1 2 3])
; Execution error (PSQLException) at org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse (QueryExecutorImpl.java:2553).
; 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: http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html
next.jdbc
is the replacement for clojure.java.jdbc
and the documentation is better https://cljdoc.org/d/seancorfield/next.jdbc/ -- 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, http://clojure-doc.org 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 clojure.java.jdbc
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.
π
great so I'm now a contributor, not just a user. π
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
You can write your own predicate functions. This is a starting point you can experiment around
(defn square?
[m]
(let [n (count m)]
(every? #(== n (count %)) m)))
(comment
(square? [[1 2]])
(square? [[1 2] [3 4]])
(square? [[1 2] [3 4] [5 6]]))
(s/def ::square?
(s/and sequential? square?))
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))
Thanks @daniel415!
an extra dep, but i found medley useful https://weavejester.github.io/medley/medley.core.html#var-filter-keys
(m/filter-keys #{:a :b} {:a 1 :c 2 :b 3})
Thanks @ban.istvan!
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?
(update m :bb #(count %)) or just (update m :bb count)
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
.
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
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")
"dev"
user=>
that's not an env var
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
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β¦
:aliases
{:dev {:jvm-opts ["-Dconf=dev-config.edn"]}}
As an aside, https://github.com/juxt/aero is a great project for managing configuration.
thanks @jr0cket .. reading through your post at http://jr0cket.co.uk/2019/07/CIDER-jack-in-to-Clojure-CLI-projects-from-Spacemacs.html seems to be what I need..
your example there works. Does that mean your problem is solved?
or is your question now how to jack in with that profile?
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"))))
All the .dir-locals.el you could want here : https://practicalli.github.io/spacemacs/clojure-projects/project-configuration.html and here https://practicalli.github.io/spacemacs/reference/cider/configuration-variables.html
I am fairly sure the JVM options are part of the cider-clojure-cli-global-options
problem solved
How to iterate every [key value]
of a deeply nested map?
have a look at clojure.walk
namespace
or tree-seq
β https://clojuredocs.org/clojure.core/tree-seq
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
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"
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...
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)
yourcompany.queue.protocols
yourcompany.queue.impl.sqs
yourcompany.queue.impl.rabbit
yourcompany.queue.impl.kafka
quick macro question: i want to define a method on a multimethod, from within a macro
i have (defmulti defcard-multi (fn [title] title))
as the base. and then i have the macro
(defmacro defcard [title] `(defmethod defcard-multi ~title [_] {}))
and then calling (defcard "anything")
throws a large spec error
i've reduced it to still happening if i leave the multimethod out of the picture, just using defn
instead
as simple as:
(defmacro defcard [title] `(defn temp [_] ~title))
what am I missing?
that _
will become namespace-qualified and cause the problem, use ~'_
both defmethod
and defcard-multi
will be qualified as well
Thatβs ok
right
ah, thank you
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"])
(vector "string")
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