#clojure logs

2016-02-14

05:45vivekramaswamyA quick question, I am getting a stack overflow in this small clojure program, not sure why ideas would help? http://shortText.com/736de871
05:48blur3dvivekramaswamy: you’re not using the correct recursion syntax
05:49blur3dYou use ‘recur’ instead of your function name - https://clojuredocs.org/clojure.core/recur
05:49vivekramaswamyok, got it, thanks a lot
06:05LauJensenGents, is there a switch which detect if AOT compilation is running? I have a java lib that dies if its called during AOT compilation, so I need it to bypass a certain line until the app is actually launched
06:11vivekramaswamyHello blur3d, I did the change, but still end up getting a compilation error, any ideas, https://codeshare.io/F4J46
06:16blur3dvivekramaswamy: Well, you’re missing a closing paren
06:21vivekramaswamyThank you blur, working off a textpad is a pain while using clojure, any easy to use editor other that emacs that you are aware of, that wil check for parens
06:29blur3dvivekramaswamy: What do you want the function to do? Print out each item in the list one by one?
06:31blur3dif so, no need for recur… just use (map #(println %) '(1 2 3))
06:31blur3d,(map #(println %) '(1 2 3))
06:31clojurebot(1\n2\nnil 3\nnil nil)
06:31TEttinger,(map println [1 2 3])
06:31clojurebot(1\n2\n3\nnil nil nil)
06:32blur3dvivekramaswamy: lighttable is fairly friendly.. i’d give it a go
06:32TEttinger^ blur3d
06:32TEttingerno need for anonymous fns wrapping something if it's being called with the args as-given
06:33blur3dTEttinger: that works also, haha… haven’t written clojure in over a year now
06:33TEttinger,(map str '(a b c) [1 2 3])
06:33clojurebot("a1" "b2" "c3")
06:33TEttinger,(map str '(a b c) [1 2 3] "?!@")
06:33clojurebot("a1?" "b2!" "c3@")
06:34TEttingerI love how versatile the seq abstraction is
06:34TEttingerstrings are seqs of chars! now everything's easier!
06:35blur3dYeah. I really loved using clojure.. I’ve just changed my line of work
06:36blur3dI have a personal project that is highly data driven and lazy, so I hope to prototype it in clojure soon
06:37vivekramaswamyNope blur3d, I was just reading a book and trying out recur, you are right for something as simple as this I can use a map, but I just wanted to try doing it using recur
06:38noncomhow to make a server built on ring/compojure accept params passed in url, like "http://some-url?id=1&something_else=2
06:57blur3dnoncom: http://stackoverflow.com/questions/7785214/compojure-how-to-map-query-parameters
08:03side_effect1hello. I started learn clojure with clojurescript repl. I want to reproduce this code in repl [datascript.core :as d] context https://github.com/bnomis/om-next-datascript-localisation-demo/blob/master/src/om_next_datascript_localisation_demo/datascript/db.cljs#L5
08:04side_effect1I know I should start from basic and the I can write some combination from marcos import, def, refer
09:16justin_smithside_effect1: (require '[datascript.core :as d]) works in a repl
09:16justin_smithside_effect1: also, you can run the ns form exactly like it is there, in a repl
09:21side_effect1justin_smith, thanks. It works.
09:22justin_smithside_effect1: in general there are very few things you can do in a source file that you can't do in a repl
09:22justin_smith(and even with those there's a way to do it if you really want to)
09:23hodwikAny idea why in Emacs I would get Namespace not found. for everything in the repl
09:23hodwikincluding simple stuff like (+ 1 1)
09:24justin_smithhodwik: because you ran (in-ns 'some-ns) for an ns that was not loaded yet
09:24justin_smithhodwik: run (clojure.core/refer-clojure) to restore sanity
09:24hodwikNamespace not found. :L
09:25justin_smitheven (clojure.core/refer-clojure) doesn't work?
09:25hodwikYeah
09:25justin_smithbecause clojure.core is kind of needed in order to have a repl at all...
09:26hodwikYes, that makes sense
09:26justin_smithwait, is "namespace not found" a clojure error or a CIDER one I wonder?
09:26justin_smithbecause it could be CIDER is just in a broken state
09:28hodwikSo, the repl works until I change namespace to my project
09:28hodwikthen nothing works
09:28justin_smithhow are you loading your project namespace?
09:28justin_smithis it automatic? are you sure it is actually happening?
09:28hodwikC-c M-n from the .clj window
09:32hodwikHow about I rewind a step, is there an out-of-the-box emacs setup for clojure
09:32hodwikbecause I suspect I am setting something up incorrectly, but there's too many moving pieces for me to figure out what it is
09:34justin_smithhodwik: best practice with cider is to nuke it all (plugin for clojure and all elisp / elc related to clojure), then reinstall a specific version. And never do in-place incremental updates.
09:34justin_smithAlways remove everything before updating.
09:35justin_smithfrankly I got tired of the breaking things and just use a repl in a terminal now. (require 'foo.bar :reload) after saving a file does as much as I actually need
09:36hodwikI don't blame you, this emacs/clojure integration seems very touchy
09:36hodwikThis is install attempt 3 for me, still can't get it to work as described in the braveclojure book
09:37justin_smithactaully for files in another project, on disk, but loaded as a dep from a jar, you also occasionally need (load-file "/full/path/to/file.clj")
09:37justin_smithbut anyway those things are pretty much all that's needed to redefine anything at runtime, which is the amount of integration I really need.
09:38hodwikSo you're just using lein from terminal
09:39hodwikwhat about for editing?
09:39justin_smithemacs
09:39justin_smithjust clojure mode
09:39hodwikOh, but you just run your code in the term window?
09:39justin_smithright, using require or load-file as apropriate to load new definitions
09:40hodwikI'm comfortable with that workflow, I think I'll switch to that
09:40hodwikthank you
09:40justin_smithwhen working that way, clojure.repl/dir and clojure.repl/apropos become very usefil
09:40justin_smith*useful
09:41hodwikI'll take a look at those
10:25LauJensenGents, is there a switch which detect if AOT compilation is running? I have a java lib that dies if its called during AOT compilation, so I need it to bypass a certain line until the app is actually launched
10:26justin_smithLauJensen: the standard way to do this is to put the line in question inside a function that gets called. Or does the line cause this error even inside a function body definition?
10:28LauJensenjustin_smith, Its the instantiation of a global. I could wrap it in an atom and init it in -main
10:28justin_smithLauJensen: you can also use declare, and actually assign the value in -main
10:29justin_smithor even use a delay
10:29justin_smithno need for an atom if it isn't going to get multiple values at runtime
10:29LauJensenA delay?
10:29justin_smith,(def foo (delay (do (println :realized) :OK)))
10:29clojurebot#'sandbox/foo
10:30justin_smith,foo
10:30clojurebot#object[clojure.lang.Delay 0x54ae79a7 {:status :pending, :val nil}]
10:30justin_smith,(realized? foo)
10:30clojurebotfalse
10:30justin_smith,@foo
10:30clojurebot:realized\n:OK
10:30justin_smith,@foo
10:30clojurebot:OK
10:30LauJensenOh right
10:30justin_smiththe code in delay gets called once, on first deref, then it holds that value
10:30LauJensenGood tip, thanks
10:31LauJensenIn my test, delay fires immediately
10:31justin_smithare you dereffing immediately?
10:31LauJensenno
10:32justin_smithumm... then you are doing it wrong somehow
10:33LauJensentry this, (def tst (javax.swing.JOptionPane/showMessageDialog nil "TST"))
10:33LauJensenand on my system, it pops before dereffing
10:33justin_smithumm, that's nopt delayed
10:34justin_smithLauJensen: (def tst (delay (javax.swing.JOptionPane/showMessageDialog nil "TST")))
10:34justin_smiththat won't pop the window until you run (deref tst) or the equivalent @tst
10:34justin_smith(just verified in my own repl)
10:38justin_smithLauJensen: also I discovered that call returns nil - it's not a value at all just a side effect. Which makes me think you don't want a delay, just a function call.
10:38justin_smith(if that's equivalent to what your code was doing)
10:39LauJensensorry, i just forgot to type delay in here, had it in the repl
10:39LauJensenNo wait, i didnt, nevermind :)
10:39justin_smithhaha
10:41LauJensenThanks for taking the time Justin
11:03insamniacanyone use quil much? I'm trying to figure out the best/right way to handle input from a channel
11:05benjyz1is there any good irc channel for web-security?
11:05insamniacmy simple brain wants to make the channel read to update some mutable external state, and have quil :update look at it
11:05benjyz1..maybe someone here knows
11:06insamniac##security maybe
11:20insamniacor i guess if i'm smart I can just read the channel during my :update fn
11:20arkhdeny user input by default and allow only if input matches the right regex and min/max length
11:23noncomjustin_smith: ping
11:24justin_smithhello, noncom
11:24noncomhi! now implementing the idea of a separate login page, and i lose the ani-forgery item on the login form POST erquest :/ do you know, how can I handle this?
11:25justin_smithyou'll need to generate the login page on the server side and include the token in the submission form
11:25noncomi return the app html page in response to a correctly authorized request, but then the requests that are done from that page, like css requests, lose the token
11:25noncomah.. ok, i am generating the login page from a template.. how do i include the token?
11:26justin_smithas a hidden field on the form
11:43noncomjustin_smith: ok, for example, i create that field, say, i name it "csrf-aft", then how do i interpret it on the server? i have the ring middleware that cares for csrf, but how to make it recognize it
11:43noncom?
11:49noncomgot some info here: http://www.luminusweb.net/docs/security.md now studying
12:04noncomjustin_smith: it worked! :) now - another question - how do you then come back to "http://host/#/single-page-app-address" addressing? because i now have "http://host/login/#/single-page-app-address" ..
12:04noncomthe "/login/" part should not be thre
12:04noncom*there
12:05justin_smithnoncom: via the target field of the form
12:05justin_smithor a redirect
12:05justin_smitheither one works
12:07noncomjustin_smith: hmm what do you put in there? neither _blank nor _self seem to fix this..
12:08justin_smithsorry, not target, I mean action d'oh
12:09justin_smithbut then whatever path that posts to has to be ready to take a login, of course, and respond with the app if apropriate
12:09justin_smithso it might make more sense to redirect after success
12:10noncomjustin_smith: ehh.. i am soo noob in the web.. okay, if i generate a token for a correct login attempt, then, if i redirect to another page which contains a web-app, how do i maintain the token on the client side and authenticate with the SPAPP correctly?
12:25noncom* this time i meant an auth token, not the csrf one
12:25TimMcIs there still a point in using # instead of ? given that all modern browsers support the History API?
12:26noncomTimMc: is this a general question or per my asking?
12:28TimMcgeneral
12:29noncomjustin_smith: if i don't redirect but instead give the page as a direct response then i can embed the auth token into it, but it won't work with redirect like that.. :/ or should i somehow pass the parameter with redirect? will it shuttle first to the client and then back to the targeted redirect page?
12:29TimMcThere was this awkward period after SPAs became trendy but before the History API was a thing, and it was terrible -- people used various combinations of # and ? for resource paths. But now there's the History API and it's pretty well supported, so I'm not sure what the point of using # is.
12:30noncomTimMc: i am not really sure easy. i use the "session" middleware which implies using "#" as the path indicator..
12:33justin_smithTimMc: it allows following vanilla href links without page loads
12:35TimMcjustin_smith: I think the idea is to intercept those clicks.
12:35justin_smithalso it allows arbitrary content in links/ locations - anything after # is legal
12:36justin_smithTimMc: with # I don't need to intercept anything
12:36justin_smithmuch simpler
12:36TimMchmm
12:36justin_smithTimMc: different routes in my SPA don't represent separate server resources
12:36TimMcah
12:37justin_smiththey represent different approaches to the app feature set, all backed by the same data
12:37TimMcI mean, I also don't like AJAX-for-main-content in the first place, I think it's terrible, and I generally assume that complexity is what you've signed up for with SPAs...
12:37justin_smithTimMc: of course if different pages represent different wholly distinct server resources, that can be different I guess
12:37TimMcalso endless synchronization issues
12:37TimMcGithub is *forever* getting out of sync with its URLs.
12:38justin_smithTimMc: the frontend knows how to display data, the backend knows what data should be displayed. The backend has no view logic. This isn't super complex - there are other sources of complexity but this part just works.
12:38justin_smithfor my app at least, ymmv with other designs of course in various ways
12:39justin_smithbbl heading to the office
13:05sevviei suck with clojure, but I used it to make a valentine's gift for my beloved. http://github.com/sevvie/vacant-riddles
13:33justin_smithif I weren't miserable and doomed to die alone I'd check it out
13:33justin_smithj/k looks cool, nice concept
13:35rhg135I have yet to find a girl who appreciates my unique abilities
13:35rhg135Darn, that sounds so hipster
13:36justin_smithnah, just old-fashioned conceited
13:36justin_smith:)
13:37justin_smithhipster would be "I have yet to find someone who appreciates my discerning and obscure taste"
13:37rhg135I mean that in a totally not conceited way
13:38hlolliHumanity woulde evolve quickly if Clojure programmers were as sought after as bodybuilders. Same applies for female Clojure programmers.
13:39rhg135When I talk to a girl I mention code and her eyes glaze over
13:39futuro`rhg135: talk to different women?
13:40rhg135Maybe that'll work, futuro`
13:40futuro`goodspeed!
13:41futuro`man, I am losing my mind trying to fix an om bug
13:41justin_smithrhg135: no time to lose, you know tonight is the best night possible for a first date!
13:41futuro`ooo, so true!
13:42rhg135I rather dislike the idea of dating
13:42futuro`as in, the common approach to a "date", i.e. dinner, a movie, some semblance of conversation?
13:43hlolliMy flatmate and my neighbours are having sex. Im developing website and eating Ben Jerrys icecream to survive :)
13:43futuro`hlolli: I'm glad to hear that your flatmate is on such good terms with your neighbours
13:43rhg135No, the concept. Spending time with someone only to have it end suddenly
13:44hlollinot what I ment, BUT you are actually right, she is in faact having sex with our flatmate.
13:44hlolliI mean neighbour and my flatmate. They fell in love.
13:44futuro`hlolli: neat!
13:44hlolliBut I also hear sounds from the apartment below, so the love is in the air
13:44futuro`I rarely even /talk/ with my neighbors, let alone fall in love with them
13:44justin_smithrhg135: dates need to be relationship complete, which means you can't know without running them whether or how they end.
13:45rhg135That's not really love though
13:45justin_smithoh god that was a tortured metaphor or something
13:45rhg135Lol
13:45futuro`justin_smith: it's the perfect day for them ;)
13:46rhg135Try saying that to your gf
13:47hlolliBy the way, is anybody going to :clojureD next weekend in Berlin?
13:47futuro`rhg135: it's incredibly difficult not to say cheesy things during inappropriate times with my SO
13:47futuro`the struggle is real
13:48rhg135I'm hoping she's OK with that
13:48futuro`oh yeah, I wouldn't date them if they weren't
13:48futuro`but, you know, all things in moderation
13:50rhg135Moderation is always a good strategy
13:51justin_smithmoderators violate the first ammendment down with mods
13:51futuro`First amendment means I can say anything I want without repercussions!
13:51futuro`AMURIKA
13:53rhg135Is America in some alternate universe?
13:53justin_smithno, but 'murika is
13:53rhg135Sounds like a good idea
13:56rhg135Land of being called a bunch of explicit words while being filled with lead by your neighbor
13:56rhg135'murica that is
13:56futuroThat's exactly right; I know, I'm 'murican!
13:56justin_smithrhg135: basically it's a tarantino movie
13:57rhg135I don't know what that is.
13:57futuroa movie by this dude https://en.wikipedia.org/wiki/Quentin_Tarantino
13:57justin_smithrhg135: quentin tarantino - did pulp fiction, reservoir dogs, hateful eight...
13:58futurodjango unchained
13:58rhg135Oh!
14:05noncomjustin_smith: can you possibly give an advice on how to maintain authentication throughout the redirect? As I understand, the redirect will make client to request a completely different page, how do I maintain the authentication token with it? Do I somehow store it in the redirect response that I give from the compojure router?
14:05justin_smithnoncom: the page you redirect to should give the client a new token, etc.
14:06noncomjustin_smith: oh, so you mean that if the redirect happens, this already implies authentication? but how do i pass the identity of the user to the new page?
14:06justin_smithwhen you return a redirect, you can then expect the client to hit the other page that you redirect to, that page can offer an auth token
14:07noncomhow do i know it is the same client who passed the authentication?
14:07justin_smithyou can attach a paramter to the request string in the redirect
14:07justin_smiththat's the easiest at least
14:08justin_smithand that string can be the one time token, etc.
14:10noncomjustin_smith: oh... a shuttle
14:10noncomi see
14:10noncommakes sense with the 1-time use tokens, right!
14:11noncomjustin_smith: thank you so much, you can answer various web-related question very clear, i really appreciate that!
14:12justin_smithnoncom: np, glad I could help
16:20benjyz1hello. I want to a transformation of a map https://www.refheap.com/114795
16:20benjyz1,(def x {a {foo 0, bar 22}, b {foo 3, bar 44}})
16:20clojurebot#error {\n :cause "Unable to resolve symbol: a in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: a in this context"\n ...
16:21justin_smith,(map (fn [k v] (assoc v :id k)) {a {foo 0, bar 22}, b {foo 3, bar 44}})
16:21clojurebot#error {\n :cause "Unable to resolve symbol: a in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: a in this context"\n ...
16:21justin_smithahaha
16:21justin_smith,(map (fn [k v] (assoc v :id k)) '{a {foo 0, bar 22}, b {foo 3, bar 44}})
16:21clojurebot#<ArityException clojure.lang.ArityException: Wrong number of args (1) passed to: sandbox/eval72/fn--73>
16:21justin_smither
16:21benjyz1I'm getting a strange format
16:21justin_smith,(map (fn [[k v]] (assoc v :id k)) '{a {foo 0, bar 22}, b {foo 3, bar 44}})
16:21clojurebot({foo 0, bar 22, :id a} {foo 3, bar 44, :id b})
16:22benjyz1cool
16:22benjyz1I always want to do a doseq... but I guess its always (map fn x)
16:23justin_smithbenjyz1: doseq can only generate nil
16:23benjyz1sometimes I see into {} ...
16:23amalloynil...and controversy!
16:23justin_smith,(for [[k v] '{a {foo 0, bar 22}, b {foo 3, bar 44}}] (assoc v :id k)) ; benjyz1 alternate
16:23clojurebot({foo 0, bar 22, :id a} {foo 3, bar 44, :id b})
16:24benjyz1hard to get rid of the habit of iterating
16:24benjyz1for each ... do stuff
16:24amalloywell, we iterate all the time
16:24amalloyfor each ... make stuff
16:25amalloy(into {} (for ...)) is very common
16:25justin_smithright, but why do that when you are not even trying to create a hash-map