This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-10
Channels
- # beginners (191)
- # boot (3)
- # cljs-dev (2)
- # clojure (46)
- # clojure-austin (1)
- # clojure-spec (4)
- # clojure-uk (32)
- # clojurescript (10)
- # clojurewerkz (3)
- # cursive (14)
- # datomic (88)
- # defnpodcast (1)
- # editors (2)
- # fulcro (2)
- # hoplon (3)
- # jobs (4)
- # jobs-discuss (1)
- # luminus (5)
- # lumo (6)
- # off-topic (13)
- # random (1)
- # re-frame (50)
- # reagent (245)
- # remote-jobs (1)
- # spacemacs (3)
- # specter (16)
- # uncomplicate (4)
i’m having trouble getting oauth2 to work in a luminus app. when I enter:
(clj-http.client/post ""
{:accept :json
:as :json
:form-params {:grant_type "authorization_code"
;; :code (get-in request [:query-params "code"])
:redirect_uri "/oauth2/twitter/callback"
:client_id "uFRreriTqef12qT1kwIQsz0as"
:client_secret "a1VS3EnuXpXlNmUME0HEuqtvt7cdQWGEKfIp1gozt57aje6iHx"}})
in the repl, i get a warning about an invalid “expires” attribute:
Sep 09, 2017 11:59:30 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "set-cookie: personalization_id="v1_vCZhEFIjziUVMdDtMGBTdQ=="; Expires=Mon, 09 Sep 2019 23:59:30 UTC; Path=/; Domain=.". Invalid 'expires' attribute: Mon, 09 Sep 2019 23:59:30 UTC
Sep 09, 2017 11:59:30 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "set-cookie: guest_id=v1%3A150500157038061890; Expires=Mon, 09 Sep 2019 23:59:30 UTC; Path=/; Domain=.". Invalid 'expires' attribute: Mon, 09 Sep 2019 23:59:30 UTC
ExceptionInfo clj-http: status 401 slingshot.support/stack-trace (support.clj:201)
i’m not sure how to proceed. my goal is just to get the http POST working, but i’ve never done this before, so I’m at a loss as to how to give it the correct attributes.the cookie warnings are caused by the other end
the error is a 401
indeed. but i’m sure i’m doing one or more things wrong; i trust twitter’s api more than i trust myself.
it could be that your form params aren't being translated to the precise keys the other end needs
I don't trust auto-conversion of eg. :client-id to "ClientId" or is it supposed to be "clientId"
or "Client-ID"
all of those are valid, why use keywords?
use the actual string your endpoint wants
@mfm my app uses clj-oauth 1.5.5 to get twitter oauth, you could check what their code looks like (or justuse that lib)
It depends on how you look at it, I suppose, but life is mutable from my point of view. Things change.
@mfm it's a closed source Saas that uses twitter heavily
but this is the lib we use for oauth https://github.com/mattrepl/clj-oauth/blob/master/src/oauth/client.clj
dumb question: i have to choose either oauth or oauth2? most people talk about “oauth”, and i can’t tell if they’re talking about oauth-and-its-relatives, or exclusively oauth.
@mfm but really if you know what a successful request should look like, precisely (and knowing twitter they show you that usually) just using the actual string in the request data instead of a keyword reduces a bunch of silly problems in my experience
don't use keywords for aesthetic reasons
and values in a request aren't symbolic constants and aren't there primarily for your code to look up
But, because state is a dangerous animal, an animal that has bitten some of us in the past, we want to lock it in a box.
A friend who uses erlang always give me hints, and he always said... you must isolate the state... always isolate things on their on context with their own states, isolate all
I'm learning isolating things, but that doesn't mean it's the right one or the best one
Yes.. I'm new at this FP world, clojure world, and I'm really enjoying it.. the country where I live I think it's still not that strong.. but.. i like it
Same here @rcustodio
It's really good to have someone who does the right thing (as possible) and teach the others to do it
Much of what I do for a living is deal with time... it sounds simple, but in fact time is difficult.
My question is, beyond the inherent benefits of FP and Clojure (immutability etc.), are there good selling points for integrating more Clojure calls into an existing Java codebase? I’m still a student, so I don’t have particular experience to better frame a situation, just looking for opportunities in a couple of upcoming projects
fewer lines of code = fewer places for bugs to hide
you can code clojure without a monster of an ide doing 3/4 of the work for you
and of course, clojure and java can each call the other easily, so it is straightforward to build out clojure in existing java code
Ha, true I suppose. I figure trying to sell tangential benefits within Java might be easier than selling another paradigm to OOP mindets
tangible benefits include better concurrency support than mainstream java approaches, and it's much easier to write ETL style data in / data out code in clojure with all the built in data transformation functions
@tagore wouldn’t any programmer be able to write Clojure if they spent some time reading the doc?
Not likely (probably won’t invest the time), it would probably just be me trying to get approval to implement my functionality with clojure and convince them to make the calls in their code
I've definitely seen clojure delivered as part of a java app without getting approval to do a clojure project ("hey you didn't say we couldn't use clojure.jar to generate bytecode") but not every company would take that in good humor
I've seen ColdFusion developers transition to Clojure -- and ClojureBridge takes beginners and gets them started on Clojure. So, yes, any programmer should be able to write Clojure. Whether you can convince any specific programmer to learn Clojure is a separate issue tho'...
@hmaurer Kind of. But that doesn't mean any shop could just switch to Clojure painlessly.
Look, I hate writing Javascript as much as the next guy, and I wish my shop were a Clojure shop.
This is a good talk for considering ways to introduce Clojure: https://www.youtube.com/watch?v=2WLgzCkhN2g
I wrote this piece just over four years ago that talks about "enterprise" companies and how radical Clojure is: http://seancorfield.github.io/blog/2014/09/23/clojure-in-the-enterprise/ (note also the piece I link to by Eric Normand)
But the reality is that we're taking a bridge looking toward a series A, and everyone I work with will be out of a job if we don't close both.
(my blog post also links to Neal Ford's talk at the end, I just noticed)
(JavaScript mutterings and the "joys" of startup funding all belong in #off-topic -- not in #beginners -- this channel is supposed to be somewhere folks new to Clojure can ask beginner questions about Clojure and get specific answers)
@mjcleary Wanted to check you saw the link to Neal Ford's talk and my blog post about introducing Clojure?
@seancorfield OK, sorry- the thing is that many beginners do want to ask about their prospects, and the nature of the industry.
I'm not sure what you mean by "JavaScript mutterings" I'll be sure to let all of the Javascript programmers I know that you feel that way though 😉.
But I'll refrain from saying anything in this channel that isn't a matter of specicific answeres.
And if folks ask about non-Clojure topics, feel free to direct them to a more appropriate channel...
There's also a #jobs-discuss channel that's probably a good venue for general discussions about the Clojure job market, how to find a Clojure job, which companies are doing what with Clojure(Script) etc.
Never can seem to find this. I'll write it down next time. What's the easiest way to write a big clojure data structure (map) to a file or db and read it back later.
the way that is the least work is to use pr-str
to create the text, and write that to the file, then use read-string
got get it back
there are a couple of problems with this, one level of improvement is to use clojure.edn/read-string
or better yet make a Reader from the file and use clojure.edn/read
, but the best option is actually to use cognitect/transit
to do the write and read, this is better because it’s actually optimized for performance and it’s extensible without global config for any type you would like to put in a file, as long as you can make an appropriate reader and writer function. transit also uses a format that people can easily consume from other languages (it has bindings for quite a few popular languages already)
https://github.com/cognitect/transit-clj
I wrote a library to simplify dumping data to a file using transit, and then get it back. The main intended purpose is to simplify grabbing data from the repl and using it in unit tests or regression tests https://clojars.org/org.noisesmith/poirot
all of a sudden I found edn/read-string and it mentioned prn-str, so think i'm good.
hey guys are there any books or texts you'd recommend for learning how to "think in clojure", so to speak? does it just come over time from doing it or are there any texts that gave you an "a ha" moment, thanks
I recommend any talk given by Rich Hickey!
"Simple made Easy" if you haven't seen it yet (even if you have watch it again 😉) https://www.infoq.com/presentations/Simple-Made-Easy
If you don't mind videos, I also recommend the entire "MIT 6.001 Structure and Interpretation" (1986) course, don't be fooled by the date, the concepts are extremely important! https://www.youtube.com/watch?v=2Op3QLzMgSY
There's also a book: https://mitpress.mit.edu/sites/default/files/6515.pdf
cool, thanks friends. i've been watching a bunch of rich hickey talks and they have been helping. will check out the MIT one as well, thank you
@noman Good to have the concepts, but the only real way to think clojure (or maybe functional) is to do it. So if functional is new to you, just do stuff. http://4clojure.com was what helped change my brain.
Thanks I'll check out this site. I have some familiarity with thinking functionally from writing modern js and react code but clojure is on a whole other level.
@au-phiware Thanks for the suggestions! I am almost finishing Rich’s talk and he just said something that made me intrigued. He says that we should not entangle components together, we should use queues instead and make them “independent islands”.
How do I apply this in the context of a request/response architecture? I mean, the function that receives the request must call something in order to get that request processed and return a response
It is a difficult question to answer without more specific circumstances... In one respect a server/client architecture has already created "independent islands", and is already asynchronous (client sends request and at some later time the server sends a response). However, I think you might be asking about the design of the server? Again it very much depends on the work that needs to be done in order to serve a request. But let's say there's some shared resource, say a database, and there is a contract or interface that you have defined for the shared resource. There may ways you could fulfill that contract, some of them will be asynchronous, some of those might involve callbacks and others might involve locks. To use queues or channels, your database might wait for requests to flow in on a channel, perform the work to fulfill the request and place the result on an outbound channel provided as part of the request, where the requester is ready and waiting for the result on that channel. I fear this is a rather long winded reply... Channels are a powerful concept, it allows you to shunt data around your app and focus on your data structures instead of your method signatures. HTH
How do you make it async by pushing the request into a queue? This reminds me of Node.js and callbacks
Does it make sense on such a small example?
i just listened https://www.youtube.com/watch?v=VNTQ-M_uSo8 he said he works on clojure, spec and contractor and consultant How can he manage all those things? it took me 40days of 5+ h/day to build my first app with reagent
Stu is one of Clojure's "elder statesmen" and he's a phenomenally smart dude -- superhuman! A lot of this is also the 10,000 hours thing. You get good at stuff by just doing it a lot and always be learning.
I started doing open source work in the early 90's and it's something I always make time for so that I can keep learning beyond whatever work throws at me.
And I make an effort to read technical books outside work and to learn a new language every year or two.
Back in the day I would also save up and send myself to conferences or take training courses -- investing in myself. That's how I learned Clojure: a $200 workshop one Saturday. Totally worth the out of pocket expenses.
A few years ago I sent myself to PyCon because I wanted to learn Python. One year I managed ten conferences (because several were local and fairly cheap).
Mostly now I just go to Clojure/West and Clojure/conj -- totally worth it, if you can do it.
you are super human too you manage to chat you manage to help beginners you manage to contribute to opensource you manage to make money my god when i grow up i wanna be like you xD
I'm flattered 🙂 To be honest, it's just about being mindful of how you spend your time: a few minutes on Slack here, a few minutes on the mailing list there, an hour reading a book instead of watching TV/playing games, carving out 30 minutes here and there in your work week to look at FOSS projects or read blogs or watch an online talk. Start early, make it a habit.
UI coding is a rather big time sink, one of the reasons I try to avoid it.
Still stretching out my questions/ignorance related to application design in Clojure… I am kind of lost at the moment. I want to understand some ways of organizing my code in order to make it as much decoupled as possible. I am not sure about unit testing anymore, is it really worth it in FP? Are the difficulties of async design paid by the benefits of using it? I have a lot of unanswered questions wandering in my brain right now 😱
No one does async design by choice, try to always design synchronously. Only and only if you're problem absolutely requires async should you design that way.
What you want is to keep functions pure and grouped in namespaces by loose association.
You do want unit tests, where the unit is a single function. Those should be to avoid regression.
Thank you, I really appreciate the response 😊 The only thing I’m still really lost is regarding how to design my functions
I mean, how to make them testable if they invoke other functions by themselves
for instance, if I have a ring handler that should extract the request data and pass it forward to another function
this is how I am doing it right now : (defn handler [request] (otherFunction (extract-data request)))
I can’t unit test this, because it is invoke something else, which will in turn invoke something else
and eventually, the database will be invoked
What I can test is the extract-data, for instance
Does it make sense?
There are a range of opinions in the clj/s community about the value of unit testing. Some folks argue that REPL-driven development makes it less necessary; some feel that it's often better replaced by generative testing (which is made fairly easy by clojure.spec); and some feel that they're still very important. I'd say they have the highest value for functions that are most likely to end up with regression errors, ie functions that are likely to change. Tests that hit a DB are classically difficult to unit test. The most common solution, probably, is to replace the DB with a mock DB that'll always contain the same known values. Another useful approach is to separate out the DB function -- the part that's dependent on unknown state -- from the handling of the returned values, which can usually be written as a pure function, which is much easier to test. But that's definitely just my take on it -- there's no universal agreement in the community on the value of unit tests, and the best strategies for writing them.
I see… well, I am looking into some ways of dependency injection in functional programming now
Looks like it’s a good way of making my funcs more testable and pure
instead of just chaining the invocation
But as people said on the #beginners
it will add overhead to the function calls, that seems inevitable
Something that I really miss is a set of examples of good practices. I couldn’t find a more complex system in an open source platform that I could spend some time reading
the most common way to do dependency injection for isolation of logic is to receive the dependency as an argument. You can either specify a protocol that the arg must satisfy (eg. the first arg to map must implent IFn), or document how it is used. Libraries like stuartsierra/component and weavejester/integrant have their own takes on how to isolate state management from dependency management, but each uses this technique of providing the dependency as an arg at runtime.
Things are simpler in terms of program structure generally in FP. There's no issue having functions call other functions if they are all PURE. By pure, I mean none of them depends on inputs that are not provided through an argument. So never access a global Var, or query a DB, or read from a file. Try to do that for as much functions as you can.
So if you have something that gets the name out of a file, you have it take an input-stream or a string, you don't have it read the file.
Now, you won't be able to do this for 100% of the code, at some point, your code wants to interact with the outside world, user input, or remote state. What you want is to have your TOP level functions do these things.
Ideally, you have a pattern like: main-orchestrating-fn calls a bunch of single I/O fn, like read-file, read-input, query-x-from-db, and passes the result of those to your pure functions. The I/O functions should not call other functions, they should just do the I/O and return. Your pure function are then free to call as many other pure function as needed, and nest deeply if necessary. Though in general, try to do more orchestration, and less nesting.
also, you don't abstract IO generally - it's best to keep IO at the top level rather than hiding it under something else
which is why you need the orchestrator, to call abstracted things and IO things, alternately
This sounds like knowledge that will come with practice
trial and error
But is there any way to guide my learning? Any books/resources with more complex examples?
Lots of people seem to have gotten benefit from Clojure Applied, though I confess I have not had the pleasure of reading it yet.
My design thinking has been substantially informed by domain-driven design, which advocate bounded contexts. I tend to try to organize my larger applications around a set of core protocols, and look for opportunities to couple contexts using message queues instead of fn calls.
I see… I’ll read the blue book again, with functional programming in mind. Thank you for the response!
Is it possible to use react components (published in js) in re-frame? does anyone know of a code/app example in the wild?
Thanks I'll check out this site. I have some familiarity with thinking functionally from writing modern js and react code but clojure is on a whole other level.
does this interop macro have a name: ..
? I was looking at the docs and a few other resources and I have not been able to identify a name for it. https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/%2E%2E
I don't think it has any special name
Other than dot dot
Interesting. That must be fun trying to communicate it to others unfamiliar with the language 🙂 dot dot it is!
@sudakatux Welcome! 🙂
Maybe someone can help me out, im looking to build a kind of middleweare which makes a request to an api, maps the request to something else and posts the data to Api2
and then in the repl if i do
@(http/get "")
CompilerException java.lang.RuntimeException: No such namespace:
@sudakatux your ns
code is correct. In the repl, are you within the namespace middleman.core
?
So im writing (use 'middleman.core :reload)
to get it to reload after i make a change
To switch to a namespace, you should use in-ns
(https://clojuredocs.org/clojure.core/in-ns) in the repl