This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-11
Channels
- # adventofcode (1)
- # aleph (1)
- # announcements (3)
- # babashka (39)
- # beginners (84)
- # calva (1)
- # cider (17)
- # clj-kondo (15)
- # cljs-dev (43)
- # clojure (132)
- # clojure-dev (1)
- # clojure-europe (4)
- # clojure-nl (7)
- # clojure-norway (4)
- # clojure-uk (22)
- # clojurescript (56)
- # clojurex (24)
- # cursive (11)
- # data-science (2)
- # datascript (33)
- # datomic (7)
- # docker (2)
- # figwheel-main (11)
- # fulcro (2)
- # jobs (3)
- # joker (29)
- # leiningen (3)
- # nrepl (4)
- # off-topic (11)
- # planck (4)
- # reitit (5)
- # ring (4)
- # shadow-cljs (205)
- # spacemacs (5)
- # xtdb (9)
You can implement datafy
and nav
for such things tho'... or rather the underlying protocols...
I have a macro problem: what's the way to get the correct autogensym if unquoted once?
(defmacro def-foo
[name args subject]
`(defn ~name ~args
(let [fix-text# (pr-str ~subject)]
~(cond
(:foo subject)
`(let [len# (count fix-text#)]
(if (> len# 0)
len#
:error))
(:bar subject)
`(clojure.string/reverse fix-text#)
:else `fix-text#))))
> (-> '(def-foo bar [a] {:value a :foo true})
.. macroexpand-1
.. clojure.pprint/pprint)
(clojure.core/defn
bar
[a]
(clojure.core/let
[fix-text__1288__auto__
(clojure.core/pr-str {:value a, :foo true})]
(clojure.core/let
[len__1283__auto__ (clojure.core/count fix-text__1284__auto__)]
(if (clojure.core/> len__1283__auto__ 0) len__1283__auto__ :error))))
I'd expect the fix-text#
s to all refer to the same autogensym which is clearly not the case
Is manually gensym'ing the symbols used across quotes in an encompassing let the only way?
There's a ztellman library for this, but otherwise yes. Nesting expansion is a new context.
I am looking at profilers for Clojure and two libraries that appear viable are https://github.com/ptaoussanis/tufte and https://github.com/clojure-goes-fast/clj-async-profiler. Any recommendations on which to use?
We have a Kafka-driven service that also talks to the DB and is heavy on spec, and I would like to see if we have an actual bottleneck in code. We occasionally spike our input lag and take some time to recover from that, but that could just be a property of the sizeable messages we are ingesting. So whilst I look into the latter it would be also nice to take the generators for a spin, introduce some random traffic locally and see where time is being spent processing it.
Hello, guys! May u could help me... I'm trying to quote/unquote a code snippet but I couldn't figure out the right way Given this snippet:
clojure
(defn spec
[evt tbl]
{:event "event"
:trigger-event evt
:where '(fn [{:keys [table query-seq query-count]}]
(and (= query-seq query-count)
(= table tbl)))
I need only tbl
to be evaluated. But I couldn't find how... I've tried ~
, ~@
, etc... but it gives me back something like (quote tbl)
instead of the value associate with this symbol... can u help me?when I change '
for
, it mess up another things... basically it interpret symbols changing, for example,
fn` to clojure.core/fn
.. but I need to keep it "clean", like written
let me try
do you really need to keep it as written or are you just trying to make the argument symbols not get namespace qualified?
basically get rid of namespaces
Hi, does anyone here use clojure.data.xml?
I’m trying to read an xml string without replacing entity references.
http://clojure.github.io/data.xml/#clojure.data.xml/parse-str and a look at https://github.com/clojure/data.xml/blob/master/src/main/clojure/clojure/data/xml/jvm/parse.clj suggests that we should be able to use (xml/parse-str document :replacing-entity-references false)
but that doesn’t work..
@bronsa i'm trying to write out a edn file based on a map where some keys have functions as values
ok but if you're evaluating the quoted value at some point, then namespacing the vars should be desiderable -- if you're just parsing them then I understand
but if you are indeed evaluating them, there's a better solution:
`(fn [{:keys [table# query-seq# query-count#]}]
(and (= query-seq# query-count#)
(= table# ~tbl))
it's a Joker script that will writes the file for later processing in Clojure
it's not pretty, but works:
:where `(~'fn [{:keys [~'table ~'query-seq ~'query-count]}]
(~'and (~'= ~'query-seq ~'query-count)
(~'= ~'table ~tbl)))
tks, @dominicmdoes this work for your needs?
:where `(fn [{tbl# :table
qs# :query-seq
qcnt# :query-count}]
(and (= qs# qcnt#)
(= tbl# ~tbl)))
I am trying to make this warning go away, but I can’t figure out where to put the type hint: recur arg for primitive local: max_len is not matching primitive, had: Object, needed: long
(defn- max-depth
"Return the max depth of the taxonomy for the give sequence of synsets"
[syn-seq]
(loop [sseq syn-seq
max-len 0]
(if (not sseq)
(inc max-len) ; inc: didn't count arg.
(let [synset (first sseq)
len (apply max (map count (hypernym-paths synset)))]
(recur (next sseq)
(max len max-len))))))
Anyone know how to capture the body of a get request via a selenium webdriver?
Did you try this one? https://github.com/igrishaev/etaoin
Yep that's what we are using, and we are trying to use https://github.com/igrishaev/etaoin#devtools-tracking-http-requests-xhr-ajax but it doesn't seem to contain the body of the get request.
Do you want the body of the request or the body element of the html page?
maybe you can do it via https://github.com/igrishaev/etaoin#executing-javascript and then how you would normally get the body. If that doesn't work maybe you have run into a CORS issue
The issue we're running into with using Javascript is there is a cookie (correlation ID) that has to be sent with the request... and that correlation ID is formed in part from a third party authentication service that we can't access directly. What we're really needing to do is be able to grab the response body from the Chrome developer console.
heya, I’m struggling to do basic counting today… anyone got some clues how to generate a lazy seq of strings from an alphabet "abcde…"
like ("a" "b" "c" "d" "e" "aa" "ab" "ac" … "aaa" "aab" …)
the given solutions all seem very bad given that it sounds like what you have is just mapping numbers to strings of digits.
(defn base27 [n]
(loop [s ()
n n]
(let [r (rem n 27)
q (quot n 27)
c (if (zero? r) \space (char (+ 96 r)))]
(if (zero? q)
(conj s c)
(recur (conj s c) q)))))
(for [i (range 1000)
:let [s (apply str (base27 i))]
:when (not (.contains s " "))]
s)
I was fighting with something like that recently in a toy compiler, turning type variables (which are numbers in the compiler) into strings for pretty printing
I had a counting problem like this once where I wanted to map natural numbers to the column names of an Excel spreadsheet. (a,b,…z,aa,ab). You’d think it would be just a base 26 representation, but it’s not.
The problem with base26, where a is 0 is you never get the a prefixes because b = ab, so you have to do some kind of shift, treating 0 as special which always feels inelegant, it seems like there should some purely numeric function that would do it.
Not sure, but is this the sort of thing you're looking for?
(defn letter-combo [i]
(apply str
(map #(char (+ % (int \a)))
(loop [s (), i i]
(if (< i 26)
(conj s i)
(let [q (quot i 26)
r (rem i 26)]
(recur
(conj s r)
(dec q))))))))
(map letter-combo (range 24 28))
=> ("y" "z" "aa" "ab")
had fun trying to come up with a recursive solution:
(defn string-permute
([chars] (string-permute [""] chars))
([prev chars]
(let [strs (mapcat (fn [c] (map (fn [s] (str c s)) prev)) chars)]
(lazy-cat strs (string-permute strs chars)))))
(string-permute "abc")
;; => ("a" "b" "c" "aa" "ab" "ac" "ba" "bb" "bc" "ca" "cb" "cc" "aaa" "aab" "aac" "aba" "abb" ...
(I had posted some lazy examples here but they were holding onto the head, so I deleted them, so others don't copy them.)
(defn permutations [els]
(when-let [[f & r] (seq els)]
(let [perms (permutations r)]
(cons [f] (concat perms (map (fn [r] (cons f r)) perms))))))
I guess you can
(defn permutations-str [els]
(when-let [[f & r] (seq els)]
(let [perms (permutations-str r)]
(cons (str f) (concat perms (map (fn [r] (apply str f r)) perms))))))
will that trigger any of these concat warnings stuart was telling me about
hmm I’m not sure this is right
I want to generate them in order
ah no wait in the other order
like all the single characters, then the doubles then the triples
(defn- boop [i]
(case i
0 nil
1 (map str "abcdefghijklmnopqrstuvwxyz")
(for [x "abcdefghijklmnopqrstuvwxyz"
y (boop (dec i))]
(str x y))))
(take 100
(->> (range)
(mapcat boop)))
You're just reading it upside down!
looks like the idea from @vlaaad will work
that's going to be very expensive on the recursive subcalls, but I guess if i
is small that's not a big deal
will that do the requisite lazy seq caching
does this work for your needs?
:where `(fn [{tbl# :table
qs# :query-seq
qcnt# :query-count}]
(and (= qs# qcnt#)
(= tbl# ~tbl)))
the given solutions all seem very bad given that it sounds like what you have is just mapping numbers to strings of digits.
I had a counting problem like this once where I wanted to map natural numbers to the column names of an Excel spreadsheet. (a,b,…z,aa,ab). You’d think it would be just a base 26 representation, but it’s not.
I got inspired to try this, and yeah, it's got a few tricky bits beyond the obvious ones...
like making it go from z
to aa
instead of ba
anyone know how to run cli commands from clojure?
@josh_tackett Not sure if it's still the preferred library for this use case, but I've seen https://github.com/Raynes/conch used a lot for that purpose.
@shdzzl I'm trying to use /sh but it just prints it out rather than decrypting it:
(shell/sh "echo" "U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=|openssl" "aes-256-cbc" "-d" "-a" "-pass" "pass:aaa")
I'm going to guess that you can't pipe like that. Does this work?
(shell/sh "openssl" "aes-256-cbc" "-d" "-a" "-pass" "pass:aaa" :in "U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=")
Not at a REPL right now, so can't test.
I'm going to guess that you can't pipe like that. Does this work?
(shell/sh "openssl" "aes-256-cbc" "-d" "-a" "-pass" "pass:aaa" :in "U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=")
Not at a REPL right now, so can't test.
may be as shdzzl suggested as an alternative, conch may work better for this? https://github.com/Raynes/conch#piping
That is definitely better than using shell/sh, but also I found for interactive communication with a process via input-stream and output-streams using Process and ProcessBuilder directly is actually less complicated than using conch
Anyone an openssl expert here?
Not an expert, but the following terminal command decoded correctly for me:
echo "U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=" | openssl enc -d -aes-256-cbc -a -pass pass:aaa
Not an expert, but the following terminal command decoded correctly for me:
echo "U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=" | openssl enc -d -aes-256-cbc -a -pass pass:aaa
@josh_tackett Does the command pipeline you showed work for you when started from a shell prompt?
the problem here is that shell/sh doesn't start an sh (it's somewhat misleadingly named) so there's nothing to interpret |
as an IO redirect or start openssl as a separate process
what was shown above will work at a shell prompt, because you are using an instance of sh which understands redirects and the associated syntax
to do this with clojure.java.shell/sh you need to explicitly use a shell
user=> (clojure.java.shell/sh "sh" "-c" "echo U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=|openssl aes-256-cbc -d -a -pass pass:aaa")
{:exit 1, :out "", :err "bad decrypt\n4469843564:error:06FFF064:digital envelope routines:CRYPTO_internal:bad decrypt:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.200.4/libressl-2.6/crypto/evp/evp_enc.c:533:\n"}
btw that's the same output I get for your command above @shdzzl
Hmm I get a single \n
in :out
from clojure.java.shell/sh
with an explicit shell (`sh`) and the expected result from my terminal emulator
same for my example - notice that :err
had a string but not :out
by changing echo
to echo -n
I get "error reading input file" instead of the digital envelope bad decrypt
not sure what's going on though
(this is both in a normal shell and in clojure via shell/sh)
Could this be it? https://github.com/libressl-portable/portable/issues/378 What happens if you include the "-md" "sha256" param suggested?
that fixes it
user=> (clojure.java.shell/sh "sh" "-c" "echo 'U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ='|openssl aes-256-cbc -d -a -pass pass:aaa -md sha256")
{:exit 0, :out "hola\n", :err ""}
Same, more or less:
user=> (clojure.java.shell/sh "sh" "-c" "echo U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=|openssl enc -d -aes-256-cbc -a -pass pass:aaa")
{:exit = 0
:out = "hola\n"
:err = "*** WARNING : deprecated key derivation used.\nUsing -iter or -pbkdf2 would be better.\n"}
if nothing else, a variation on this
user=> (clojure.main/main "-e" "(+ 1 1)")
2
nil
perhaps there's something more elegant thoughMy question is flawed really. I have something using clojure.main/repl and overriding :eval in order to perform a useful nested repl. I wanted to make it a nested prepl (I have a way of binding the original *out*
so I can nest it) so that I can use it with tooling.
oh, that's a different question yes
user=> (clojure.java.shell/sh "sh" "-c" "echo 'U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ='|openssl aes-256-cbc -d -a -pass pass:aaa -md sha256")
{:exit 0, :out "hola\n", :err ""}
am I right that you can vote on http://ask.clojure.org for issues but not on JIRA? just checking
I recall Alex Miller suggesting that people vote for issues on http://ask.clojure.org, since that is the current supported way to create issues for Clojure and other contrib projects, and creating an account there does not require any manual work by anyone (whereas I believe the new Clojure JIRA has manual effort required for all new accounts, and they might be trying to keep the number of those to a low number, perhaps due to licensing and/or free support tier issues).
This page on http://clojure.org supports that: https://clojure.org/community/ask#_voting
If you’re a user, vote on ask. If you’re a developer with a jira account, vote on jira