This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-24
Channels
- # aatree (27)
- # admin-announcements (5)
- # all-the-channels (2)
- # aws (27)
- # beginners (38)
- # boot (48)
- # braid-chat (18)
- # cider (6)
- # cljs-dev (9)
- # cljsrn (8)
- # clojars (4)
- # clojure (73)
- # clojure-dev (2)
- # clojure-russia (2)
- # clojure-sg (1)
- # clojurescript (96)
- # code-reviews (3)
- # community-development (4)
- # conf-proposals (17)
- # core-matrix (2)
- # cursive (2)
- # datascript (4)
- # datomic (4)
- # dirac (1)
- # funcool (5)
- # hoplon (2)
- # mount (66)
- # off-topic (35)
- # om (211)
- # parinfer (2)
- # pedestal (2)
- # proton (1)
- # reagent (2)
hey @guru01-have you seen the Clojure Cookbook? How does this code snippet strike you? https://github.com/clojure-cookbook/clojure-cookbook/tree/master/05_network-io
That code is all you need for a program that receives a request- like from a browser- and sends a response back. On top of that, a basic http server is just having your server send text responses that conform to the basics of the protocol. This is a gentle introduction to that protocol: https://www.jmarshall.com/easy/http/
This person has gone through a similar exercise: http://angeleah.com/blog/index.html, with posts on building an Echo Server, and an Agreeable Web Server. Maybe those are helpful?
Unfortunately the Clojure libraries that hide the underlying "Socket" abstraction in Java- which Java itself adopted, and which dates back more than 30 years- look up Berkeley Sockets if interested- are typically intended to serve more sophisticated use cases and programming styles, and may require a much greater cognitive lift.
Thanks a lot Jonah. That is very helpful. I did see that chapter in Clojure Cookbook - but not in detail. Let me go digging a bit more. All those links and info are very useful.
props to @jonahbenton on crushing it with the detailed help and code reviews ⭐
I am converting a string map to keyword map and trying to massage some data as well as manipulate other. The :company value is set but when it reaches the function (accounts/account-create) it shows up nil.
user (-> (zipmap (map keyword (keys user)) (vals user))
(assoc :password salt)
(assoc :account_id (accounts/account-create (get user :company nil)))
)
Here is the map
{:first_name John, :last_name Quincy, :uid , :email , :password CYE8MGnf3Dyj, :company tester-mctestington, :account_id nil}
hey @ioneyed the user object is a string -> value map? so (get user :company nil) should be (get user "company" nil) ?
the accounts/account-create
currently just prints the incoming company and it reports a nil
(def user
{:first_name "John"
:last_name "Quincy"
:uid ""
:email ""
:password "CYE8MGnf3Dyj"
:company "tester-mctestington"
:account_id nil})
(-> (zipmap (map keyword (keys user)) (vals user))
(assoc :password "hard-coded-salt")
(assoc :account_id (str "company->account: " (get user :company nil))))
@jonahbenton: from my learning I thought the (-> operator would have applied the conversion from a string map to a keyword map before it got to my assoc :account_id so that it would be available via keywords
@jonahbenton: I was wrong and never thought to try that very simplistic attempt. It is being passed through now as it should.
@ioneyed- cool- one thing to still observe though about that code pattern. what that code is doing is "reassigning" a new map to a previously assigned local symbol. that will "work" but it's kind of anti-idiomatic, in that it's in the vein of mutability. so, one approach would be to populate a "str-user" symbol with the string map, and then assign a "kw-user" with the results of the (-> ) block.
I guess the better solution is to find a way to get it from compojure as a kw-map instead of str-map to begin with.
sure, though in web apps it's common and good practice to have an explicit data ingestion/validation/transformation step. Incoming data should be considered by default untrusted and at minimum in need of validation, subsequent to which it can be transformed into the model that suits the internal logic of the app
Hi, I’m trying to do remote CLJS figwheel stuff - I’m working on a remote server (in this case, a VM). I want my client code to connect to the websocket server on this VM. I’m using the re-frame todomvc example:
. I added :figwheel { :websocket-host “VM ip addr” }
under the :source-paths [“devsrc”]
line, but i still get WebSocket connection to '
. I’m feeling pretty dumb at this point, am I missing something obvious? Thanks very much in advance for any help.
i’m just running lein figwheel
, fwiw, so i’m not sure if the lein profiles are playing into this?
Does anyone know how to use void mutating java methods in clojure
I'm using the itext library(api?) and there's a .setData() method, but it only returns void, I can't seem to get the new object after .setData()
I tried doto
, and the method does more than just change set one field, so I don't think set!
applies here either
I've been experimenting with StringBuilder's .trimToSize() to test how to get a void method to work, how would I implement that for example?
hey @mark4carter doto is the right approach. can you share a non-working example?
(defn testSB
[]
(.toString (doto (StringBuilder. " jump ")
(.trimToSize)
)))
i think i read .trimtosize incorrectly
that might be the issue
ah, yeah. that doesn't do trim() on the visible part of the string, e.g. eliminate whitespace
let me try testing with something else, it could've been working how it was suppose to
ok yeah perfect
(defn testSB
[]
(.toString (doto (StringBuilder. "jump")
(.setCharAt 1 (char 97))
)))
works like it should
thanks
looks good!