This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-27
Channels
- # aleph (7)
- # beginners (80)
- # boot (1)
- # cider (3)
- # cljs-dev (277)
- # cljsjs (52)
- # cljsrn (1)
- # clojure (69)
- # clojure-gamedev (4)
- # clojure-italy (1)
- # clojure-losangeles (2)
- # clojure-russia (89)
- # clojure-spec (92)
- # clojure-uk (196)
- # clojured (1)
- # clojurescript (70)
- # cursive (5)
- # data-science (1)
- # datascript (84)
- # datomic (9)
- # defnpodcast (12)
- # docker (1)
- # emacs (4)
- # events (1)
- # fulcro (112)
- # graphql (1)
- # jobs (1)
- # lumo (1)
- # nrepl (21)
- # off-topic (2)
- # onyx (3)
- # protorepl (10)
- # re-frame (23)
- # reagent (66)
- # reitit (2)
- # rum (13)
- # shadow-cljs (144)
- # spacemacs (14)
- # sql (4)
- # unrepl (29)
- # vim (16)
OK, thanks... can you suggest a way to do what I want? I figure I could create a macro but I wonder if there’s another way.
(doseq [s [`doc `+]] (#'clojure.repl/print-doc (meta (resolve s))))
(although doc
is substantially more complicated)
(looks like you could use '
instead of backtick there)
It is. But Clojure lets you call private functions.
And access private variables' contents.
(the code above works -- I tested it in the REPL first)
I get these errors in a heroku app log (after following re-frame lein template instructions)
2018-02-27T03:28:46.620804+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-02-27T03:28:46.626435+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8
2018-02-27T03:28:52.373794+00:00 app[web.1]: No :main namespace specified in project.clj.
2018-02-27T03:28:52.374621+00:00 app[web.1]: Error encountered performing task 'trampoline' with profile(s): 'production'
2018-02-27T03:28:52.374755+00:00 app[web.1]: No :main namespace specified in project.clj.
Anyone familiar with this? I see that some other people ran into this problem but didn’t encounter any solutionsdoes your project.clj have a :main key?
@noisesmith: I’m don’t see one. I will paste the entirety of the file below.
(defproject npuzzle "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.908"]
[reagent "0.7.0"]
[re-frame "0.10.5"]
[garden "1.3.2"]
[ns-tracker "0.3.0"]]
:plugins [[lein-cljsbuild "1.1.5"]
[lein-garden "0.2.8"]]
:min-lein-version "2.5.3"
:source-paths ["src/clj" "script"]
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"
"test/js"
"resources/public/css"]
:figwheel {:css-dirs ["resources/public/css"]}
:garden {:builds [{:id "screen"
:source-paths ["src/clj"]
:stylesheet npuzzle.css/screen
:compiler {:output-to "resources/public/css/screen.css"
:pretty-print? true}}]}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:profiles
{:dev
{:dependencies [[binaryage/devtools "0.9.4"]
[day8.re-frame/re-frame-10x "0.2.0"]
[figwheel-sidecar "0.5.13"]
[com.cemerick/piggieback "0.2.2"]]
:plugins [[lein-figwheel "0.5.13"]
[lein-doo "0.1.8"]]}}
:cljsbuild
{:builds
[{:id "dev"
:source-paths ["src/cljs"]
:figwheel {:on-jsload "npuzzle.core/mount-root"}
:compiler {:main npuzzle.core
:output-to "resources/public/js/compiled/app.js"
:output-dir "resources/public/js/compiled/out"
:asset-path "js/compiled/out"
:source-map-timestamp true
:preloads [devtools.preload
day8.re-frame-10x.preload]
:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}
:external-config {:devtools/config {:features-to-install :all}}}}
{:id "min"
:source-paths ["src/cljs"]
:compiler {:main npuzzle.core
:output-to "resources/public/js/compiled/app.js"
:optimizations :advanced
:closure-defines {goog.DEBUG false}
:pretty-print false}}
{:id "test"
:source-paths ["src/cljs" "test/cljs"]
:compiler {:main npuzzle.runner
:output-to "resources/public/js/compiled/test.js"
:output-dir "resources/public/js/compiled/test/out"
:optimizations :none}}]})
so, what that message is telling you is that it doesn't know how to run your project because project.clj doesn't specify a main for leiningen to run
your code doesn't appear to have any back end element though - does it define any server, or is it just cljs served by figwheel during development?
@noisesmith: Yeah, just figwheel
if you have no backend code, you could just upload an index.html and js etc. to a CDN - you don't even need any server side process other than serving the files
anyway that's why heroku doesn't know what to do - it expects to start a back-end clojure process and you have none, all you really seem to need is a generic static web host
Ok, thanks @noisesmith
Any suggestions for more idiomatic ways to achieve this?
(defn connect []
(swap! connection #(or % (open-connection))))
@ggallohernandez… it is, for two reasons.
1) (open-connection)
calls into a library that itself maintains lots of global state.
(def connect
(let [ connection (delay (open-connection) ) ]
(fn []
@connection)))
maybe better?I suggest to look at the https://github.com/tolitius/mount or Component library
Is there any collection in clojurescript akin to C++ multimap? (Should be ordered, and able to contain multiple equal keys)
Or I need to manually maintain vector/list for each key instead of a single item using a sorted-map
?
Does anyone using datadog with clojure ring instrumentalization?
@neoshadybeat have not, what metrics would you be ineterested in instrumenting, out of curiosity?
Firstly Requests and response
Response time and status code
Also db connection
Between anothers
gotcha, i haven't seen a ring middleware to do all that yet. We've written a wrapper for dogstatsd (wraps the java one) if you'd build something ontop of it: https://github.com/unbounce/clojure-dogstatsd-client
i can definitely see value in creating ring middleware for response time & status code
I was working once it
If I have a map of vectors a
which equals [{:a 1 :b 2 :c 3 :d 4} {:a 5 :b 6 :c 5 :d 8}]
and another vector b
which equals [{:a 1 :c 3 :d 10} {:a 1 :c 2 :d 3}]
how would I compare these two and return any results where the attributes :a
and :c
are equal, but :b
is not equal
compare by index, or compare every pair?
if the latter, something like (for [x v1 y v2 :when (and (= (select-keys x [:a :b]) (select-keys y [:a b])) (not= (:c x) (:c y)))] [x y])
yeah, for is the easy way to do that
@josmith2016 I think I am misunderstanding you, because nothing in the second vector even has :b so you'd be getting no results if you compare
I have two different vectors that have different kinds of maps with similar data but different properties. I know what properties I want to compare in each map and want the results where for example property :a
in vector a
equals property :b
in vector b
but property :c
in vector a
doesn't equal property :d
in vector b
@josmith2016 OK - so something like this - I wasn't sure because it didn't return anything interesting with your example data and rules http://ix.io/Qkw
Thanks @noisesmith 😁
for comparing :a in x and :b and y and visa versa this is a neat trick: (apply = (map :a [x y]) (map :b [y x]))
- maybe too clever but it works
I have a dataset that I give as an input to a function I am spec'ing. This dataset can be either of two types, let's call them A and B. How would I go about spec'ing it?
@elena.caraba The general idea would be to use s/or
. If the value is an atom, is your intent to validate the atom's contents? And, is the atom A expected to hold a map that satisfies to the same spec that B would?
Here is a way to do the last bit above https://gist.github.com/mfikes/1c0bdeb1ec1c54902605e2692bbcef5c
I have some time data to work with. I pulled in clj-time. To my surprise, (inst? (time/now))
is not true, as time/now
gives a org.joda.time.DateTime object. I don't know anything about Java time and date libraries; is there a reason to prefer one over another? I.e. should I write my own predicate for a spec or have a chosen a weird option for representing times?
Ahh, what I meant by that: If you only need to tag things with an instant in time, you could use (Date.)
, but if you need to start to manipulate time values, or access their sub-parts, then the question of "Which library?" becomes relevant.
For example Clojure/(Script) #inst "2014"
and inst?
for very simple time stamping is sufficient for many use cases, and in that case you can just rely on what is in the core language.
It is surprising that cljs-time
hasn't extended the Inst
protocol to their "instant-like" time values. Hrm.
well that’s new in 1.9
@mathpunk I'm one of the maintainers of clj-time
but I'd recommend looking at clojure.java-time
which is a wrapper around the built-in Java Time stuff (added in Java 8).
boot -d clojure.java-time repl
...
boot.user=> (require '[java-time :as jt])
nil
boot.user=> (inst? (jt/instant))
true
boot.user=>
boot.user=> (jt/instant)
#object[java.time.Instant 0x21b0ad22 "2018-02-27T21:23:15.358Z"]
boot.user=> (jt/java-date (jt/instant))
#inst "2018-02-27T21:23:24.058-00:00"
boot.user=>
@alexmiller Hah. Extremely valid point. I forgot. Looking it up in ClojureScript inst?
and Inst
have evidently been there since mid-2016.
Is there a way to pass in an arbitrary function into project.clj? example. I have on env variable that contains both a username and password for a private maven repo. I want to be able to get user and pass from this one env var. Is there any way to do this?
currently:
:repositories [["maven" {:url " "
:username :env/mvn_repo_login_user
:password :env/mvn_repo_login_pass }]]
@ben.borders if the code can be found, ~(foo) evaluates foo inline in the template
you might need to insert a ~(do (require 'my.tool.ns) ...) in there
or, alternatively, you could implement a plugin, those can do whatever they like to update the project task before other things run
@ben.borders of course if all you are doing is literally getting from env: ~(System/getenv "MAVEN_USER") etc.