Fork me on GitHub
#clojure
<
2015-12-16
>
spei01:12:51

hmmm....I seem to be really bad at transducers as i'm not sure how to solve this problem with transducers...

profil01:12:42

I may be overkilling it, but I thought it could be fun to solve with transducers 😄

spei01:12:56

Its not very good, but i tried to pull it apart a little https://gist.github.com/ship561/2e3f3664c2f0bf3676f9

spei01:12:54

I tried to make the transforming functions composable, but it still looks weird to me.

profil01:12:51

yeah its a mess

spei01:12:24

on the bright side, each of those xf1 and xf2 functions are supposed to be the composable transducing functions, which I think is what they are supposed to look like

timvisher02:12:33

is there a good example of a 'close over environment variable by accident at compile time' bug?

timvisher02:12:43

i'm not sure a better way to describe it than that

timvisher02:12:23

i had a long discussion with someone at work today about it. the long and short of it is that they thought that if you had (def charnock (System/getenv "CHARNOCK")) in an ns, that it would somehow freeze at that value at compile time.

timvisher02:12:59

to prove this wasn't the case i gave them an example that printed the value of the def and ran it with multiple CHARNOCK=foos using java -jar and indeed everything was fine.

timvisher02:12:51

they gave me a counterexample like this

(def charnock (if-not (System/getenv "CHARNOCK") (throw (Exception.)) (System/getenv "CHARNOCK"))

timvisher02:12:27

that indeed throws if you lein uberjar without CHARNOCK set in the environment.

timvisher02:12:47

even though if you do set it you can still reset it at runtime in that process's environment

timvisher02:12:40

it came down to his mental model being that somehow the (def charnock (System/getenv … call being frozen at the time of compilation whereas i knew that it would maintain its fluidity

timvisher02:12:22

but i still have it in the back of my head that it's possible to close over compile time scope in someway due to aot compilation. i just can't think of how

danielcompton04:12:40

@timvisher: I know what you mean, though I can’t remember the exact circumstances, AOT sounds right though

trancehime08:12:07

Anyone here can help me with something in hiccup?

vijaykiran08:12:05

Don’t ask to ask, just ask simple_smile

trancehime08:12:00

The drop-down is like this: (drop-down attr-map? name options selected), how can I format options in order to allow a custom :value with a different label such as: [:option {:value id} label]?

trancehime08:12:59

If I use map and do [:option {:value id} label] without making use of drop-down, I cannot specify selected without writing an ugly hack

trancehime08:12:04

Anyone got any bright ideas?

davebryand09:12:15

hi, can someone help me with how I would get pull-person-attrs to bring that vector into the quoted form returned by find-person please?

(def pull-person-attrs [:entity/uuid
                        :person/name
                        :person/token])

(def find-person
  '[:find (pull ?person pull-person-attrs) . :in $ ?person])

vijaykiran09:12:28

@davebryand: do you want generate the [:find ..] vector from [:entity/uuid …] ?

cjmurphy10:12:18

@trancehime: Do you just want to jam [:option {:value id} label] into options, so this question can be answered without knowing about hiccup?

trancehime10:12:30

I... guess? The way I'm doing it now I'm just setting options as a vector containing the stuff I want to pass in a form, so just a vector of id. Of course when it's rendered that's not helpful to the end-user since there's nothing to indicate what the ID is actually assigned to

cjmurphy10:12:58

Oh I see - so its a hiccup question. I hoped it might be answered just with clojure knowledge.

cjmurphy10:12:03

What is a drop-down ie which namespace?

cjmurphy10:12:18

I just read your intro - sorry you said it was a hiccup question already!

trancehime10:12:41

its basically just a shorthand way of writing a <select></select> in HTML

cjmurphy10:12:42

Each option needs a value attribute. And you are giving that attribute but still it does not display?

cjmurphy10:12:50

<option value="volvo">Volvo</option>

cjmurphy10:12:46

And the equivalent in hiccup is: [:option {:value "volvo"} "Volvo"]

cjmurphy10:12:55

Would that be right?

trancehime10:12:00

that is correct.

trancehime10:12:31

I do not know how to format the options vector in drop-down such that :value "volvo" and "Volvo" can be different

trancehime10:12:43

since I am populating the selectable fields from a database

trancehime10:12:54

or rather, selectable choices

cjmurphy10:12:14

Hmm - with map you can create anything out of anything, just has to be same number of them.

trancehime10:12:32

I've already been using map to format the data

cjmurphy10:12:07

But you are not getting what you want, or is it you are getting what you want?

cjmurphy10:12:44

When you println do you get [:option {:value "volvo"} "Volvo"]

trancehime10:12:51

I can only use map to have drop-down give me [:option {:value "something"} "something"] when I want [:option {:value "something"} "Actual Term"]

cjmurphy10:12:41

You can map over two collections, would that help?

trancehime10:12:08

i'm not sure that helps given drop-down's options argument only accepts 1 collection

trancehime10:12:20

it passes that collection to something called select-options which I have linked

cjmurphy10:12:07

If I can map from ["something" "Actual Term"] to hiccup will that help?

cjmurphy10:12:41

I mean there would be a vector or these vectors.

trancehime10:12:42

I think I have to do a vector of vectors

trancehime10:12:00

[["something" "Actual Term"] ["something2" "Term 2"]]

cjmurphy10:12:18

I think we've solved it??

trancehime10:12:29

I have no idea, but I need to go so I'll see if it works another time

trancehime10:12:13

thanks for hearing me out

cjmurphy11:12:46

(def input [["something" "Actual Term"] ["something2" "Term 2"]])
;; @trancehime

cjmurphy11:12:35

(map (fn [in] [:option {:value (first in)} (second in)]) input)

danstone11:12:26

New lib released this morning for those lucky people using DynamoDB: https://github.com/mixradio/faraday-atom just thought I'd plug it here before putting out on mailing list tonight

roelof11:12:41

Hello , I try to register a user. Therefore I use a last-login which has to be a time. But the user have not logged in. How do I make a dummy time object for this ?

danielstockton13:12:27

How do people usually handle accept mimetypes on api endpoints? Does bidi/ring have anything built-in?

danielstockton13:12:41

I want to change the response based on the accept header

denik13:12:42

Any reason why one can’t used namespace-qualified keys in defrecord?

denik13:12:53

like

(defrecord hello
  [my-ns/my-key])

denik13:12:20

throws

CompilerException java.lang.RuntimeException: No such namespace: my-ns, compiling:...

danielstockton13:12:55

this could do the job but doesn't seem popular for something i expect is very common: https://github.com/rufoa/ring-middleware-accept

stuartsierra13:12:47

@denik: The keys in a defrecord become local variables within the body of methods the record implements. They also compile into Java instance fields.

denik13:12:54

@stuartsierra: thanks. I’m going from datomic/datascript hash-maps to records. Is that uncommon? Or do people remove all the namespace prefixes to do that?

stuartsierra13:12:32

@denik: If you have maps with namespaced keys to start with, it's probably easiest to leave them as maps.

denik13:12:24

@stuartsierra: ok makes sense. Thank you!

roelof13:12:27

no one who can help me ?

pvinis13:12:58

when will 1. 8 be out?

alexmiller13:12:13

We should have another RC coming out soon.

alexmiller13:12:43

Hard to predict time from there to release but hopefully not too long

snowell14:12:01

That lets you create DateTime objects and coerce them into whatever format you want/need

pbostrom15:12:58

hello fellow Clojurians. I wrote up a post mortem on a production bug in our Clojure service. Just thought I would share it: http://techblog.roomkey.com/posts/too-many-files.html

alexmiller15:12:51

nice writeup!

alexmiller15:12:04

I'm sure it will help some poor soul down the line :)

pbostrom15:12:27

ha! yes, I did not find much on the googles when I initially began debugging this problem

polymeris15:12:06

site seems to be down, @pbostrom ?

alexmiller15:12:23

prob out of file descriptors ;)

pbostrom15:12:42

hmm, I don't see any problems at the moment, it's just static content on an s3 bucket, should be pretty resilient

roelof15:12:23

Thanks , Im at the moment tired of figthing and trying clojure so I take a break

pyr15:12:52

@pbostrom: http://techblog.roomkey.com does not resolve

pyr15:12:43

or at least, not consistently

pbostrom15:12:43

ahh, interesting

roelof15:12:10

I could not find any good tutorial or book to learn how to make authentication work with buddy or friend

roelof15:12:56

sorry I mean a tutorial of how I can make a user registering and storing in a database and the autherisation

roelof15:12:09

adam is just pointing at some things

roberto15:12:07

yeah, you have a different problem than authentication

roberto15:12:26

were you able to store the user in the database?

roberto15:12:48

were you able to authenticate a user that has a record in the database?

roberto15:12:02

you would need to narrow down the problem you are having.

roelof15:12:20

I thought I had but I get confused which route has to point at what code

roelof15:12:27

There is a get and a post route. I thought the first needed to point only to the page which holds the registration form

roelof15:12:54

and the second one to a validation function and the store function

roelof16:12:19

But then I cannot find the user back with yesql

roelof16:12:32

@roberto: Do I have this part right ?

roberto16:12:07

can you paste your code?

alexmiller16:12:02

@snowell: the most critical of those -v fns were created, but did not want to create an entire alternate universe of vector fns

alexmiller16:12:11

at this point, you can get the identical effect with transducers

roelof16:12:31

@roberto: I have this so far in my routes.clj :

(ns clcommerce.routes.home
  (:require [clcommerce.layout :as layout]
            [compojure.core :refer [defroutes GET]]
            [ring.util.http-response :refer [ok]]
            [ :as io]))

(defn home-page [req]
  (layout/render
    "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))

(defn about-page []
  (layout/render "about.html"))

(defn login-page [req]
  (layout/render "login.html"))

(defn save-message![req]
  )

(defroutes home-routes
           (GET "/" [] (home-page))
           (GET "/about" [] (about-page))
           (GET "/login" request (login-page request))
           (POST "/" request (save-message! request))  

roberto16:12:10

you have 2 definitions for GET “/“

snowell16:12:14

@alexmiller: Oh yeah, I understand it would be completely unneeded. Just a random thought I had

roberto16:12:18

that is the first thing that I spotted

roberto16:12:15

so, one of those is surplus, and should probably be in a different route

roelof16:12:24

oke, the first need to point to /login

roelof16:12:53

the second one I have to think about what schould be in there . The post one

roelof16:12:16

and I think the save message needs to be something like this : (store/add-user! ds (update-in user [:password] #(hs/encrypt %))))

roelof16:12:20

the add-user is in another ns and looks like this :

(ns acme-auth.store
  (:require [clojure.java.jdbc :as jdbc]
            [buddy.hashers :as hs]))


(defn add-user! [ds user]
  (jdbc/with-db-transaction [conn ds]
                            (let [res (jdbc/insert! conn
                                                    :user
                                                    {:name (:name user) :admin (:admin user) :last-login NULL  :is_active true  :password (:password user)})
                                  user-id ((keyword "scope_identity()") (first res))]))) 

roelof16:12:08

@roberto: am I on the right track ?

roberto16:12:10

I’m sorry. I don’t think I follow. I don’t see where in your routes you are adding users or authenticating them.

roelof16:12:39

I just try to add users at the moment

roelof16:12:15

login route is the route to the form and post schould validate it and store it

roelof16:12:46

the validation is one thing I have to figure out when the user can be added

roberto16:12:24

but none of your routes is adding users, at least none of the routes you pasted. So I’m at a little loss.

roelof16:12:57

IM also lost

roelof16:12:21

that is why Im taking a break and I hope I can find a good tutorial about this

roelof16:12:03

otherwise clojure is not for what I want to use for it .

davebryand17:12:00

would love help on a simple clojure question, please. I’m trying to get pull-board-attrs to be used in the find vectors in find-board and find-boards-for-person, but not sure how to do that in this quoted form. Should I just use a function instead?

(def pull-board-attrs [:entity/uuid :board/name])

(def find-board
  '[:find (pull ?board pull-board-attrs) . :in $ ?board])

(def find-boards-for-person
  '[:find [(pull ?board pull-board-attrs) ...] :in $ ?person
    :where [?person :person/boards ?board]])

davebryand17:12:02

Ok, I think I got it. Does this look idiomatic or am I barking up wrong trees?

(def pull-board-attrs [:entity/uuid :board/name])

(def find-board
  `[:find (pull ?board ~pull-board-attrs) . :in $ ?board])

davebryand17:12:08

nope, that’s not it simple_smile

rufoa19:12:11

@danielstockton: i'm the guy who made rufoa/ring-middleware-accept - it should do what you're looking for! I can't account for its lack of github stars though 😉

danielstockton19:12:57

@rufoa I went for parsing the accept header with a regex but your library looks good if I need languages and encoding too

eraserhd20:12:43

Do we capitalize Clojure?

anisoptera20:12:56

i mean i rarely capitalize anything but if i'm in proper-grammar-mode then i do

oli21:12:33

@davebryand: you should be able to send in pull-board-attrs as an argument (assuming you'll eventually do a datomic/query call)

oli21:12:39

something like...

rcanepa21:12:04

Hey everyone! I am trying to understand how compojure-api deals with middleware. In particular, I want to set a middleware for a group of routes. Until now, I have accomplished it for a single endpoint (repeating the same code for the others) doing this:

juhoteperi21:12:55

@rcanepa: You can use :middlewares with context*

rcanepa21:12:05

Reading the docs, wasn’t enough for me to understand how to set the middleware for all the endpoints of the context.

rcanepa21:12:46

Ok. Can I move the parameter destructuring to the context too?

rcanepa21:12:00

Somethings seems magical to me right now (I have been working with Clojure for less than a month)… so to understand the basis of how compojure-api works, should I dive into the ring and compojure code bases?

ghadi21:12:43

compojure-api is magic. I recommend looking at something simpler

juhoteperi21:12:53

Yes, Compojure-api is quite magical

ghadi21:12:23

sorry, I hate to be down on something because there are people behind projects, but peek under the covers of compojure-api vs compojure itself

ghadi21:12:36

Then try pedestal.

ghadi21:12:44

or just straight up compojure

juhoteperi21:12:22

Back to context*, if you have path-parameter in the context path, you should be able to use :path-params with context, but I'm not sure if documentation works correctly with that

ghadi21:12:53

(Sorry I totally didn't read the scrollback)

rcanepa21:12:28

Great… I want to learn how it works and I have time to read the other code bases. So if you say that I should peek on compojure’s code, I will.

juhoteperi21:12:10

@rcanepa: There's a test about using :path-params with context*, so it should work correctly: https://github.com/metosin/compojure-api/blob/master/test/compojure/api/integration_test.clj#L613-L622

rcanepa21:12:56

@juhoteperi: Thanks, I will read it too.

davebryand22:12:27

thanks @oli — i’ll give it a shot

ddellacosta22:12:55

okay, so hello world on installing a template for local use

ddellacosta22:12:36

getting

$ lein new my-template foo
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
Failed to resolve version for my-template:lein-template:jar:RELEASE
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
Could not find template my-template on the classpath.
$

ddellacosta22:12:19

not sure what I’m doing wrong—I did little other than lein new template my-template —to-dir my-template-dir

ddellacosta22:12:27

and then lein install inside of my-template-dir

ddellacosta22:12:36

what dumb thing am I doing (or not doing)?

ddellacosta22:12:51

lein version is 2.5.1

hypirion23:12:50

@ddellacosta: You need to add the --snapshot flag to the command: lein new my-template foo --snapshot (I tend to just remove the -SNAPSHOT part of the project version, usually)

ddellacosta23:12:46

oh, I didn’t realize that was the issue there…gotcha, thanks

hypirion23:12:14

Well, the tutorial doesn't mention it, so 😐