This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-26
Channels
- # announcements (1)
- # beginners (42)
- # biff (11)
- # calva (15)
- # cider (3)
- # clj-http-lite (3)
- # clojure (52)
- # clojure-europe (16)
- # clojure-nl (1)
- # clojure-norway (39)
- # clojure-uk (4)
- # clojurescript (52)
- # code-reviews (13)
- # conjure (1)
- # cursive (4)
- # data-science (1)
- # datomic (5)
- # emacs (6)
- # events (3)
- # graalvm (5)
- # hyperfiddle (7)
- # kaocha (14)
- # lsp (11)
- # malli (3)
- # nbb (13)
- # off-topic (87)
- # pathom (15)
- # polylith (23)
- # portal (5)
- # reitit (4)
- # shadow-cljs (110)
- # squint (114)
- # testing (1)
- # vim (13)
I use mysql8 + next.jdbc the one of the cloumn type is JSON. In mysql client use update command update JSON is OK , but my programm execute update sql show error:
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Invalid JSON text: "Invalid encoding in string." at position 843 in value for column 'bz_unit_certificate_ui.performance'.
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:104)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:371)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
at next.jdbc.result_set$stmt__GT_result_set.invokeStatic(result_set.clj:650)
at next.jdbc.result_set$stmt__GT_result_set.invoke(result_set.clj:645)
at next.jdbc.result_set$eval9716$fn__9724.invoke(result_set.clj:925)
at next.jdbc.protocols$eval8798$fn__8799$G__8789__8808.invoke(protocols.clj:33)
at next.jdbc$execute_BANG_.invokeStatic(jdbc.clj:250)
at next.jdbc$execute_BANG_.invoke(jdbc.clj:237)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.spec.test.alpha$spec_checking_fn$fn__3023.doInvoke(alpha.clj:153)
I copy SQL use #dbg from var and run it in mysql is ok. The SQL not have a gramma question.Hmm, it may be a bad json encoding instead of character encoding https://stackoverflow.com/questions/44014903/rapidjson-parse-error-invalid-encoding-in-string-207
I use clojure.string/replace '\\n' to '\\\n' or replace '\\n' to '\n' It's still get a error
(s/replace (first sql) #"\\n" "\\n")
==> Data truncation: Invalid JSON text: "Invalid encoding in string."
if I repalce "\\n" to ";" (other chacter) is successed. How can I escape the "\\n"can someone help me remember the function names to find prefixes and suffixes of a sequence? e.g. given a list of length n, there's a function that given 5 will find the tail/suffix of the list starting at element number 5. (rest^5 some-seq)
https://clojuredocs.org/clojure.core/drop-while maybe?
(drop-while #(not= % 5) some-seq)
no, i want to effectively call rest 5 times, finding the 5th tail. in common-lisp it is called nth-cdr
it is amazing how many small things I forget, not using the language for a while. I was searching for nth-rest and rest-n, and nth-suffix, etc...
https://clojuredocs.org
is amazing for lookup something you forget about. you probably remember rest
and for this function on clojuredocs there is See Also section with other functions with similar or connected behaviour.
its for a test case so I don't care about laziness. ahh nthrest, not nth-rest. voilà
thanks delaguardo, I did indeed glance quickly through the doc of rest, mostly at the examples, while also searching for prefix, suffix, etc. didn't get all the way to the see-also section.
does the search field in clojuredocs search only function names, or does it search the text as well? its notable that the doc for nthrest does not contain the word "suffix"
neither does the doc for drop.
maybe its due to drop being lazy and suffix could imply eagerness?
naaaa, lazy suffix is quite easy to understand.
@U010VP3UY9X search field on clojuredocs is only for function name. but See Also section does contain docstrings for other functions as well.
1. you wanted a function with some extended behaviour for the rest
function
2. lookup rest
on clojuredocs, that will give you this page - https://clojuredocs.org/clojure.core/rest
3. Inside of See Also right after examples there are links to drop
, nthrest
, nthnext
4. and for drop
the docstring say “Returns a lazy sequence of all but the first n items in coll.” which sounds to me exactly as you describe what you was looking for.
Clojure has it own “standard library” which doesn’t have to be similar to anything you previously had to deal with. This is why there is no mention of “suffix” anywhere.
would be nice if the search, also searched the content (or optionally so). That way someone (anyone) could just add a helpful example containing the word suffix, and problem solved. It is nice that clojuredocs already alows users to add helpful examples.
for example, in the reduce
doc there's a helpful example which reminds me of the order of the arguments to the client function [acc item]
rather than [item acc]
. I use that example often actually.
clojure.repl/find-docs searches docstrings (and can take a regex)
You might try https://clojure.org/api/cheatsheet. Find the right section, in this case “Seq in, Seq out “, then explore Tail-items rest nthrest next fnext nnext drop drop-while take-last for
How would I output an input-stream into a file? I tried this
(defn input-stream->file [input-stream file-path]
(with-open [o (io/output-stream file-path)]
(.write o input-stream)))
but receive an errorhttps://clojuredocs.org/clojure.java.io/copy could work here
also the error could be due the input-stream not being open?
Given a long string and a set of subs ranges, how can I return a new string with upper-case
applied to each of the given ranges? Is there something that can help with this kind of string transformation or just reduce over it with subs
?
(let [long-string "The rain in spain falls mainly on the plains"
ranges #{[5 8] [5 15] [2 5]}]
(mapv (comp clojure.string/upper-case (partial apply subs long-string)) ranges))
This could be an approach? perhaps it could be more readableMaybe something like this?:
(let [to-uppercase? (fn [n uppercase-ranges] (some #(some #{n} (apply range %)) uppercase-ranges))]
(->> "Aliquam erat volutpat. Nunc eleifend leo vitae magna. In id erat non orci commodo lobortis. Proin neque massa, cursus ut, gravida ut, lobortis eget, lacus."
(map-indexed (fn [idx char]
(if (to-uppercase? idx #{[0 7] [13 21]})
(Character/toUpperCase char)
char)))
(apply str)))
Although it is linear, so it would be slow for really long strings.The strings I'm dealing with are quite long, so efficiency is definitely a consideration.
You might look into a rope datastructure that can handle changes in the string without continually rebuilding the entire string
I'm a little surprised this isn't part of one of the string manipulation libraries like https://github.com/funcool/cuerdas or https://github.com/expez/superstring.
@U11BV7MTK thanks for that tip. I'll give https://github.com/IGJoshua/ropes/blob/master/src/clj/ropes/core.clj a try