This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-27
Channels
- # arachne (1)
- # beginners (31)
- # boot (84)
- # cider (9)
- # clara (2)
- # cljs-dev (102)
- # cljsrn (20)
- # clojure (254)
- # clojure-belgium (1)
- # clojure-dusseldorf (17)
- # clojure-greece (7)
- # clojure-italy (6)
- # clojure-russia (2)
- # clojure-spec (8)
- # clojure-uk (9)
- # clojurescript (93)
- # component (4)
- # copenhagen-clojurians (1)
- # cursive (24)
- # datomic (22)
- # editors (1)
- # emacs (8)
- # garden (2)
- # hoplon (357)
- # lein-figwheel (1)
- # leiningen (4)
- # luminus (27)
- # mount (13)
- # off-topic (7)
- # om (71)
- # onyx (35)
- # planck (3)
- # re-frame (53)
- # reagent (35)
- # ring-swagger (24)
- # specter (10)
- # sql (6)
- # untangled (47)
- # vim (157)
Hi, I’m trying to specify a lib’s fn as a config value in an edn-based configuration (duct-framework). I’m successfully able to specify vars directly in the map, such as {:components {:app duct.component.handler/handler-component}}
, but one specific var (`fixtures.adapters.jdbc/jdbc-adapter`) returns a no class found exception. However, I’m able to use that var if I do the following in the REPL: (require ‘[fixtures.adapters.jdbc]) (fixtures.adapters.jdbc/jdbc-adapter)
. I haven’t had to specifically require other vars in the map. Does anyone know why this one var would have an issue?
link to the actual namespace: https://github.com/banzai-inc/fixtures-component/blob/master/src/fixtures/adapters/jdbc.clj
Hi! What is the best way in Clojure to have atom
with overridden IDeref
implementation? Like what I achieve by ClojureScript's specify!
:
(defn wrap-atom [x & m]
(specify! (apply atom x m)
IDeref
(-deref [this] ...)))
Creating a new type (with deftype
or reify
) that wraps your atom, and implement all atom methods...
Thanks, reimplementing all stuff is the thing I wanted to avoid, but if it's not possible I'll do...
@ul you could possibly extend clojure.lang.Atom using proxy
so that you only need to override the one specific method. I've not actually tried doing that though so y'know
Sadly it fails with CompilerException java.lang.VerifyError: Cannot inherit from final class
@currentoor Just an fyi, you can put hiccup into html mode to get the exact behaviour you want, e.g:
boot.user=> (html {:mode :html} [:script {:src "demo_async.js" :async true}])
"<script async src=\"demo_async.js\"></script>"
Hi. Does Clojure include a Clojure parser? One which converts a Clojure file in a data structure which can be analysed? The data structure needs to be complete, which means it needs to have all the used whitespace characters and comments. So that the originally parsed source file can be restored exactly as it was. Is there something like this included in Clojure oder do I have to look for libraries?
@rarous Do you mean the read-string function from tools.reader? Or is there anything else included which would provide me the desired behavior?
Because (read-string (1, 2))
provides (1 2)
. But I need a data structure which gives me information what was parsed and also the ,
separator I have used...
Do you need to analyze the whitespace and comments?
curious
I would guess that most of the parser functionality you'll find will ignore stuff like that. If you need to "restore" the originally parsed source file, can you not just persist the source itself? 🙂
I need to read a Clojure file, make some changes and then write back the whole file. For doing the changes I need a parser which understands EDN. But it must preserve the file layout, which includes all the whitespacing an comments. All the readers I found so far loose all the file layout 😞
Input: (1, 2) ;; test
. Desired output (something like this): [{:type :list :elements [{:type :number :value 1} {:type :whitespace :value ", "} {:type :number :value 2}]} {:type :whitespace :value ";; test"}]
@witek I think you're looking for https://github.com/xsc/rewrite-clj
There's also https://github.com/rundis/rewrite-cljs which has less features. Depends on the environment you're in. 🙂
Awesome!
Q about naming conventions: a common recommendation is to call fns the noun they represent. However, if I call the fn that returns a product
(defn product [])
, what do I call the let bindings that I assign products to?
- product
: shadowing, dangerous when refactoring, surprising bugs
- product*
: works but strange
- prdct
(intentional misspelling): even stranger
- a-product
: I guess that works but I feel a bit uneasy
which way out of this dilemma (quadrilemma) do you prefer?
@pesterhazy: @ztellman writes eloquently about these matters in https://leanpub.com/elementsofclojure
I just really wish he would finish his frontend-server https://www.youtube.com/watch?v=_1rh_s1WmRA, so he could finish up the book, I’m so looking forward to the next chapters 🙂
@pesterhazy from your (minimal) example, I do believe @ztellman would say that if your product
function pulls data from another scope (like a database) it should be called get-product
(or if defined in a foo/bar/baz/product
namespace, just get
)
if it on the other hand converts something to a product, it should be called ->product
@pesterhazy but the whole first chapter, which is on the topic of naming, is downloadable for free.
@pesterhazy p
? if let
is not that huge, that works most of the time for me. (and products would be pp
)
on the other hand I'm not entirely comfortable having a product
function in the first place.
I think convention is [shorthand]s for a sequence of things, so ps
would perhaps be more idiomatic there @misha
@dominicm true, however I find myself stumble upon xs
a lot, and xx
goes much smother.
but I'd say "follow project's existing style guide, unless it is outrageous"; and in your private repo no one will hear you scream
@misha I don't understand what you mean by:
> stumble upon xs
a lot and xx
goes much smoother
@slipset, I did read (and liked) the first chapter of the @ztellman book, but you still run into issues with naming clashes
so the solution would be not to use simple nouns as fns?
interesting...
https://github.com/dakrone/clj-http Is there a way with this library to view the request that is being made? I am making a request successfully in postman but the same request with this library isn’t working
@josh_tackett If the library doesn’t support it, you could always look at the requests using something like wireshark
@dunn.mat that’s a good point
I’m just trying to figure out the difference between postman and this lib
postman works well
but the lib doesn't
@josh_tackett :debug true?
i want to say postman does some hackery to work around CORS things so it won't be doing the same request in both instances
postman:
GET /sap/c4c/odata/v1/c4codata/ HTTP/1.1
Host:
Authorization: Basic <user>:<pass>
x-csrf-token: fetch
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 2381b22d-8330-040d-139c-3fb4fd31deb8
i had a vagrant machine running a service that postman was hitting but i couldn't hit from my local machine because of CORS. Is there any way to check the response? My suspicion is the error message might be instructive
(http/request
{:method :get
:url (str " ")
:headers {"Authorization" (str "Basic " (base64/encode “<user>:<pass>"))
"x-csrf-token" "fetch"
"Content-Type" "application/json"}
})
@dpsutton there is no error, postman works
just a difference between my request and postman
@bfabry Awesome 🙂
{:user-info nil,
:use-header-maps-in-response? true,
:body-type nil,
:debug true,
:headers
{"Content-Type" "application/json",
"x-csrf-token" "fetch",
"Authorization" "Basic QURNSU5JU1RSQVRJT04wMTpXZWxjb21lMQ==",
"accept-encoding" "gzip, deflate"},
:server-port nil,
:http-url
" ",
:uri "/sap/c4c/odata/v1/c4codata/",
:server-name "",
:query-string nil,
:body nil,
:scheme :https,
:request-method :get}
GET /sap/c4c/odata/v1/c4codata/ HTTP/1.1
Host:
Authorization: Basic QURNSU5JU1RSQVRJT04wMTpXZWxjb21lMQ==
x-csrf-token: fetch
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 2381b22d-8330-040d-139c-3fb4fd31deb8
/sap/c4c/odata/v1/c4codata/ HTTP/1.1
must be this extra HTTP/1.1
not sure how to get that into a request those with clj-http
Hello folks, does anybody know if there is a lib out there using log4j2
as logger already?
I actually think I've had a surprising thing where it turned out postman was using cookies and I didn't realise it before
Might be worth adding it to clojure.logging
maybe
tried using this stuff https://github.com/dakrone/clj-http/blob/master/README.org#basic-auth instead of rolling your own basic auth params?
oh, found something... https://github.com/gja/clj-log4j2h
@bfabry they don’t use basic auth though
they use a base 64 encoded request
@bfabry any way to add the HTTP/1.1 at the end of the url?
I think that’s my issue here
its the difference between the requests
I'd be surprised if it was, that's just the normal get request scheme afaik, clj-http should be sending it the same
{:requestLine
#<BasicRequestLine GET https://my307174.crm.ondemand.com/sap/c4c/odata/v1/c4codata/ HTTP/1.1>,
:protocolVersion #<HttpVersion HTTP/1.1>,
:params
#<BasicHttpParams org.apache.http.params.BasicHttpParams@149f0852>,
:method "GET",
:config nil,
:class org.apache.http.client.methods.HttpGet,
:allHeaders
[#<BasicHeader Connection: close>,
#<BasicHeader Content-Type: application/json>,
#<BasicHeader x-csrf-token: fetch>,
#<BasicHeader Authorization: Basic <user:pass>>,
#<BasicHeader accept-encoding: gzip, deflate>],
:aborted false,
:URI
#<URI https://my307174.crm.ondemand.com/sap/c4c/odata/v1/c4codata/>}
Ah you’re right it is sending it that way
it is getting a response, but the token is not valid to do a write
this doesn’t make any sense
post man is working and clj-http is not
and the requests look the same
@jr response looks good
it’s XML though
@bfabry how do you test that?
@bfabry Postman doesn’t have incognito
I just have the app downloaded
right
@bfabry do you know how to send a curl request from clojure
no, that'd be a cool tool though, something that translated clj-http requests into a curl request line
I am getting a successful response. Then when I try to use the toke from the reponse to make a write request, I get a 403 @dpsutton
and even if I take the token from the GET in clojure and use it for the write POST in postman, it doesn’t work
is it possible it is deserializing the token incorrectly? perhaps when stringifying it or turning it into the map with keys, it is incorrectly doing something with the key?
also, when making the write request with the token from clojure but sending the request from postman, what was the response? how did you know that it did not work?
@dpsutton is it possible it is deserializing the token incorrectly? perhaps when stringifying it or turning it into the map with keys, it is incorrectly doing something with the key? I bet this is the problem!!! also, when making the write request with the token from clojure but sending the request from postman, what was the response? how did you know that it did not work? I got a 403
I bet the response is reading the token incorrectly
now the question is how to get the write one
good questoin
pass true where?
ya cheshire is for JSON
like if you ask for the token from both clj and postman, would it show the same token?
so postman keeps sending back the same token
but clj is a different token everytime
4kesF5SwynJXyrrFMFsRdw==
4kesF5SwynJXyrrFMFsRdw==
yep postman there
WiH7ebper13BBPhCJQripg==
FJJmv1wuyca_mp123Mc2YA==
clj there
changes every time for clj
how can I view that cookie?
ostman v0.8.x can display browser cookies as it shares the same environment with the browser. For the packaged app, you’ll need to enable the Interceptor. You can then view response cookies in the “Cookies” tab of the response section. Refer to the sandbox documentation for info on how to access cookies in the pre-request/test scripts
alright one sec
ah found some cookies…yum
where did these cookies come from though?
I bet yes
but obv Postman is doing this on its own
so I need to do the same in clj
ok found the cookies
how do you add cookies to an http request?
with clj
awesome
let me give this a shot
I’ve never really dealt with cookies
I’ll need to read about that bit myself before I ask you guys
I would humbly suggest cookies aren't generally considered a good way to interact with an api, so unless you're forced to use them I would try not to
@bfabry I am dealing with SAP and it seems that cookies are the only option right now haha
I just need to do a POC here
will pound out the production system after we get POC
hahahahha
exactly
success 🙂
great work guys
I really appreciate the help
time to pipe this baby through the system
hmm first time I run into this:
(-> (into (sorted-map) {1 1})
(get :foo)) ;; ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword
that is surprising. I guess you can't have a sorted map of things are are incomparable so you can't look in a sorted map for a thing that could not be in it
Shouldn't setting *print-namespace-maps*
to true cause namespaced maps to print without the reader shorthand or am I misunderstanding how *print-namespace-maps*
should work? This is in a vanilla Clojure REPL
Clojure 1.9.0-alpha13
user=> (binding [*print-namespace-maps* true]
{:db/id 1 :db/ident :foo/bar})
#:db{:id 1, :ident :foo/bar}
I want it to print:
{:db/id 1 :db/ident :foo/bar}
okay, so im back to the ongoing task of wrapping my head around channel logic. I am again running into a situation where I feel like I would be well served by a "closed?" function. But I am vaguely aware that this is a frowned upon concept, because querying a channels open/closed state leads to bad design. However, there's this concept of a "timeout" channel in the api, which automatically closes after n milliseconds. How else would one use such a construct other than by querying whether or not the channel has yet closed? This is very relevant to what im currently doing: forwarding data from a socket connection with a timeout.
so either recur on this go-loop after N seconds or take the result of an async operation before N seconds or bail
it’s just a way to force an async operation to bail after a timeout has exceeded. I’m not sure what you mean like a load balancer
im trying to figure out what alts does in general in order to figure out how you used it to implement a "bail after n milliseconds" situation
if you want to just share with me some psuedocode on how you did that, i could also study it that way
(let [[ch result] (alts! [channel-receiving-async-io (timeout 2000)])
(do-something-with result))
that ensures that channel-receiving-async-io
does not exceed timeout and if it does then will contiue computing
ya, that's why you don't need to check if it's closed?
, in any place you're using it you're using blocking waiting for either it or something else
timeouts are a good way to not saturate a go routine and prevent it from context switching
thanks a bunch. thats excellent. Yeah, with the addition of alts to my repertoire, I can definitely see how polling status is not the best plan
Think of it more as a pipeline and when you try operating on a closed channel then nothing will be produced
yeah, thats how I sort of think about it, but then I saw another person in this thread https://groups.google.com/forum/#!topic/clojure/_KzEoq0XcHQ suggesting that operating on a closed channel was a programming error. which seemed incompatible with the idea that the producer is in charge of closing the channel
so if you stick to the core functions and compose them then you will not receive a nil value from the channel
interesting. ill toy around with it a bit to try to flesh out that philosophy in my head a bit more
but generally if you’re sniffing for a nil coming through a channel (or want to know if it is closed) then you are using the wrong core.async functions
I will actually probably use this in some work I'm doing with directed graphs, actually, if you dont mind, @bcbradley
i'm eventually gonna build a library out of this and a few other things i've got cooking
then taking those in the sets (those that don't depend on eachother at that stage in the pipeline) and exeucting them concurrently
try it with this if you wanna see it in action: (organizer {1 #{2} 2 #{4 3}} [1 2 3 4])
ahh, yes interesting. My use is actually in reactive programming. so, when a value changes, all values that depend on it are updated
so @jr going back to the earlier stuff, how would i express the following idea: do this forever until in-chan closes: (>! out-chan (<! in-chan))
heres what is going on here. I get stuff from socket a, and i put it into socket b until socket b gives me a response, then i take that response and put it in socket a
so, its like
"connect returns two channels for input and output"
(let [[a-in a-out] (connect "a-host" "a-port")
[b-in b-out] (connect "b-host" "b-port")]
(go (>! a-out (alts! (timeout 1000) b-out (go-forever (>! b-in (<! a-in)))))))
the imperitive description is "if we get a response from b, put that on a. if we timeout, put that on a. otherwise, keep putting stuff that shows up on a into b"
but i think in the above scenario, doesnt this make that go-block run forever, even after the alt has completed? unless I tell the go-forever block to poll whether or not the a-in channel is closed?
or maybe i just test the returned value of the <! operation, because that operation returns nil if the channel is closed?