This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-22
Channels
- # aatree (21)
- # announcements (10)
- # avi (1)
- # aws (15)
- # beginners (96)
- # boot (269)
- # braid-chat (92)
- # cider (9)
- # clara (10)
- # cljs-dev (3)
- # cljsjs (14)
- # cljsrn (20)
- # clojure (198)
- # clojure-art (3)
- # clojure-hamburg (2)
- # clojure-ireland (4)
- # clojure-russia (117)
- # clojure-spain (3)
- # clojured (1)
- # clojurescript (253)
- # code-reviews (6)
- # community-development (7)
- # conf-proposals (52)
- # core-async (4)
- # cursive (4)
- # datomic (4)
- # devcards (1)
- # emacs (59)
- # euroclojure (5)
- # funcool (1)
- # hoplon (39)
- # human (1)
- # jobs (4)
- # ldnclj (15)
- # ldnproclodo (1)
- # leiningen (3)
- # mount (37)
- # off-topic (14)
- # om (77)
- # perun (10)
- # proton (12)
- # rdf (1)
- # re-frame (9)
- # reagent (42)
- # ring-swagger (10)
- # yada (50)
Is there a function like map, but where I can discard some elements? A kind of combined remove+map where I would remove elements I don't need, and transform the ones I do at the same time?
@didibus: you could do that using reduce. it would be cleaner to just compose remove
and map
though
@bfabry: If I compose remove and map, it'll loop twice though. But on #C03S1KBA2 irc I was told about the keep
@didibus: if you compose them as transducers it won't š alternatively, the reduce
version (reduce #(if (odd? %2) (conj %1 (inc %2)) %1) [] [1 2 3 4 5])
Hum, I hadn't really paid attentions to transducers. Pretty cool though, I was actually wondering how to do that in Clojure
@didibus: transducers form user=> (into [] (comp (map inc) (filter odd?)) [1 2 3 4 5 6 7 8]) ;; assuming you want the result in a vector
actually my transducer form was round the wrong way in comp, should be (into [] (comp (filter odd?) (map inc)) [1 2 3 4 5 6 7 8])
Well, we have Clojure 1.8.0 live in production on three of our five servers. New Relicās epic fail this afternoon called a halt to our rolling upgrade.
First time weāve direct linked our entire code base!
if i use the current version from the luminus template versus an older version from a tutorial (clojure web development essentials)
Using Leiningen? If so, try lein deps :tree
and see if it identifies the conflict in versions for you.
Java library versions can be a bit of a pain point since itās hard to tell when theyāve introduced incompatible changes a lot of time š¦
i tried lein deps :tree, but i canāt find the problematic library listed in the output
any suggestions on getting a backend websocket server going? looking for more of a small library than a http://socket.io equivalent.
why might a BufferedImage's .getHeight() be underreporting the height by roughly 37 pixels?
I have a ring app serving some css and png files, the css load on my page fine but the images will not loadā¦ says not found?
@flyboarder what is your static ring handler setup like?
possible related if pngs are referenced from css files remember the png path is then relative to the css path not the root /
@nowprovision: i dont know what you mean by relative to css not root / ??
are the png references in the html
or in the css files?
what does your ring handler setup look like?
try changing to route/files unless your intent is a single war at the end
@nowprovision: haha that seems to have stopped serving all the static files š
change root-path to "resources/"
one sec
(route/files "/" { :root "resources/" } ) or (route/files "/" { :root "resources/public" } )
https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/util/response.clj#L123
from https://github.com/weavejester/compojure/blob/1.4.0/src/compojure/route.clj#L25
using files still resulted in no assets served, resources correctly serves css via html but not images
Is it possible for me to have parallel operations inside a doseq? doing some stuff with side-effects, but here's a hackeneyed example:
(defn wat []
(let [a (range 2)
b (range 2 4)]
(doseq [x a
y b]
(prn (str x " " y)))))
expected outcome: 0 2
1 3
there may be a more idiomatic way of doing this, but i've used something like
(let [a (range 2)
b (range 2 4)]
(doseq [[x y] (map vector a b)]
(prn (str x " " y))))
you can of course also use map+doall as an alternative to doseq, which might be better since it's mapping anyway
i.e.
(let [a (range 2)
b (range 2 4)]
(doall (map (fn [x y] (prn (str x " " y))) a b)))
@dmitrig01: Yes, it worked thanks!
How about (doseq [[x y] (zipmap (range 2) (range 2 4))] (prn x y))
?
Since you're printing, you really want the side effects, not the result, so you don't really want (doall (map ...))
mapv i think is eager
having trouble with my log in function.anyone who can help?
am new to clojure trying to learn making my own web application
@samlinncon are you using a library?
no am not using any library,just a query to the database
(defn login "function used to authenticate users in the system" [id username password role] ;;validate form (cond (empty? username) (layout/render "login.html" {:msg "Please Enter a username"}) (empty? password) (layout/render "login.html" {:msg "please enter a password"}) (empty? role) (layout/render "login.html" {:msg "please select a role"}) (not (seq (db/get-userinfo-by-username username))) (layout/render "login.html" {:msg "Username does not exist"}) (not (crypt/compare password (:password (first (db/get-userinfo-by-username username))))) (layout/render "login.html" {:msg "Incorrect Password"}) :else (let [user-data (first (db/get-userinfo-by-username username)) id (:user_id user-data) role user-data] ;;set the session data (println ":::" username role) (println "###" util/set-session-data!) ;;(util/set-session-data! id username password role ) (cond (= role "admin" ) (layout/render "admin/admin.html") (= role "secretary" ) (resp/redirect "secretary/secdashboard.html")))))
page not found
login post url
@samlinncon show your routes.
(defroutes home-routes (GET "/" [] (login-page)) (GET "/reset" [] (reset-password-page)) (GET "/about" [] (about-page)) (POST "/login" [ id Username password role :as req](println ":)" req) (login id Username password role)))
hey @samlinncon what does your form action say?
Any particular reason i shouldn't use (. clojure.lang.RT (nextID))
(stolen from the gensym source) to generate an int that's unique throughout the running app? I'm wrapping a java library which has methods which require a unique id be passed to it on each call.
there are several "types" of ids which must be tracked and that would be much easier of a solution than figuring out where to put a bunch of incrementing atoms
@jjttjj: as a rule of thumb, don't rely on anything from the java sources of clojure except for the clojure.lang
public interfaces and clojure.java.api.Clojure
,
@bronsa: so using MultiFn
directly instead of through defmulti
and defmethod
is okay by that rule?
@bronsa: right, you did. And it's a class. And I see no interface exposing adding methods. Kinda sad, since I was using it as a dispatcher in a component and it worked well so far.
(defn gen
"Returns a function that, when called, will call f with an incremented
generation number and an additional context data argument."
[f]
(let [generation (volatile! (long -1))]
(fn
[data]
(vswap! generation #(inc (long %)))
(f @generation data))))
@bronsa: So I wanted to dispatch on handlers registered by dependent component. Hence I need to register multimethods at system boot time and I potentially might have more than one instance of a component, then I can't use a global variable multimethod, since components could potentially clobber the handlers. So I figured a multimethod not bound to a var, but used as a component record field would make sense.
hi vim users, are you able to get java classes auto completion hints using vim fireplace?
I remember having this some time back but i am not getting any completions with my current setup
@kul: Yes. At least with cider-nrepl.
What are you trying to autocomplete and in what context?
Works for me. And have you loaded the ns?
@meow: is doing something like this better than just having a top level atom that i keep inc-ing?
(defn gen
[]
(let [generation (volatile! (long -1))]
(fn
[]
(vswap! generation #(inc (long %))))))
(def next-id (gen))
(next-id)
Or is this abusing it and the gen function should strictly be intended to wrap another function?And triggerin autocomplete shold anyway load the ns if it's not loaded
Nope, I run repl on separate terminal
that code I posted was just an example - you could further modify it to suit your needs better
hey @jaen fwiw, defmethod is just sugar on (.addMethod multiFn): https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L1669 and defmulti similarly is just doing (new MultiFn).
@jonahbenton: yes, I did figure that out and it's exactly what I'm doing right now, but while defmethod
can be basically used as-is with a free-standing MultiFn
(although the def
in the name is slightly misleading), defmulti
has no such non-`def` alternative and I my question was in light of what bronsa said about relying on implementation details - basically if it's kosher to rely on such implementation details.
@jonahbenton: problem is that being macros you can dynamically add methods or define multimethods at runtime
oh the bright side i came to know about ultra from @juhoteperi 's dotfile
@jaen depends on what you mean by rely. If you're making a lib, yeah, probably bad idea without requisite disclaimers. If you're making an app, well- your source code may not be forward compatible with later versions of clojure, and you can check that at startup- if (new MultiFn) fails, you exit. A packaged app would continue to work, modulo maintenance concerns on this specific architectural decision.
Well, I'm hoping for it to be a lib at some point, so yeah, better to avoid it. So nice to hear a patch to expose that in clojure.core
is welcome.
(it's basically an event handling component for event sourcing that gathers all domain events from it's dependencies)
@jaen gotcha, you're basically talking about dispatch on event type
Yup; I just figured I could use something that Clojure already has instead of rolling my own.
know about core.match?
Sure I do, my first exposure to FP was Haskell, so it's one of the first libraries I add to any project ; d
yup, gotcha. runtime defined dynamic predicate dispatch
Yup. I could probably just shove all handlers into a map and call it a day, but I figured MultiFn
is probably more optimised than that ; d
protocols are fairly amenable to this kind of programmatic construction
but of course limited to selection based on type
protocols are essentially defined as a big map of fns
I need [event-type event-version]
at least, so protocols could become an awkward visitor pattern
@jaen are your events derived from parsing a data steam?
@alexmiller: thanks- would you agree that direct use of MultiFn- create new, .addMethod, etc- would be undesirable in a library?
I would consider MultiFn to be part of the implementation and subject to change
not that we have any plan to change it :)
@alexmiller- thanks, makes sense. Any reason that an add-method doesn't exist in core, or patch for same would not be welcomed?
Can imagine concerns related to lifecycle- what impact would add-method at runtime have on safety. But there is remove-method...
not known to me :)
sometimes you can find more background by trolling the clojure irc logs around when things were added
MultiFn dates back to sept/oct 2007
hrm, unfortunately that's pre irc
which started in feb 2008
looks like there was an earlier PolyFn
gotcha, thanks Alex, that makes sense
https://github.com/clojure/clojure/commit/fe567065b55b47705a6292e6f993001e4ef31997 seems like where things started to look like today
the intention there seems to be that defmethod is the way you add methods to a multi
seems like defmethod body could be split into the var part and the add part though
interesting comparing that commit with https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L1691 vars originally had a dispatch map?
but now, yeah, looks like defmethod could be cleanly split. and I see addMethod uses rwlock around the method table.
Hi developers! I'm new in this and I would like to know about the following commands: lein figwheel lein run lein cljsbuild auto I'm a little confused about them because I don't know if "lein figwheel" does the same as lein "cljsbuild auto; lein run"
Not the same. Among other things, lein figwheel gives you a repl that can run code in your browser.
So, if I run ālein figwheelā is not necessary to do a "lein cljsbuild auto; lein runā right?
@jaen: core.match ? I'm using it for event dispatch
static but flexible
(although it would be nice to have a dynamic solution)
I'm getting a java.net.SocketException "Permission Denied" error when running my ring/jetty server - trying on all different ports, all above 1024, and it it just doesn't seem to want to start ā any advice? trying to bind both to 0.0.0.0 and 127.0.0.1, doesn't work either
hey @dmitrig01: try -Djava.net.preferIPv4Stack=true ?
argh we still need this kind of hacks in 2016 ? God, IPv6 will never prevail
It's often a symptom of wrongly configured IPv6 or even some tools (like remote desktop, security tools messing up IPv6)
I've seen stuff like this where there is an ipv6 localhost in /etc/hosts before an ipv4
Heya! Does anyone have any experience with data streaming libs in Clojure I should take a look at? I know of Storm and Onyx; most of the Hadoop stuff seems to be focused on traditional Hadoop jobs rather than online processing.
I would not recommend Storm for new clojure projects unless you either already have a storm infrastructure and experience or you need to take advantage of the multiple language capabilities. It takes a lot to get right, and having used it for awhile, I don't see any compelling advantages of it (outside of multi language) compared to Onyx.
ack - that didn't help. turned out i set up the configuration wrong to the point where the port wasn't even getting passed into jetty, so it was trying to bind to a nonexistant port
(inc bja)
Onyx looks really cool and seems to aim at being Storm without the quirks
Iāve used Storm for a long time, itās a good tech, but clojure DSL is not great and very seldom used in the community apparently
I'll also note that stand alone clojure apps via docker images consuming kafka/sqs solve a lot of my problems given that I've already solved how to deploy random containers and manage my queuing system. You end up writing a small internal library for metrics/logging anyway, and if you can reuse that, deploying a single container or uberjar isn't usually too different from deploying a lot of them.
Hello. I can answer questions about Onyx. @lvh
michaeldrogalis: Hiya! Iāve never had an excuse to use Onyx yet but it looks like that might be changing Iām not sure we can get away with just Onyx, though; we have some stuff thatās online (data enrichment stuff), but a bunch of stuff thatās offline, for which HDFS still seems to be the standard data store. What do you normally store data going out of Onyx in, assuming that at some point Onyx is going to look at it again?
michaeldrogalis: the competing design is just a bunch of HDFS, with spark streaming attempting to do the realtime stuff, which is somewhat of an open question if it can actually do it
@lvh Storage choice is heavily dependent on the application, can't generalize that.
We're working on better integration points with HDFS, but it's mostly being driven by customer demand. Time is at a premium
michaeldrogalis: Sure, that makese sense Weāre looking at fairly large amounts of data (often includes pcap, netflow, &c), a lot of it sensitive, so being able to run on dedicated hardware is a plus; combine with in-house expertise on running HDFS, and HDFS becomes a clear first candidate
michaeldrogalis: you do do a bunch of āofflineā data processing a la classic Hadoop MR with Onyx, though, right? Just not from/to HDFS?
@lvh: Yeah, most projects that I've consulted on have used Datomic as a storage target for moving around large-ish blocks of immutable data
michaeldrogalis: napkin-mathy weāre looking at >200PB so a few of the simpler options arenāt applicable
Hey, big thanks to everyone for help with my cluster simulator. Iām really close. Iāve figured out pubsub in core.async, and using go blocks to simulate workers. Iāve got the fn for one worker+inputs/outputs. I canāt quite figure out how to build the pubsub channels with the dependency DAG tho. I think I want to do some kind of reduce(?) across a depth-first traversal, chaining the pubsubs together, with the final result being the āheadā channels I put the data into. Does that make sense? Iām using Loom. cc @danielcompton š° ā š¶
nice work!
Code if anyone's got wisdom, apologies for the ugly https://gist.github.com/LusciousPear/6b99efc863735aab0d44