Fork me on GitHub
#beginners
<
2016-09-26
>
eslachance01:09:19

:thinking_face: I'm using http.async.client (mostly because I'm now using its websockets) and I'm facing an issue where it's not sending the authentication headers as expected...

(defn send-message [session msg channel]
    (let [client (http/create-client)
          resp (http/POST
                 ; client (str "" channel "/message")
                 client "" ;I'd rather keep that private!
                 :headers {:Authorization (str "Bot " (get @session :token))}
                 :body {:content msg}
                 )]
      [resp])
    )
The body is fine (as you can see I'm using http://requestb.in to check the request, great troubleshooting tool), but the Authorization header is not present. Anyone can tell me how I'm derping?

manenko05:09:07

just a guess, but try to use string keys for headers, i.e. :headers {"Authorization" (str "Bot " (get @session :token))}

eslachance11:09:52

And simple as that, @manenko saves the day! Thank you, that was exactly it.

manenko11:09:56

:thumbsup:

joshkh13:09:45

Quick question regarding clj-time that's probably too dumb for stackoverflow. If I have an arbitrary date, how can I specifically set the hour? Something like (at-hour (t/now) 9)? I could write a function but I feel like there's some core functionality that I'm glossing over.

joshkh13:09:33

And if I wrote a function it would require something like (t/date-time (t/year dt) (t/month dt) (t/day dt) hour (t/minutes dt) (t/seconds dt))'which feels verbose, especially if I'm writing a functions for each granularity of a datetime.

psavine4214:09:25

whats the latest on clojure dataflow? it looks like it was around in contrib in v1.2, and now it is deprecated? there is hoplon which is a cljs implementation, and some other libs (pulsar?) but is native support anywhere?

Alex Miller (Clojure team)15:09:52

you might want to look at core.async for that kind of thing

seancorfield15:09:24

@rodeorockstar Feel free to open a GitHub issue on clj-time suggesting that enhancement… You’re right there’s nothing like it right now. The closest would be with-time-at-start-of-day and then add the hours as a period I think...

josh_tackett16:09:11

@seancorfield Do you know how to do a lein clean on heroku?

seancorfield16:09:30

@josh_tackett Sorry, no clue. I don’t use Heroku (beyond experimenting to get an instance up and running a Clojure program years ago).

josh_tackett16:09:57

@seancorfield No matching method: sha1Hex, compiling:(taoensso/carmine.clj:156:20)

josh_tackett16:09:07

I’m having this issue

josh_tackett16:09:13

lein deps :tree looks good though

seancorfield16:09:20

Sounds like a version conflict. Have you tried :pedantic?

seancorfield16:09:44

That sha1Hex error rings a bell… I don’t remember the fix tho’, sorry.

josh_tackett16:09:42

lein deps :pedantic returns nothing

codefinger17:09:29

@josh_tackett run heroku config:set LEIN_BUILD_TASK=“clean compile”

codefinger17:09:29

err, maybe uberjar instead of compile

seancorfield17:09:57

@josh_tackett You’d need to put :pedantic? :abort in project.clj and then run lein deps I think. I don’t use Leiningen these days but I think that’s the approach. https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L74-L78

josh_tackett17:09:06

it looks like it won’t help with this issue

dominicm17:09:47

It won't start lein if you have unresolved conflicts

josh_tackett17:09:07

@dominicm I added that and it runs fine with lein run

josh_tackett17:09:18

the issue is happening when I run travis

dominicm17:09:45

Perhaps not competing dependencies then. What does Travis do different?

josh_tackett17:09:27

Figured it out

josh_tackett17:09:37

it was another module of our project that was built in Java

josh_tackett17:09:41

it was throwing the error

josh_tackett17:09:52

and pushing up through since it is also a dep for me

psavine4218:09:25

@alexmiller thanks you are right - totally derped there/

pawel.kapala21:09:29

I have a threading macro -> I want to finish at some point based on a function parameter n:

(defn step-until [n]
(-> foo
     step1 
     step2
     step3
     step4
     step5))
For (= n 2) I’d like to execute until step3 I’m reading about cond-> but I don’t know how to apply it here. Is there a good soul with an idea how to do it? Thanks!

pawel.kapala21:09:46

Naively I’d write:

(defn step-until [n]
(cond-> foo
   (< 1 n) step1
   (< 2 n) step2
   (< 3 n) step3
   (< 4 n) step4
   (< 5 n) step5))

jswart21:09:22

-> nor cond-> is a loop. Does something else run step-until in a loop?

jswart21:09:33

if so, maybe have that decide to quit at n == 3

pawel.kapala21:09:29

no step-until is not intended to be run in a loop

jswart21:09:03

So you are passing in a number, and you want that many steps to execute?

pawel.kapala21:09:19

indeed you got me here it is loopish in behaviour, but I have a set of different steps

jswart21:09:28

If you are only doing side effects, you could replace for with dotimes.

jswart21:09:50

I would likely not have ended up with this particular structure though, because it feels very foreign to me.

pawel.kapala21:09:21

no side effects here, i have a single map, that i pass to a number of functions...

jswart21:09:44

But you also have state right?

jswart21:09:49

you are updating the hashmap

jswart21:09:51

well “state"

jswart21:09:54

as it were

pawel.kapala21:09:05

yeah in that sense it’s a state

jswart21:09:36

Yeah, so i would likely do it in a reduce

jswart21:09:47

if I need to keep the values

jswart21:09:54

i wrote a blog post about it

pawel.kapala22:09:05

thanks, but I still don’t see how reduce would end multi-step map transformation at certain point.

jswart22:09:24

boot.user=> (doc reduced) ------------------------- clojure.core/reduced ([x]) Wraps x in a way such that a reduce will terminate with the value x

jswart22:09:28

or you can do it manually

jswart22:09:41

You could also put the map in an atom

jswart22:09:19

Odds are though there is a completely different way to write this code such that none of this is an issue.

jswart22:09:23

or maybe not

jswart22:09:26

I don’t have much context

pawel.kapala22:09:38

sure, thanks anyways!

pawel.kapala22:09:11

it goes down to the data I think 😉 I think I’ll include the step number in the map as it’s meaningful (it’s queried upon)

jswart22:09:38

makes sense

jswart22:09:32

Just out of curiosity what are you doing? What is the larger context?

pawel.kapala22:09:24

I’m practicing basics of the language

pawel.kapala22:09:47

I’ll post it on github soon enough 😉

jswart22:09:51

Ah I see, well good luck!

jswart22:09:14

Also try checking out some-> that might also do what you want.

pawel.kapala22:09:42

@jswart thanks mate! you helped alot, I went with reduce, but here’s the twist I’m passing a collection of partials from the initial threading macro to the reduce and take n from that collection before passing to reduce to get the desired effect. Good ‘ol reduce always does the job 🙂