This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-06
Channels
- # admin-announcements (7)
- # beginners (37)
- # boot (36)
- # cider (8)
- # cljs-dev (16)
- # clojure (155)
- # clojure-hamburg (1)
- # clojure-russia (2)
- # clojurecup (21)
- # clojurescript (69)
- # clojurex (12)
- # core-async (2)
- # datavis (3)
- # datomic (5)
- # devcards (4)
- # events (2)
- # hoplon (15)
- # lein-figwheel (45)
- # off-topic (22)
- # om (77)
- # re-frame (8)
- # reagent (7)
- # slack-help (1)
question- how would I translate the following into clojure?
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
socket.emit("foo", "hi");
socket.disconnect();
}
}
proxy
might work better
I would prefer reify
to proxy
in most cases. See this thread and answer by @kushalp for why: http://stackoverflow.com/questions/5821892/why-should-i-use-reify-instead-of-proxy-in-clojure
How can I read the first part of this [:debet {:account "cash", :amount 100}]
so I need :debet as output
I’m not sure I understand your question, but if you literally want to get :debet
out of it, it’s (first [:debet {:account "cash", :amount 100}])
. If that’s not what you’re asking, please clarify.
Is there some good practice on primary key’s type?. I have seen in many examples the use of an UUID instead of a auto incremental integer. Is this related to concurrency?
If anyone is interested, I found a good explanation here: https://github.com/clojure-cookbook/clojure-cookbook/blob/master/01_primitive-data/1-24_uuids.asciidoc. In short, they provide “uniqueness” along multiple databases and tables, which can be pretty useful in some situations. Also, they hide information about the amount of information that resides inside a table (I am not sure why this could be a good thing).
@rcanepa: If you choose to use auto increment ints or bigints attacker may guess the id's of the next entry. This opens for some attacks that are not possible by choosing random ids like UUIDs
@rcanepa: Yea, np. It's a rat race. I think such common knowledge should be bundled into libs or frameworks so that newcomers don't have to deal with it immediately.
@eggsyntax: you are right . That is working but when I have this
(def transaction [ {:debet :account "cash" :amount 100 }} { :credit {:account "bank" :amount 100}} ]
)
then this is not working : (first (first transaction) ))
I see then [:debet {:account "cash", :amount 100}]
instead of just :debet@roelof: That's not valid clj, though. Is the second closing squiggly brace on the first map a typo? Or did you intent an opening squiggly before the first :account
?
@eggsyntax: I think the last ) is a left-over from closing the function
oke, sorry : then it will be (def transaction [ {:debet {:account "cash" :amount 100 } } { :credit {:account "bank" :amount 100}} ]
OK. Note that in your original post you had [:debet ...]
, and here you have {:debet ...}
. That is, you've changed the vector to a map.
If you want it to be a map, it gets a bit more awkward, but you could do (first (keys (first transation)))
.
It feels to me like maybe you haven't quite clarified in your mind what you're trying to represent.
@eggsyntax: im experimenting what is the best way to represent
If you want the transaction to consist, by definition, of a debit and a credit, I'd consider something like
(def transaction {:debit {:account "cash" :amount 100}
:credit {:account "bank" :amount 100}})
Then you don't have to pull out the name :debit
, because you know it'll contain a debit, so you can just do (:debit transaction)
to get the info about the debit.
I am attempting to create an app that I upload a file to and read its contents before doing other things. I am getting the parameters back from my uploaded file and I am unsure how I would read the uploaded file from ring.middleware.multipart-params. The parameter map of a sample uploaded file is as follows: {:file {:size 70, :tempfile #<File /tmp/ring-multipart-4755435914544293619.tmp>, :content-type text/csv, :filename request_temp.csv}} 1. Do I use the :tempfile key or the :filename key? 2. Is there an extra step that I am missing?
@kyle_schmidt: it looks to me like you should use the :tempfile
key, as its value is a File object.
@codonnell: I was trying that and it wasn't cooperating. I'll keep experimenting.
Does make any sense to use protocols to define CRUD operations on different models/types? Or I will gain nothing because I will just move complexity from one place to another?… I am learning about multimethods and protocols and I am trying to come up with a situation in which they may useful.