This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-18
Channels
- # aleph (59)
- # beginners (21)
- # bigdata (1)
- # boot (110)
- # cider (7)
- # clara (1)
- # cljs-dev (160)
- # cljsjs (3)
- # clojars (10)
- # clojure (122)
- # clojure-czech (2)
- # clojure-dusseldorf (5)
- # clojure-france (1)
- # clojure-italy (4)
- # clojure-korea (5)
- # clojure-russia (13)
- # clojure-spec (15)
- # clojure-uk (78)
- # clojurebridge (1)
- # clojurescript (196)
- # core-async (6)
- # core-logic (27)
- # cursive (11)
- # data-science (2)
- # datomic (45)
- # dirac (9)
- # emacs (2)
- # funcool (8)
- # hoplon (16)
- # immutant (13)
- # jobs (1)
- # klipse (11)
- # lein-figwheel (1)
- # leiningen (1)
- # off-topic (3)
- # om (40)
- # onyx (31)
- # pedestal (25)
- # re-frame (55)
- # ring (1)
- # ring-swagger (1)
- # rum (4)
- # specter (1)
- # sql (2)
- # untangled (30)
- # vim (12)
- # yada (12)
More of a basic question here. I have a grid of {::x int? ::y int? ::exits (spec/coll-of ::direction :type set?)}
cells, specced as ::grid/cell
. This isn't really a clojure.spec question, but maybe the spec helps?
I want to implement Dijkstra's Algorithm to find the shortest path by following exits. Dijkstra assumes an omniscient view of all nodes, which is fine: I can say that the unvisited set is (all-cells grid)
. But the algorithm is most easily expressed by maintaining a map of the current distance from the origin node to each target node. But a map keyed by keywords or strings does not seem appropriate here. It's more natural to use cells themselves as keys. In a language with a dictionary that allowed arbitrary objects as keys, you would say:
distances = new Dictionary()
distances.set(origin_cell, 0)
remaining_cells = all_cells.without(origin_cell)
remaining_cells.each(cell =>
distances.set(cell, nil) # initial setup, no known distance
Is there a data type in Clojure that will let me use arbitrary data as keys? Or would I be better of making a simple key function such as (fn [cell] (format "%d,%d" (::x cell) (::y cell)))
?also: working on a game? care to trade github repo links? 😄 always looking to learn from other clj/s gamedevs
cljs.user=> (defrecord Foo [a b c])
cljs.user/Foo
cljs.user=> {(Foo. 1 2 3) 3}
{#cljs.user.Foo{:a 1, :b 2, :c 3} 3}
cljs.user=> {[1 2] 3}
{[1 2] 3}
( ^ @amacdougall, fyi when you wake up 🙂 )
hello guys, I have a question ^^. Does someone know how to exactly have the list of possible metadatas for def
Hi folks. What do people do to avoid huge uberjars in deployments? I'd rather not generate 100+ MB jars if I can avoid it. Is excluding specific dependencies a viable option? Is it better to avoid uberjars alltogether?
@jrheard i potentially have livecoding cljs working for ios + android on react-native with opengl bindings, and you can use like http://regl.party for declarative gl http://g.recordit.co/Clb3hsjxtc.gif
@triss Found this just now for some general purpose functions including map-vals
: https://github.com/weavejester/medley. It also references in its readme some other libs.
@jannis is your uberjar including some classpath weirdness like transitive dependencies that are not used?
@anmonteiro It contains a number of huge packages like com.ibm.icu
(37.9MB unpacked), it.unimi.dsi.fastutil
(63MB unpacked). I'm not using them in my code but my immediate dependencies might.
hah, right. I don’t have a solution for that, no
Project Jigsaw will be able to reduce the size of generated jars, but it will be available from Java 9 on only and if you can use it with clojure, I dont know at all.
Hi, hoping someone might be able to help me with an issue I'm having. I need to make an API call but two of the params require a string, so I have 2 strings inside a string, like this: (client/get (format "https://graph.facebook.com/v2.8/act_%s/insights?level=ad&access_token=%s&filtering=[{field:"ad.impressions",operator:"GREATER_THAN",value:0}]&limit=2000&offset=0" "123" "456")) Unfortunately it appears that the " in front of ad.impressions is being treated as the end of the url causing it to throw CompilerException java.lang.ClassNotFoundException: ad.impressions. Is there a way to nest strings?
@jrheard : Well I'll be darned.
(let [m {[0 0] :a
[0 1] :b
[0 2] :c}]
(m [0 0]))
Somehow it just never occurred to me to try, since people use maps almost exclusively with keyword or string keys!
This may not be everyday Clojure, but it solves my problem precisely.If I wanted to find all namespaces in a Clojure project that use a specific macro (e.g. deffoo
) - how would I best approach that?
Seriously not trolling here: grep
?
If you need to find it as part of a Clojure program, for use in a Clojure program, sure, you might need to be fancier, but if you're just curious, well...
if you have programmatic goals, then you could scan all of your source files with tools.reader
or I guess even just the regular reader
then look for that symbol using walk
@alexmiller Hehe, yeah, grep
would not be good enough. tools.reader sounds good. Plus tools.namespace to walk over the files in a source tree?
@robert-stuttaford we're probably way OT for #datomic now..
Not sure about laziness. I imagine the trick is, like tufte, to do the measurement in the inner loop. That way, unless map
is slow in itself, you repeatedly measure the inner loop.
true, thanks
That's how I did it anyway, I got odd results with tufte when surrounding the map
directly.
the character I used there to represent it is the character you would use in java regex
but if I try to just say the string "\x1D" I get:
CompilerException java.lang.RuntimeException: Unsupported escape character: \x
can someone tell me what’s wrong with this? http://pastebin.com/Cmdpj3WT i feel like i’m either a) missing something incredibly obvious or b) misunderstanding the ->
macro
gives me java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector
on line 2
user=> (-> 2 #(+ % 1))
CompilerException java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.ISeq, compiling:(NO_SOURCE_PATH:20:1)
user=> (-> 2 (#(+ % 1)))
3
@jannikko it doesn't really fix the large uberjar problem but rsync works quite well for uploading large jars after the initial upload. Also I have also from time to time thought about using docker as a solution, but never tried. You could create a docker image with the large dependencies added to the image before your app jar. Then build a non-uber jar put it in the image and reference the prior deps on the classpath. That should cache the dependencies and should only incur the small app jar changes when the image is pushed a second time. Of course each time you change your set of dependencies, you would need to make sure they got added to the image.
@mikeb @janniko that docker approach you suggest definitly works, I have been something similar already and its one of the selling points of docker.
you could just run lein uberjar, it will download them once and keep them cached on your server. Leiningen / maven will do that for you.
Or you copy them from the maven cache somewhere and add them to the classpath when starting the thin jar
there is a lein plugin that generates a tarball of your project, which has directory lib/ which contains all the jars
lein classpath
will give you want lein thinks the classpath for your project is (which may work depending on what you are using this directory for)
i want to make a bunch of http requests in parallel and then wait for them all to be finished and collect their results in a list. what’s the best way of going about this?
@liamd http-kit has a client that can do that: http://www.http-kit.org/client.html#combined
i haven’t really messed around with threads, that’s going to spawn that many threads right?
this is my first naive try:
(defn get-all-configuration-settings [environments]
"Gets all config settings in parallel"
(->> environments
(mapv #(future (describe-environments %)))
(mapv (fn [x] @x))))
to force it using mapv which map is important? the deref one or the one creating the futures?
user=> (supers (type []))
#{java.util.Collection clojure.lang.IPersistentStack clojure.lang.Reversible clojure.lang.APersistentVector clojure.lang.Sequential java.util.RandomAccess clojure.lang.Associative clojure.lang.IReduce clojure.lang.IEditableCollection clojure.lang.IPersistentCollection clojure.lang.IPersistentVector java.util.List clojure.lang.AFn clojure.lang.IKVReduce clojure.lang.Counted clojure.lang.Seqable clojure.lang.IFn clojure.lang.IReduceInit clojure.lang.IHashEq clojure.lang.Indexed java.lang.Iterable clojure.lang.ILookup clojure.lang.IMeta java.lang.Comparable java.io.Serializable java.util.concurrent.Callable clojure.lang.IObj java.lang.Runnable java.lang.Object}
user=>
vectors are seq-able
that is, they can produce a sequence view when asked
anyone know how to properly compare strings for equality when they contain unicode?
i currently run my webapp using lein ring headless
but i’m pretty sure i need a core namespace for deploying to heroku and packaging a jar and all that? any idea?
1. it generate an uberwar, a war file being a common format for java app servers and you can use tools like jetty-runner to run it standalone
2. lein ring uberjar will generate an uberjar that will launch a jetty server serving your app
those will both base their configuration on the same configration that lein ring headless uses, so if lein ring headless works, either of those should launch your app fine
I don’t get ex-info
when doing deftest
from code like (throw (ex-info "Invalid input for label" (s/explain-data ::sl/label-main product)))
i get only https://www.refheap.com/c34d52b669b6a34e7a5a04364 . What can i do to get ex-info data during tests from exception?
@liamd i’d recommend uberjar
for heroku. heroku will run lein uberjar
by default (not sure if that results in lein ring uberjar
in your app)
otherwise, you can heroku config:set LEIN_BUILD_TASK=“ring uberjar”
gives me uhhh:
Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: Symbol
what is the more updated/used source of Clojure documentation, http://clojuredocs.org, http://clojure.org, others? I ask because I’m on http://clojuredocs.org and I see some examples missing and I’m wondering if I should add them (in this case for clojure.zip).
Speaking for just myself, I always go to clojuredocs. As far back as I can recall, it has had explanatory examples for all of my needs. But I've no idea if there's actually a better source, I haven't felt the need or itch to pursue it 🙂
http://clojuredocs.org is more or less a crowd sourced site, unless something has changed it is not run by the same entity that runs http://clojure.org