2016-02-14
| 05:45 | vivekramaswamy | A quick question, I am getting a stack overflow in this small clojure program, not sure why ideas would help? http://shortText.com/736de871 |
| 05:48 | blur3d | vivekramaswamy: you’re not using the correct recursion syntax |
| 05:49 | blur3d | You use ‘recur’ instead of your function name - https://clojuredocs.org/clojure.core/recur |
| 05:49 | vivekramaswamy | ok, got it, thanks a lot |
| 06:05 | LauJensen | Gents, 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:11 | vivekramaswamy | Hello blur3d, I did the change, but still end up getting a compilation error, any ideas, https://codeshare.io/F4J46 |
| 06:16 | blur3d | vivekramaswamy: Well, you’re missing a closing paren |
| 06:21 | vivekramaswamy | Thank 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:29 | blur3d | vivekramaswamy: What do you want the function to do? Print out each item in the list one by one? |
| 06:31 | blur3d | if so, no need for recur… just use (map #(println %) '(1 2 3)) |
| 06:31 | blur3d | ,(map #(println %) '(1 2 3)) |
| 06:31 | clojurebot | (1\n2\nnil 3\nnil nil) |
| 06:31 | TEttinger | ,(map println [1 2 3]) |
| 06:31 | clojurebot | (1\n2\n3\nnil nil nil) |
| 06:32 | blur3d | vivekramaswamy: lighttable is fairly friendly.. i’d give it a go |
| 06:32 | TEttinger | ^ blur3d |
| 06:32 | TEttinger | no need for anonymous fns wrapping something if it's being called with the args as-given |
| 06:33 | blur3d | TEttinger: that works also, haha… haven’t written clojure in over a year now |
| 06:33 | TEttinger | ,(map str '(a b c) [1 2 3]) |
| 06:33 | clojurebot | ("a1" "b2" "c3") |
| 06:33 | TEttinger | ,(map str '(a b c) [1 2 3] "?!@") |
| 06:33 | clojurebot | ("a1?" "b2!" "c3@") |
| 06:34 | TEttinger | I love how versatile the seq abstraction is |
| 06:34 | TEttinger | strings are seqs of chars! now everything's easier! |
| 06:35 | blur3d | Yeah. I really loved using clojure.. I’ve just changed my line of work |
| 06:36 | blur3d | I have a personal project that is highly data driven and lazy, so I hope to prototype it in clojure soon |
| 06:37 | vivekramaswamy | Nope 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:38 | noncom | how to make a server built on ring/compojure accept params passed in url, like "http://some-url?id=1&something_else=2 |
| 06:57 | blur3d | noncom: http://stackoverflow.com/questions/7785214/compojure-how-to-map-query-parameters |
| 08:03 | side_effect1 | hello. 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:04 | side_effect1 | I know I should start from basic and the I can write some combination from marcos import, def, refer |
| 09:16 | justin_smith | side_effect1: (require '[datascript.core :as d]) works in a repl |
| 09:16 | justin_smith | side_effect1: also, you can run the ns form exactly like it is there, in a repl |
| 09:21 | side_effect1 | justin_smith, thanks. It works. |
| 09:22 | justin_smith | side_effect1: in general there are very few things you can do in a source file that you can't do in a repl |
| 09:22 | justin_smith | (and even with those there's a way to do it if you really want to) |
| 09:23 | hodwik | Any idea why in Emacs I would get Namespace not found. for everything in the repl |
| 09:23 | hodwik | including simple stuff like (+ 1 1) |
| 09:24 | justin_smith | hodwik: because you ran (in-ns 'some-ns) for an ns that was not loaded yet |
| 09:24 | justin_smith | hodwik: run (clojure.core/refer-clojure) to restore sanity |
| 09:24 | hodwik | Namespace not found. :L |
| 09:25 | justin_smith | even (clojure.core/refer-clojure) doesn't work? |
| 09:25 | hodwik | Yeah |
| 09:25 | justin_smith | because clojure.core is kind of needed in order to have a repl at all... |
| 09:26 | hodwik | Yes, that makes sense |
| 09:26 | justin_smith | wait, is "namespace not found" a clojure error or a CIDER one I wonder? |
| 09:26 | justin_smith | because it could be CIDER is just in a broken state |
| 09:28 | hodwik | So, the repl works until I change namespace to my project |
| 09:28 | hodwik | then nothing works |
| 09:28 | justin_smith | how are you loading your project namespace? |
| 09:28 | justin_smith | is it automatic? are you sure it is actually happening? |
| 09:28 | hodwik | C-c M-n from the .clj window |
| 09:32 | hodwik | How about I rewind a step, is there an out-of-the-box emacs setup for clojure |
| 09:32 | hodwik | because I suspect I am setting something up incorrectly, but there's too many moving pieces for me to figure out what it is |
| 09:34 | justin_smith | hodwik: 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:34 | justin_smith | Always remove everything before updating. |
| 09:35 | justin_smith | frankly 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:36 | hodwik | I don't blame you, this emacs/clojure integration seems very touchy |
| 09:36 | hodwik | This is install attempt 3 for me, still can't get it to work as described in the braveclojure book |
| 09:37 | justin_smith | actaully 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:37 | justin_smith | but 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:38 | hodwik | So you're just using lein from terminal |
| 09:39 | hodwik | what about for editing? |
| 09:39 | justin_smith | emacs |
| 09:39 | justin_smith | just clojure mode |
| 09:39 | hodwik | Oh, but you just run your code in the term window? |
| 09:39 | justin_smith | right, using require or load-file as apropriate to load new definitions |
| 09:40 | hodwik | I'm comfortable with that workflow, I think I'll switch to that |
| 09:40 | hodwik | thank you |
| 09:40 | justin_smith | when working that way, clojure.repl/dir and clojure.repl/apropos become very usefil |
| 09:40 | justin_smith | *useful |
| 09:41 | hodwik | I'll take a look at those |
| 10:25 | LauJensen | Gents, 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:26 | justin_smith | LauJensen: 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:28 | LauJensen | justin_smith, Its the instantiation of a global. I could wrap it in an atom and init it in -main |
| 10:28 | justin_smith | LauJensen: you can also use declare, and actually assign the value in -main |
| 10:29 | justin_smith | or even use a delay |
| 10:29 | justin_smith | no need for an atom if it isn't going to get multiple values at runtime |
| 10:29 | LauJensen | A delay? |
| 10:29 | justin_smith | ,(def foo (delay (do (println :realized) :OK))) |
| 10:29 | clojurebot | #'sandbox/foo |
| 10:30 | justin_smith | ,foo |
| 10:30 | clojurebot | #object[clojure.lang.Delay 0x54ae79a7 {:status :pending, :val nil}] |
| 10:30 | justin_smith | ,(realized? foo) |
| 10:30 | clojurebot | false |
| 10:30 | justin_smith | ,@foo |
| 10:30 | clojurebot | :realized\n:OK |
| 10:30 | justin_smith | ,@foo |
| 10:30 | clojurebot | :OK |
| 10:30 | LauJensen | Oh right |
| 10:30 | justin_smith | the code in delay gets called once, on first deref, then it holds that value |
| 10:30 | LauJensen | Good tip, thanks |
| 10:31 | LauJensen | In my test, delay fires immediately |
| 10:31 | justin_smith | are you dereffing immediately? |
| 10:31 | LauJensen | no |
| 10:32 | justin_smith | umm... then you are doing it wrong somehow |
| 10:33 | LauJensen | try this, (def tst (javax.swing.JOptionPane/showMessageDialog nil "TST")) |
| 10:33 | LauJensen | and on my system, it pops before dereffing |
| 10:33 | justin_smith | umm, that's nopt delayed |
| 10:34 | justin_smith | LauJensen: (def tst (delay (javax.swing.JOptionPane/showMessageDialog nil "TST"))) |
| 10:34 | justin_smith | that won't pop the window until you run (deref tst) or the equivalent @tst |
| 10:34 | justin_smith | (just verified in my own repl) |
| 10:38 | justin_smith | LauJensen: 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:38 | justin_smith | (if that's equivalent to what your code was doing) |
| 10:39 | LauJensen | sorry, i just forgot to type delay in here, had it in the repl |
| 10:39 | LauJensen | No wait, i didnt, nevermind :) |
| 10:39 | justin_smith | haha |
| 10:41 | LauJensen | Thanks for taking the time Justin |
| 11:03 | insamniac | anyone use quil much? I'm trying to figure out the best/right way to handle input from a channel |
| 11:05 | benjyz1 | is there any good irc channel for web-security? |
| 11:05 | insamniac | my simple brain wants to make the channel read to update some mutable external state, and have quil :update look at it |
| 11:05 | benjyz1 | ..maybe someone here knows |
| 11:06 | insamniac | ##security maybe |
| 11:20 | insamniac | or i guess if i'm smart I can just read the channel during my :update fn |
| 11:20 | arkh | deny user input by default and allow only if input matches the right regex and min/max length |
| 11:23 | noncom | justin_smith: ping |
| 11:24 | justin_smith | hello, noncom |
| 11:24 | noncom | hi! 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:25 | justin_smith | you'll need to generate the login page on the server side and include the token in the submission form |
| 11:25 | noncom | i 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:25 | noncom | ah.. ok, i am generating the login page from a template.. how do i include the token? |
| 11:26 | justin_smith | as a hidden field on the form |
| 11:43 | noncom | justin_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:43 | noncom | ? |
| 11:49 | noncom | got some info here: http://www.luminusweb.net/docs/security.md now studying |
| 12:04 | noncom | justin_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:04 | noncom | the "/login/" part should not be thre |
| 12:04 | noncom | *there |
| 12:05 | justin_smith | noncom: via the target field of the form |
| 12:05 | justin_smith | or a redirect |
| 12:05 | justin_smith | either one works |
| 12:07 | noncom | justin_smith: hmm what do you put in there? neither _blank nor _self seem to fix this.. |
| 12:08 | justin_smith | sorry, not target, I mean action d'oh |
| 12:09 | justin_smith | but then whatever path that posts to has to be ready to take a login, of course, and respond with the app if apropriate |
| 12:09 | justin_smith | so it might make more sense to redirect after success |
| 12:10 | noncom | justin_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:25 | noncom | * this time i meant an auth token, not the csrf one |
| 12:25 | TimMc | Is there still a point in using # instead of ? given that all modern browsers support the History API? |
| 12:26 | noncom | TimMc: is this a general question or per my asking? |
| 12:28 | TimMc | general |
| 12:29 | noncom | justin_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:29 | TimMc | There 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:30 | noncom | TimMc: i am not really sure easy. i use the "session" middleware which implies using "#" as the path indicator.. |
| 12:33 | justin_smith | TimMc: it allows following vanilla href links without page loads |
| 12:35 | TimMc | justin_smith: I think the idea is to intercept those clicks. |
| 12:35 | justin_smith | also it allows arbitrary content in links/ locations - anything after # is legal |
| 12:36 | justin_smith | TimMc: with # I don't need to intercept anything |
| 12:36 | justin_smith | much simpler |
| 12:36 | TimMc | hmm |
| 12:36 | justin_smith | TimMc: different routes in my SPA don't represent separate server resources |
| 12:36 | TimMc | ah |
| 12:37 | justin_smith | they represent different approaches to the app feature set, all backed by the same data |
| 12:37 | TimMc | I 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:37 | justin_smith | TimMc: of course if different pages represent different wholly distinct server resources, that can be different I guess |
| 12:37 | TimMc | also endless synchronization issues |
| 12:37 | TimMc | Github is *forever* getting out of sync with its URLs. |
| 12:38 | justin_smith | TimMc: 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:38 | justin_smith | for my app at least, ymmv with other designs of course in various ways |
| 12:39 | justin_smith | bbl heading to the office |
| 13:05 | sevvie | i suck with clojure, but I used it to make a valentine's gift for my beloved. http://github.com/sevvie/vacant-riddles |
| 13:33 | justin_smith | if I weren't miserable and doomed to die alone I'd check it out |
| 13:33 | justin_smith | j/k looks cool, nice concept |
| 13:35 | rhg135 | I have yet to find a girl who appreciates my unique abilities |
| 13:35 | rhg135 | Darn, that sounds so hipster |
| 13:36 | justin_smith | nah, just old-fashioned conceited |
| 13:36 | justin_smith | :) |
| 13:37 | justin_smith | hipster would be "I have yet to find someone who appreciates my discerning and obscure taste" |
| 13:37 | rhg135 | I mean that in a totally not conceited way |
| 13:38 | hlolli | Humanity woulde evolve quickly if Clojure programmers were as sought after as bodybuilders. Same applies for female Clojure programmers. |
| 13:39 | rhg135 | When I talk to a girl I mention code and her eyes glaze over |
| 13:39 | futuro` | rhg135: talk to different women? |
| 13:40 | rhg135 | Maybe that'll work, futuro` |
| 13:40 | futuro` | goodspeed! |
| 13:41 | futuro` | man, I am losing my mind trying to fix an om bug |
| 13:41 | justin_smith | rhg135: no time to lose, you know tonight is the best night possible for a first date! |
| 13:41 | futuro` | ooo, so true! |
| 13:42 | rhg135 | I rather dislike the idea of dating |
| 13:42 | futuro` | as in, the common approach to a "date", i.e. dinner, a movie, some semblance of conversation? |
| 13:43 | hlolli | My flatmate and my neighbours are having sex. Im developing website and eating Ben Jerrys icecream to survive :) |
| 13:43 | futuro` | hlolli: I'm glad to hear that your flatmate is on such good terms with your neighbours |
| 13:43 | rhg135 | No, the concept. Spending time with someone only to have it end suddenly |
| 13:44 | hlolli | not what I ment, BUT you are actually right, she is in faact having sex with our flatmate. |
| 13:44 | hlolli | I mean neighbour and my flatmate. They fell in love. |
| 13:44 | futuro` | hlolli: neat! |
| 13:44 | hlolli | But I also hear sounds from the apartment below, so the love is in the air |
| 13:44 | futuro` | I rarely even /talk/ with my neighbors, let alone fall in love with them |
| 13:44 | justin_smith | rhg135: dates need to be relationship complete, which means you can't know without running them whether or how they end. |
| 13:45 | rhg135 | That's not really love though |
| 13:45 | justin_smith | oh god that was a tortured metaphor or something |
| 13:45 | rhg135 | Lol |
| 13:45 | futuro` | justin_smith: it's the perfect day for them ;) |
| 13:46 | rhg135 | Try saying that to your gf |
| 13:47 | hlolli | By the way, is anybody going to :clojureD next weekend in Berlin? |
| 13:47 | futuro` | rhg135: it's incredibly difficult not to say cheesy things during inappropriate times with my SO |
| 13:47 | futuro` | the struggle is real |
| 13:48 | rhg135 | I'm hoping she's OK with that |
| 13:48 | futuro` | oh yeah, I wouldn't date them if they weren't |
| 13:48 | futuro` | but, you know, all things in moderation |
| 13:50 | rhg135 | Moderation is always a good strategy |
| 13:51 | justin_smith | moderators violate the first ammendment down with mods |
| 13:51 | futuro` | First amendment means I can say anything I want without repercussions! |
| 13:51 | futuro` | AMURIKA |
| 13:53 | rhg135 | Is America in some alternate universe? |
| 13:53 | justin_smith | no, but 'murika is |
| 13:53 | rhg135 | Sounds like a good idea |
| 13:56 | rhg135 | Land of being called a bunch of explicit words while being filled with lead by your neighbor |
| 13:56 | rhg135 | 'murica that is |
| 13:56 | futuro | That's exactly right; I know, I'm 'murican! |
| 13:56 | justin_smith | rhg135: basically it's a tarantino movie |
| 13:57 | rhg135 | I don't know what that is. |
| 13:57 | futuro | a movie by this dude https://en.wikipedia.org/wiki/Quentin_Tarantino |
| 13:57 | justin_smith | rhg135: quentin tarantino - did pulp fiction, reservoir dogs, hateful eight... |
| 13:58 | futuro | django unchained |
| 13:58 | rhg135 | Oh! |
| 14:05 | noncom | justin_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:05 | justin_smith | noncom: the page you redirect to should give the client a new token, etc. |
| 14:06 | noncom | justin_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:06 | justin_smith | when 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:07 | noncom | how do i know it is the same client who passed the authentication? |
| 14:07 | justin_smith | you can attach a paramter to the request string in the redirect |
| 14:07 | justin_smith | that's the easiest at least |
| 14:08 | justin_smith | and that string can be the one time token, etc. |
| 14:10 | noncom | justin_smith: oh... a shuttle |
| 14:10 | noncom | i see |
| 14:10 | noncom | makes sense with the 1-time use tokens, right! |
| 14:11 | noncom | justin_smith: thank you so much, you can answer various web-related question very clear, i really appreciate that! |
| 14:12 | justin_smith | noncom: np, glad I could help |
| 16:20 | benjyz1 | hello. I want to a transformation of a map https://www.refheap.com/114795 |
| 16:20 | benjyz1 | ,(def x {a {foo 0, bar 22}, b {foo 3, bar 44}}) |
| 16:20 | clojurebot | #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:21 | justin_smith | ,(map (fn [k v] (assoc v :id k)) {a {foo 0, bar 22}, b {foo 3, bar 44}}) |
| 16:21 | clojurebot | #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:21 | justin_smith | ahaha |
| 16:21 | justin_smith | ,(map (fn [k v] (assoc v :id k)) '{a {foo 0, bar 22}, b {foo 3, bar 44}}) |
| 16:21 | clojurebot | #<ArityException clojure.lang.ArityException: Wrong number of args (1) passed to: sandbox/eval72/fn--73> |
| 16:21 | justin_smith | er |
| 16:21 | benjyz1 | I'm getting a strange format |
| 16:21 | justin_smith | ,(map (fn [[k v]] (assoc v :id k)) '{a {foo 0, bar 22}, b {foo 3, bar 44}}) |
| 16:21 | clojurebot | ({foo 0, bar 22, :id a} {foo 3, bar 44, :id b}) |
| 16:22 | benjyz1 | cool |
| 16:22 | benjyz1 | I always want to do a doseq... but I guess its always (map fn x) |
| 16:23 | justin_smith | benjyz1: doseq can only generate nil |
| 16:23 | benjyz1 | sometimes I see into {} ... |
| 16:23 | amalloy | nil...and controversy! |
| 16:23 | justin_smith | ,(for [[k v] '{a {foo 0, bar 22}, b {foo 3, bar 44}}] (assoc v :id k)) ; benjyz1 alternate |
| 16:23 | clojurebot | ({foo 0, bar 22, :id a} {foo 3, bar 44, :id b}) |
| 16:24 | benjyz1 | hard to get rid of the habit of iterating |
| 16:24 | benjyz1 | for each ... do stuff |
| 16:24 | amalloy | well, we iterate all the time |
| 16:24 | amalloy | for each ... make stuff |
| 16:25 | amalloy | (into {} (for ...)) is very common |
| 16:25 | justin_smith | right, but why do that when you are not even trying to create a hash-map |