This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-22
Channels
- # arachne (8)
- # bangalore-clj (1)
- # beginners (72)
- # boot (95)
- # braveandtrue (5)
- # business (1)
- # capetown (1)
- # cider (180)
- # cljs-dev (8)
- # cljsrn (20)
- # clojure (104)
- # clojure-art (1)
- # clojure-brasil (8)
- # clojure-czech (1)
- # clojure-greece (15)
- # clojure-korea (13)
- # clojure-poland (2)
- # clojure-russia (53)
- # clojure-sg (5)
- # clojure-spec (60)
- # clojure-uk (35)
- # clojurescript (186)
- # community-development (3)
- # core-async (24)
- # cursive (18)
- # datascript (11)
- # datomic (39)
- # devcards (4)
- # emacs (2)
- # events (1)
- # funcool (23)
- # hoplon (148)
- # juxt (1)
- # ldnclj (2)
- # luminus (1)
- # off-topic (22)
- # om (27)
- # onyx (35)
- # overtone (2)
- # pedestal (7)
- # perun (8)
- # protorepl (2)
- # rdf (6)
- # re-frame (15)
- # reagent (2)
- # ring-swagger (10)
- # untangled (54)
I am doing some casual stuff with prismatic/graph and am writing lots of functions like (fnk [a b c] (+ a b c))
and I appreciate not having anaphoric macros but the repetition there is a lot
it makes me wonder if there's an intermediate option where you declare a symbol prefix; e.g., (crazy-fnk $ (+ $/a $/b $/c))
I guess you can't write that macro cleanly without a good code-walker, but still
maybe the real answer is a macro for the whole graph
(fn [a _] (:text a)) <-- is there a way to write this as an anonymous function #(:text %1) <-- how do I tell it to expect a %2 but its not used?
it creates the arity based on the % params you use
so you’d have to use it uselessly like #(do %2 (:text %1))
why not just use the fn form?
you could do #(:text (first %&))
#(-> %& first :text)
that’s as clever as I’ve got :) but I wouldn’t use it for anything other than code golf
@alexmiller: it's somethign that looks like (re-frame/reg-sub :equation (fn [db _] (:equation db))) I had thought making it using #% might be clearer, %& is very cute, but I guess I'll just use fn for now.
Nothing to do with clojure. But chrome is giving me a certificate error for http://amazon.com? is anybody else getting that?
hmm.. restarted chrome. dont have the issue anymore. Well then..
hi all, where can i see best practices for clojure project structure, namespaces and etc?
@dotspy There really isn't any definitive "best practices" for that. It depends very much on your specific project.
About the only guidance most people seem to agree on is "keep it simple" 🙂
dotspy: I think it is very common to use "lein new", maybe using the app template, to set up a basic skeleton. There are more involved leiningen skeleton templates available, but I've never used them.
I’m building several related ClojureScript apps and I need to share some code amongst them. What’s the best method? private maven repository? git submodules?
@hans Yeah i used lein to create new project. But now im stuck, should i use smth like java best practise for folder naming in my CRUD + REST basic app, or smth else.
dotspy: for a very complete template of a web app, you can check Luminus.
@dotspy i’d recommend reading Clojure Applied https://pragprog.com/book/vmclojeco/clojure-applied
anybody knowing how riemann works here? I wrote a simple http server - https://paste.in.ua/2125/ - but if I start it as (http-server {:port 1234 :app some-fn})
, nothing except for http-server
itself is executed. Any ideas what I should do to make it work?
@nikki thats cool. Is there an app?
how did you manage to open the clojure repl?
I want to serialize clojure data structures, such that 2 values that are .equals
will emit the same bytes. Is there a library that already does this? I am interested in serializing the standard edn set of types. The reason for this is that I am interested in content-addressing clojure data-structures.
It seems like data.fressian
for example returns different bytes for 2 equivalent array maps (due to impl ordering)
that would eliminate the differences due to ordering, and is easy to do (using clojure.walk)
clojure.walk, to encode sorted versions of unsorted structures is my fallback if I can't get anywhere. The obvious problem is efficiency, you have to walk and reallocate the entire structure before you can start writing bytes.
i'm not familiar with fressian, but would it be possible to emit bytes for a map in the order of the keys?
It may be possible to override write handlers for particular types, I will look into it as well.
I don't know of anything doing this, but it's a cool idea
Ok, I'll look at doing it by extending fressian, I'll release something to the world if all goes well
Turns out there is some subtlety in doing this. e.g bigints/longs, vectors/seq/list equivalence. Maybe I shouldn't be using .equals or =
as the basis for output equality, rather best effort but limited to both type and equality.
The alternative is to always return bigint for integer ambiguity, and vectors for sequence ambiguity. This seems like it may lead to bugs in particular regarding lists.
Is there a kind of some->
threading macro or something similar that returns the first result to satisfy a given predicate?
@patrkris @mpenet It needs to be a pipeline like thing, testing the result of the previous form against the predicate, and using it as first parameter of the next.
Not sure I need it anymore, but here is my attempt (adjusted some->
):
(defmacro pred->
"When pred against x is truthy, threads x into the first form (via ->),
and when pred against that result is truthy, through the next etc."
[pred x & forms]
(let [g (gensym)
steps (map (fn [step] `(if (-> ~g ~pred) ~g (-> ~g ~step)))
forms)]
`(let [~g ~x
~@(interleave (repeat g) (butlast steps))]
~(if (empty? steps)
g
(last steps)))))
=> #'dev/pred->
(pred-> even? 1 inc inc)
=> 2
Hi, I'm just trying out Clojure and was wondering what the best way is to check if a vector contains a map. Is there anything built in? Or do I dissect the data and compare against the key/value? [{:foo "bar"}] contains? {:foo "bar"}
@emileswarts Do you mean any of these?
(some #{{:foo "bar"}} [{:foo "bar"}])
=> {:foo "bar"}
(some map? [{:foo "bar"}])
=> true
That’s it! Thank you
#compojure-api any have experience of using compojure-api to download file with byte-array format instead of default json?
@joseph What do yo mean with byte-array? You'll need a serialization format
I mean I have a file in the Byte array format, and want to return it as body directly, but I found it's default converted to json format
Do you have :return
key in the handler? That will enable serialization always
(ok (io/file ...))
(ok (io/resource ...))
and (ok (byte-array ...))
should all work (though I guess you should also assoc content-type to the response)
@joseph I mean the Compojure-api handler metadata
is the cider room private?
sorry, I still do not understand what you mean :return
key, but I print out the response, it's like this
{:status 200, :headers {\"Content-Disposition\" \"attachment; filename=\\\"dataset.dta\\\"\", \"Content-Type\" \"application/json; charset=utf-8\", \"Content-Length\" \"189362\", \"Access-Control-Allow-Origin\" \"*\", \"Access-Control-Allow-Methods\" \"POST\", \"Access-Control-Allow-Headers\" \"X-Requested-With,Content-Type,Cache-Control\"}, :body #object[java.io.BufferedInputStream 0xefcbd55 \"java.io.BufferedInputStream@efcbd55\"], :compojure.api.meta/serializable? true}
@joseph The problem is :compojure.api.meta/serializable? true
and that is caused by your handler code
@juhoteperi any idea to change it? as it as false?
Please paste the whole handler code somewhere
(defmethod handle-request :download-dataset
[request header]
(let [dataset-type (-> request :input :type)
download-command (assoc (dissoc (:input request) :type)
:command "download")
csv-file (get-remote-file "/download-data" download-command header)
metadata-file (when (or (= dataset-type "STATA")
(= dataset-type "SPSS"))
(get-remote-file "/download-documentation"
(dissoc download-command :case-subsets)
header))
x-request-id (get header "X-REQUEST-ID")
data (case dataset-type
"CSV" (.getBytes csv-file)
"STATA" (convert-csv-file! csv-file metadata-file "dta" x-request-id)
"SPSS" (convert-csv-file! csv-file metadata-file "sav" x-request-id))
suffix (case dataset-type
"CSV" "csv\""
"STATA" "dta\""
"SPSS" "sva\"")]
(log/with-logging-context (merge header
request
{:success-code 200
:version (helpers/project-version)})
(log/info "Succeed downloading dataset with format " dataset-type))
(let [f (FileOutputStream. "dataset.dta")]
(.write f data)
(.close f))
(assoc (ok (byte-array data))
:headers
{"Content-Disposition" (str "attachment; filename=\"dataset." suffix)})))
What about the compojure handler? (GET ...)
part
(context "/download" []
:middleware [extract-request-header!]
(POST "/" []
:summary "The interfact to communicate with client."
:responses {200 {:schema resp-v/transit-schema
:description "Successful operation!"}
400 {:schema error-v/bad-request-error-400-schema
:description "Bad request!"}
401 {:schema error-v/unauthorized-error-401-schema
:description "Unauthorized!"}
404 {:schema error-v/not-found-error-404-schema
:description "Not found!"}
500 {:schema error-v/system-error-500-schema
:description "System error!"}}
:form-params [request :- s/Str]
(handler/wrap-exception! (read-string request) (:header @app-state) handler/handle-request)))
Okay, :responses
causes the serialization
If you have set the response Schema using :return
or :responses
; the response is always serialized to JSON or such
@juhoteperi hmm, it comes 500 error...
@juhoteperi I also added two middleware after the api, one is used to allow cross origin and another is to set the content type of response which contains byte-array file to application/octet-stream. I print the response in the middleware, the setting content-type one seems triggered twice
"resp: {:status 200, :headers {\"Content-Disposition\" \"attachment; filename=\\\"dataset.dta\\\"\", \"Access-Control-Allow-Origin\" \"*\", \"Access-Control-Allow-Methods\" \"POST\", \"Access-Control-Allow-Headers\" \"X-Requested-With,Content-Type,Cache-Control\", \"Content-Type\" \"application/octet-stream\"}, :body #object[\"[B\" 0x58198f69 \"[B@58198f69\"]}"
"/download/"
"resp: {:headers {\"Access-Control-Allow-Origin\" \"*\", \"Access-Control-Allow-Methods\" \"POST\", \"Access-Control-Allow-Headers\" \"X-Requested-With,Content-Type,Cache-Control\"}}"
can anyone recommend a lib (or libs) that can read .obj
and .mtl
files and render/export them as .svg
or straight to raster?
@pradeepcheers: its actually just an ssh into somewhere and im running emacs and cider and everything there haha
Refheap is back up and running, I'm not sure why it went down and didn't auto recover or how long it has been. Apologies friends.
Also apologies for ignoring my 300 thousand Clojure projects, I've been hustling to find a job and there are two companies in Los Angeles using Clojure that I am aware of and none of the ones except Geni that I've worked and am going to work for are using it, but I hope to have a better work life balance at the job I'm about to join and ideally will start going through and updating my projects and releasing and such.
I start December 5th, so between now and then I'll do what I can. Any projects anyone wants admin access to, to help manage, please let me know. I don't know what folks consider important and priority
I’ve used a couple of your libs @raynes, thanks for putting them out there, and the work that went into them 👍. Glad to hear your work situation is stabilizing.
I've been contracting pulling my <expletive> together and kinda forgot to look for jobs for 7 months.
More work will go into them. Seems like a lot of folks are really into raynes/fs. I think that needs to be entirely rewritten against Java 8.
@juanmp If they let me slip in some Clojure, I work in data engineering and will be learning machine learning. Ask me in February 😛
Most are Clojure projects I started when I was a teenager, but I've got projects in there in lots of languages. They cited that in the interview so it was the first interview I've done with no whiteboarding. Blew my mind. I did pair with my team lead on some non-trivial js problems for the first hour, two latter portions of the rxjs interactive tutorial.
Embarrassingly forgetting how to use a mac keyboard having used a Surface Book for months.
Oh, peronas is shutting down on the 30th. I need to add a new authentication mechanism to refheap. Any preferences? I'd default to github.
@bfabry I don’t know what led you to believe that Onyx is a distributed implementation of CSP for Clojure, but that isn’t accurate.
It seems I should not have read these two statements as being related, then. 🙂
Sorry for the noise