#clojure logs

2015-05-10

00:00airportyhHello all, I am learning about protocols. What are the common protocols that are built-in?
00:28turbofailderp. looks like i was too late. but in case anyone else is interested in airportyh's question see https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/protocols.clj
00:36justin_smith(inc turbofail)
00:36lazybot⇒ 6
03:15cflemingdnolen: Yeah, that might be - I have to revise that. I did the support originally for cljx, but it'll get much more use now. It's actually surprisingly tricky to do well.
03:37goraciohey there, lein figwhell reloads only client but what about reload of the server ? i have to re run - lein figwheel in that case each time
03:54goraciolein figwhell reloads only client but what about reload of the server ? i have to re run - lein figwheel in that case each time
04:08dysfunyour server is written in clojure?
04:08dysfunyou can use ring.middleware.reload to reload code
04:10goracioyes server in clojure also
04:11dysfunthen (:require [ring.middleware.reload :refer [wrap-reload]]) and (wrap-reload my-handler)
04:11dysfunnote that you should only do this in development
04:13goracioand where should i require that ?
04:13dysfundepends how your app is structured
04:14goracioi guess in development-middleware
04:14goracioi use luminus template
04:14dysfunhow long ago did you use the luminus template? i'm familiar with the old one but not the new one
04:14dysfunthe old one has a middleware.clj
04:14goracioi use new build
04:15dysfunanyway, wherever you're wrapping your middleware is the right place
04:15dysfuni find it most convenient to have a function to call for dev and a function to call for live
04:15goraciohttps://gist.github.com/fellz/ecc473faac1e6ccb108c
04:16dysfunyeah, i'd put that in development-middleware
04:16dysfunwith the require in the ns form at the top
04:17goracioand then i added (wrap-reload handler) in development-middleware
04:17dysfunwell you have an arrow form
04:17dysfunso i'd just add a new line in it with 'wrap-reload' in it
04:17goracioso just wrap-reload ?
04:18goracioah ok
04:18dysfunwhat does 'omlet' do?
04:19escherizebackend service for making savory breakfast foods
04:19goraciowell i am trying simple app - take some articles from db and show them on the page )
04:19dysfunwith om, i'm guessing
04:19goraciowith reagent
04:19dysfunheh
04:20escherizeyou might wanna try reagent
04:20escherizereagent is Noice.
04:20goraciowell i cann't convert json from server to articles list
04:20escherizealso it's the default luminus +cljs template.
04:21escherizeis that the jquery one?
04:21dysfunyou can easily convert json from the server to an articles list
04:21goracioi user cljs-ajax
04:21dysfunno, Ractive is the guardian's alternative to React. released around the same time. discovered it yesterday, looks cool
04:21goracio(GET "/articles" {
04:21goracio :handler articles-list
04:21goracio :error-handler error-handler})
04:21goraciosomething like this
04:22escherizegoracio: please use a pastebin service? like refheap.com
04:22goraciook
04:22goracioso response i get is ArrayMap
04:22goracionot a HashMap
04:22escherizeSo, what are the benefits of ractive > react?
04:23dysfunractive has a bit of a different look at the world. you know how om and reagent have to do all the clojure mutable state stuff to improve react performance? well ractive enables you to do it directly
04:23escherize,(type [])
04:23clojurebotclojure.lang.PersistentVector
04:23escherize,(type {:a 1})
04:23clojurebotclojure.lang.PersistentArrayMap
04:24dysfunractive has primitives for updating a render of a component, for example, where react would by default rerender
04:24dysfunplus two way binding
04:25escherizeactually dysfun, I use re-frame so I am insulated from the internals of that [ reagent -> component -> dom ] pipeline
04:26dysfun*shrug*
04:26dysfungoracio: i don't recognise that syntax. what plugin are you using?
04:26dysfunthe :handler bit
04:26goraciocljs-ajax
04:26escherizehave u ever checked out their readme? https://github.com/Day8/re-frame/
04:27dysfungoracio: are you definitely requesting JSON?
04:27dysfunescherize: i've only just heard of it
04:27goraciodysfun: Accept:application/json, application/edn, application/transit+json, text/plain, text/html, */*
04:28dysfunhrm. can you check the server is returning json by pinging a request at it with curl?
04:28goracioand i got json
04:29dysfun*shrug* sounds like cljs-ajax is the problem
04:29goracioContent-Type: application/json; charset=utf-8
04:29dysfuni've been using test data so far embedded in my main cljs file, so i haven't had to deal with ajax yet
04:29dysfundoes the content look right?
04:29goracioyes it's json
04:30dysfun*shrug* i don't know how cljs-ajax works, sorry
04:30escherizegoracio, you can check with this
04:30escherizehttps://gist.github.com/d629b6bd93ac00fa96fc
04:30escherizenow you'll be printing the returns for articles.
04:30dysfunwell, bar that typo, "resoonse" :)
04:30escherizederp
04:31escherizeit compiled in my head
04:31escherizehttps://gist.github.com/6054ae88a0c987fd3e77
04:31goracio{"title":"Hello world !!! "}
04:31goracio(.log js/console (:title response))
04:31goracioreturns nil
04:31clojurebotI don't understand.
04:32escherizewhen you log it, in the console, is it a map or a string?
04:32escherize,(use 'clojure.core.match)
04:32clojurebot#error{:cause "Could not locate clojure/core/match__init.class or clojure/core/match.clj on classpath.", :via [{:type java.io.FileNotFoundException, :message "Could not locate clojure/core/match__init.class or clojure/core/match.clj on classpath.", :at [clojure.lang.RT load "RT.java" 449]}], :trace [[clojure.lang.RT load "RT.java" 449] [clojure.lang.RT load "RT.java" 412] [clojure.core$load$fn__54...
04:32escherize,(use core.match)
04:32clojurebot#error{:cause "core.match", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.ClassNotFoundException: core.match, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.ClassNotFoundException, :message "core.match", :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}], :trace [[java.net.URLClassLoader$1 run "UR...
04:32escherize,(use 'core.match)
04:32clojurebot#error{:cause "Could not locate core/match__init.class or core/match.clj on classpath.", :via [{:type java.io.FileNotFoundException, :message "Could not locate core/match__init.class or core/match.clj on classpath.", :at [clojure.lang.RT load "RT.java" 449]}], :trace [[clojure.lang.RT load "RT.java" 449] [clojure.lang.RT load "RT.java" 412] [clojure.core$load$fn__5427 invoke "core.clj" 5862] [cloj...
04:32escherizedamnit im sorry
04:32goraciocljs.core.PersistentArrayMap
04:32goracioit's this
04:33dysfunhrm, the bot should really pastebin those or something
04:33goracioArrayMap
04:33dysfunArrayMap is like a map
04:33dysfunit just happens to be ordered
04:33escherizeTIL
04:33escherizewait i notices something, goracio:
04:33escherizeyou said the map looks like {"title":"Hello world !!! "}
04:33goracioyep and it should give some value from (:title response)
04:34escherize,(:title {"title":"Hello world !!! "})
04:34dysfun(see "sorted-map")
04:34clojurebot#<RuntimeException java.lang.RuntimeException: Invalid token: :>
04:35escherizeI think it's a cljs map with keys that are strings
04:35dysfuni presume the colon is from familiarity with javascript :)
04:35escherizei copy pasted. :(
04:35escherize,(:title {"title" "Hello world !!! "})
04:35clojurebotnil
04:35dysfunaha, the string keys
04:36escherize,(get {"title" "Hello world !!! "} "title")
04:36clojurebot"Hello world !!! "
04:36goraciowell i use :format {:json-kw
04:36dysfunwell are they coming back as keywords or not?
04:37goraciothat worked )
04:37goracio(get ....
04:38escherizeyeah you should find a way to make them keywords if possible
04:38goraciothere is option :keywordize? true
04:38goraciowill try it
04:39goraciooption is not working (
04:40goraciohow to send in :edn format ?
04:40goracioi use wrap-restful-format
04:41escherize,(-> {:a 1 :b 2} pr-str read-string)
04:42clojurebot{:a 1, :b 2}
05:09escherizeFlex box from reagent: http://re-demo.s3-website-ap-southeast-2.amazonaws.com/
05:11goraciowell what the best way to handle json api still ?
05:11goraciocompojure-api ?
05:13escherizecompojure-api is kind of complicated, but has tons of benefits.
05:14goraciowell that stuff with cljs-ajax also not the best option
05:14goracioi guess
05:14goraciowith all that conversions from string to keywords
05:15Deraengoracio: If you're having problems with cljs-ajax you could try cljs-http
05:18goraciook will look at it
05:19escherizeyou could do the string -> keyword thing yourself
05:19escherizenot the best idea but it's quick:
05:20escherizehttps://gist.github.com/764023fab0ac3be11440
05:22goraciook
05:25goracioescherize: what the best way to display that arraymap ? with map or with for ?
05:26escherizeyou can print it to the console with (.log js/console <map-name>)
05:26goracioi mean in reagent
05:26escherizeohhh
05:26escherize[:pre (pr-str <array-map>)]
05:27escherizeworks wonders
05:27escherizeI have another way too, sec
05:27escherizeI wrote this for a toy project
05:28escherizehttps://gist.github.com/e1fe925e5af4eb52ce99
05:28goracioi saw this style https://gist.github.com/fellz/416942e5e22191075e6b
05:29escherizedid you want to see the text representation of the map, or display its contents?
05:29goraciodisplay contents
05:29goraciolist of articles in this case
05:30escherizeyou can use either.
05:30goracioarticle has title author subject and _id
05:34goracioescherize: undeclared variable table
05:35goracioi guess it's recursion
05:41goracioescherize: it doesn't work i have 2 articles so it's arraymap and then each article also arraymap
05:54escherizegoracio: you mean you have a structure like [{:a 1} {:a 2}] ?
06:12goracioescherize: yep
06:58supersymdo we have anything that can support a notion of 'shorthand' paths e.g. [:a :b [:c :d]] becomes [:a :b :c] and [:a :b :d] (potentially nested deeper ofc)
06:58supersymlike a flatten/combinations mix I guess
07:35irctcHi I'm baffled why
07:35irctc(let [] (map println #{1 2}) (map println #{}))
07:35irctcdoesn't print anything
07:36irctcat all!
07:37puredangermap is lazy and you didn't realize it
07:38irctcoh shit
07:38puredangerWrap doall or dorun around it to realize
07:38irctcok
07:38irctcthanks guys
07:39mnngfltgirctc, `map` just returns a LazySeq and doesn't automatically realize it
07:40irctcbtw is there a macro to realize a sequence
07:40irctcthat i can use just outside of a map
07:42mnngfltgirctc, doall?
07:43irctchmmmm
07:43irctcok thanks people
07:43irctc:)
07:43LnLI have an issue with vendor prefixing in garden, has anybody here used it before?
07:45LnLIs there a way to do `{:display #{"flex" "-webkit-flex"}}` but with the builtin prefixing
08:19andrew_Hi all! Why it is not possible to see output if launching a .clj script with 'java ...' command?
08:41gfredericksandrew_: what does "output" mean?
08:42gfredericksjustin_smith: that makes me feel all patriotic https://www.youtube.com/watch?v=lyHSjv9gxlE
08:48kaiyinhttps://gist.github.com/kindlychung/91199d72b031ff8c2c95 Isn't it a bit disturbing that [node value] is repeated multiple times?
08:49andrew_gfredericks: side effect of println. Actually solved te issue: goo.gl/YjT2rc
08:52gfredericksah yeah
08:52gfrederickskaiyin: not if you like it always being lexically obvious where things come from
08:54kaiyingfredericks: that should be a problem if you see defmulti-defmethod-defmethod... as a whole entity.
08:54kaiyinshouldn't
08:55gfrederickskaiyin: well, you could write a macro to dry it up if that's your preference
08:56Glenjaminif you want a whole entity
08:56Glenjaminuse case / cond
08:56gfredericksor condp
08:56Glenjaminthe idea with multimethods is they're open to extension from anywhere
08:57kaiyinGlenjamin: Ah, I see.
09:07kaiyinhow do you remove a multimethod in the repl?
09:20kaiyinwhy do we need #' prefix for the dispatch function? https://gist.github.com/kindlychung/bfc4cbad0b01a866b452
09:34gfrederickskaiyin: because multimethods don't let you update the dispatch function; so #' works around that with indirection
09:35kaiyingfredericks: what does #' do exactly?
09:36justin_smithgfredericks: that punch at the end really does it
09:37justin_smith,'#'+ ; kaiyin
09:37clojurebot(var +)
09:38gfredericksnow I wish that talk I did on vars was recorded
09:38kaiyin,(var var)
09:38clojurebot#error{:cause "Unable to resolve var: var in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve var: var in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6740]} {:type java.lang.RuntimeException, :message "Unable to resolve var: var in this context", :at [clojure.lang.Ut...
09:39gfredericks,(var var var var var chex var)
09:39clojurebot#error{:cause "Unable to resolve var: var in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve var: var in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6740]} {:type java.lang.RuntimeException, :message "Unable to resolve var: var in this context", :at [clojure.lang.Ut...
09:39gfredericks,(quote)
09:39clojurebotnil
09:39gfrederickssorry am being unhelpful
09:39gfrederickskaiyin: vars are the houses your functions live in
09:39gfrederickssort of
09:40kaiyinok
09:40kaiyinhow does that solve the updating problem?
09:40justin_smithkaiyin: a namespace is a collection of vars
09:40kaiyinok
09:40gfrederickskaiyin: a var can pretend to be a function by proxying the call to the function it's housing
09:40justin_smithwhen you pass the var rather than the value of the var, when the namespace changes, the thing sees the new value in the namespace
09:42justin_smith(the one gotcha being if you destroy and recreate the namespace, like clojure.tools.namespace can do, this stops working - because there is actually a different var created)
09:42kaiyinin other words, the var always points to the lastest version of the function.
09:42justin_smithright
09:42gfredericksindeed; almost by definition
09:43justin_smithkaiyin: another way to see it - def alters the value of the var, if you want a new def / defn call to change your other code, referring to the var helps
09:43kaiyinok, got it.
10:04gfredericksmost of the time it's not necessary though
10:20michaelr`hi
10:20michaelr`Is this a known problem that an uberjar would start especially slow on osx?
10:39justin_smithmichaelr`: I'd suspect some delay in acquiring a resource
10:56justin_smithalso, you could use jstack to find out what it's doing when it is taking so long
14:52TimMcclojurebot: offline development |is| http://lolnein.com/2013/09/25/withoutinternet/ (semi-NSFW)
14:52clojurebotRoger.
15:28kaiyinhttps://gist.github.com/kindlychung/97bf9b74daf0230ea4f6 I am thinking that this way of generating dispatching keywords could go very wrong. e.g. tag1 is :a , type1 is :b.c tag2 is :a.b , type2 is :c
15:30patrkrishi folks. is there a predicate somewhere or an idiomatic/easy way to test whether two sets are disjoint?
15:35kaiyin,(def s1 #{1 2 3})
15:35clojurebot#'sandbox/s1
15:35kaiyin,(def s2 #{4 5 6})
15:35clojurebot#'sandbox/s2
15:36kaiyin,(every? #(= % nil) (map s1 s2))
15:36clojurebottrue
15:36kaiyinpatrkris: ^ my two cents.
15:36patrkriskaiyin: thanks :)
15:38oddcullys/#(= % nil)/nil?/
15:38Bronsakaiyin: that won't work if the set contains `nil`
15:39Bronsapatrkris: (comp empty? clojure.set/intersection) should do it
15:40patrkrisBronsa: ah of course... thanks
15:40patrkris:)
15:40oddcully,(empty? (clojure.set/intersection #{nil 1 2} #{4 5 6}))
15:40clojurebot#error{:cause "clojure.set", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.ClassNotFoundException: clojure.set, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6740]} {:type java.lang.ClassNotFoundException, :message "clojure.set", :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}], :trace [[java.net.URLClassLoader$1 r...
15:40oddcullyoh... too late anyway
15:42kaiyinBronsa: yeah, that's much better.
15:45kaiyinIs there a way to make the repl automatically use pprint every time it prints something?
16:34dumptruckhello
16:35dumptrucki am trying to use a java class annotation in clojure
16:35dumptruckit looks like gen-class is capable of this but i can't find very much documentation
16:35dumptruckin particular, i'm not sure of the structure for the metadata on the :name
16:36dumptruck(gen-class :name ^{somethinghere} com.whatever.Classname)
16:37dumptruckit appears to be a map which is pretty self explanatory... but I want to add an annotation which would look like this in java: @Plugin(id = "theid", name = "thename")
16:38dumptruckwhich i would imagine goes like so: (gen-class :name ^{Plugin {id "theid" name "thename"}} com.whatever.Classname)
16:38dumptruckbut my ide is complaining about id
16:41dumptruckdoes it need to be ^{Plugin {:id "theid" :name "thename"}}
17:41x1n4u(map '(1 2 3) '(4 5 6))
17:41x1n4u,(map '(1 2 3) '(4 5 6))
17:41clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn>
17:46justin_smithx1n4u: map needs a function
17:47oddcully(inc Bronsa) ; dijoint
17:47lazybot⇒ 110
18:03crazydiamondHi. I'm trying to delete and create Datomic database at a heat. But after creation when I "connect" to the URI it fails with error "database does not exist". But in console I see the database after delete/create sequence. Can anyone suggest, should I add some "sync" command to it or whatever? http://dpaste.com/1A4GW5X
18:05bensucrazydiamond: my solution to that problem was to add a timeout
18:05crazydiamondbensu, interesting
18:06bensucrazydiamond: I don't remember correctly but it was longer than expected and not very reliable
18:06crazydiamondyes, seems like that. cause in command line it was already done with timeout
18:06crazydiamondlike 0.5-1 sec
18:06crazydiamondfor me to type next command
18:07bensuyeah, I'm not sure but my timeout was over 2sec
18:07crazydiamondI wonder what should happen
18:07dlauwhat is the difference between (mapv #({:a %}) ["foo" "bar"]) vs (mapv (fn [v] {:a v}) ["foo" "bar"]) ? i feel like im misunderstanding the function macro :l
18:07bensuafter trying a couple of times
18:08justin_smith,'#{:a %}
18:08bensudlau: the first one thinks {} is a function
18:08clojurebot#{% :a}
18:08crazydiamonddlau, if you write #({:a %})
18:08justin_smitherr
18:08justin_smith,'(#{:a %})
18:08clojurebot(#{% :a})
18:08crazydiamondit would run map {} as a function
18:08justin_smith,'#({:a %})
18:08clojurebot(fn* [p1__73#] ({:a p1__73#}))
18:08justin_smiththat's the one I wanted
18:08justin_smithnote how it is calling the hash map with no args
18:08crazydiamonddlau, use rather #(do {:a %})
18:09justin_smithuse fn
18:09crazydiamonddlau, "do" is one way to understand function macro better :-)
18:10dlauoh
18:10dlauwoah that bot is cool O.O
18:12dlaugreat thanks so much, I thought #({}) would return a function hehe
18:14justin_smithit does, it's just a function that calls a hash map with no arguments
18:16justin_smith,(#({:a 0}) :a)
18:16clojurebot#error{:cause "Wrong number of args (1) passed to: sandbox/eval98/fn--99", :via [{:type clojure.lang.ArityException, :message "Wrong number of args (1) passed to: sandbox/eval98/fn--99", :at [clojure.lang.AFn throwArity "AFn.java" 429]}], :trace [[clojure.lang.AFn throwArity "AFn.java" 429] [clojure.lang.AFn invoke "AFn.java" 32] [sandbox$eval98 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler ev...
18:16justin_smithoops
18:16justin_smith,(#({:a 0} :a))
18:16clojurebot0
18:17oddcully,(map :a {:a 0})
18:17clojurebot(nil)
18:23whodidthiswhats a fun way to add mime types to files served with ring.middleware.resource/wrap-resource
18:33whodidthisfound it
18:43RaynesTEttinger2: Yo
18:44gfredericksyo
18:45Raynesyo
19:09xzilendFor a clojure app that pulls data from an API and puts it into redis, would you prefer to have a constantly running app with an internal scheduler, or a tight app ran with cron?
19:23mavbozo_xzilend, constantly running app
19:24mavbozo_xzilend, i prefer doing as many as possible in clojure
19:46underplankHey all.. Anybody know if you can use the scratch-buffer in emacs to execute s-expr in cider using C-x C-e?
19:59escherizeHas anyone here used re-com? https://news.ycombinator.com/item?id=9521955
20:00escherizeit's a component library on top of reagent
20:23gfredericksunderplank: I do that all the time, I just have to switch it to clojure-mode
20:29underplankgfredericks: ahh… I thought it might be something like that… so M-x clojure-mode ?
20:30gfredericksunderplank: yep
20:30gfrederickswhich turns on cider mode for me, not sure if that's normal
20:30underplankgfredericks: ahh. ok… i’ll have a look.. I can always flick that on as well.
21:51justin_smithgfredericks: cider installs a hook on clojure mode
22:09underplankSo I have a ring handler. And I want to initiate a webhook only AFTER the response has been returned by the ring hander. I could spawn a future with a delay in the middle of the handler but this seems not great. Is they anyway I can attach an event to the return of a function?
22:11justin_smithunderplank: middleware can easily do some action after the wrapped function (but it should usually return or modify the value the wrapped function returned)
22:12underplankjustin_smith: hmm yeah I thought about that. Would you basically just pass something back from the handler in the return function that the middle ware would pick up?
22:12underplanksorry return data
22:12justin_smithsure, if it needed some extra input beyond what the handler returned
22:14underplankok. that might work.thanks!
22:34weiHas anyone used Om or Reagent with react-bootstrap? I’m trying to implement a popover
23:09jdkealyanyone ever run into an issue of serving javascript and css at non-https path and getting insecure link errors ?
23:09jdkealysorry wrong chan ...