This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-13
Channels
- # aleph (16)
- # announcements (8)
- # aws (5)
- # babashka (54)
- # beginners (48)
- # calva (7)
- # cider (7)
- # clojure (209)
- # clojure-brasil (4)
- # clojure-europe (20)
- # clojure-italy (12)
- # clojure-nl (21)
- # clojure-uk (69)
- # clojurescript (24)
- # cursive (11)
- # datascript (7)
- # datomic (47)
- # emacs (14)
- # graphql (20)
- # hoplon (25)
- # jobs (1)
- # kaocha (1)
- # leiningen (14)
- # meander (7)
- # off-topic (44)
- # other-languages (1)
- # pathom (20)
- # re-frame (2)
- # reagent (51)
- # reitit (3)
- # remote-jobs (1)
- # shadow-cljs (46)
- # spacemacs (5)
- # sql (65)
- # tools-deps (86)
- # vim (11)
[SOLVED] nevermind I googled how to do it in Java again, and actually used the correct method now! I ended up using
(:import (org.apache.commons.codec.binary Base64))
(c/get url {:headers {"Authorization"
(str "Basic " (Base64/encodeBase64String (.getBytes (str email ":" token))))}})
Original: How do I do this in clojure : echo -n :topsecreted12341234agfawerf | base64
@gbson If you need to do this from the command line for whatever reason, bb also has java.util.Base64
:
$ echo -n :topsecreted12341234agfawerf | bb '(String. (.encode (java.util.Base64/getEncoder) (.getBytes (read-line))))'
"bm90bXllbWFpbEBnbWFpbC5jb206dG9wc2VjcmV0ZWQxMjM0MTIzNGFnZmF3ZXJm"
The first library I tried using was java.util.Base64 but then I ran into some classpath bugs possibly with IDEA / Cursive which made the whole JDK invisible to Cursive (it still worked tho). Since the IDE had the apache commons libs in sight I misused them and then used them correctly 😄
sounds like you have a lot going on 🙂
echo "bytes to encode" | clojure -e '(-> (java.util.Base64/getEncoder) (.encodeToString (.getBytes (slurp *in*))) println)'
Ynl0ZXMgdG8gZW5jb2RlCg==
echo "bytes to encode" | base64
Ynl0ZXMgdG8gZW5jb2RlCg==
🙂 I wonder if there is something cursive related that messed up your classpath? I'd debug that before making workarounds your code
Yeah it seems to be I reported it there, I could work around it by switching the JDK to v1.8 and then it found everything
Hi guys, I wondering what are these thing "MongoOptions" "SeverAddress" why have this "^" and why can be before the name of a variable?
Thank you!
How would i go about doing this? Any help would be appreciated. Ps. I really like Clojure
there’s a couple different approaches, but just to provide an example
(defn eval-not [input]
(let [[-not [-and x y]] input
new-form `(or (not ~x) (not ~y))]
new-form))
okay, interesting. is there a way you could do it with the code i already provided? (the cond example)
that ` form is going to create a bunch of namespaced symbols in the output
here’s an example that avoids the backtick
(defn eval-not [input]
(let [[-not [-and x y]] input
new-form (list 'or (list 'not x) (list 'not y))]
new-form))
if you’re rewriting expressions, then the backtick, ` , can be very helpful since that’s what its purpose is*
when I use this on a cli curl -X GET '"https://reqres.in/api/users?page=2' -H 'API-Key:MySecret' I get the correct json results in clojure snippet (client/get "https://reqres.in/api/users?page=2" {:headers ["API-Key" "MySecret"]}) it fails to clj-http: status 401 what am I doing wrong? I have been all over the clj-http github docs but ....
{:headers {"API-Key" "MySecret"}}
-- it's a hash map, not a vector.
one tactic to note the difference is to use netcat, nc
@dev.4openid see the examples here https://github.com/dakrone/clj-http#get
eg. nc -l 1234
then, curl -X GET '"
followed by nc -l 1234
(client/get "
that may help you pinpoint exactly what is the difference in payloads
@smith.adriane I'm not sure what you're suggesting -- nc 1234
is not a valid command on macOS:
nc: missing hostname and port
oops 😬
nc -l 1234
also [] for :headers is not valid
I said that above ^
{:headers {"API-Key" "MySecret"}}
-- it's a hash map, not a vector.
thanks @seahckr
it worked!
@smith.adriane In this case nc
doesn't help because the client/get
call (in clj-http
) fails before it even sends the request (because the :headers
argument was wrong).
But it seems like a neat trick for requests that do get through. How would you send back a valid response to the client tho?
cat valid-response | nc -l 1234
Right, but you'd need to know how to write a valid HTTP response -- that's what I'm asking you to elaborate, so that other beginners here can use that trick for testing.
I’m actually not sure how to send back an* *in*valid response
it depends on what the client is expecting
echo "HTTP/1.1 200 OK" | nc -l 1234
That will send back a success status and an empty response which might be enough for testing.typically, for this type of debugging, I don’t worry about generating a valid response. it’s mostly for comparing requests to figure out* exactly how they differ
you can probably use something like ncat -l <port> -c "tee log | ncat
or something (but at this point just using tcpdump seems easier)
looks like I will have to dive in with wireshark to see the differences?
or maybe use mitmproxy? bit of a fiddle around?