Fork me on GitHub
#beginners
<
2017-03-21
>
abhiroop04:03:54

@seancorfield How do you understand which functions should be part of core and which ones not?

grounded_sage05:03:23

What would be cool is a public utility functions library. So people can easily copy functions put together by others. Not a library you pull down but a reference online.

foamdino08:03:19

@grounded_sage like clojure-cookbook (which I discovered yesterday)

grounded_sage08:03:04

@foamdino I was thinking that. But I think something even more like http://clojuredocs.org where the function is described anyone can put in examples etc. Then maybe people could vote, comment on them etc

camdenclark08:03:29

one resource when I was learning to use pandas (the python dataframe library) was a paste that had a bunch of interesting snippets the creator had used frequently. Something like that might be useful but for anything else a google search for a stack overflow post is more useful.

sb16:03:40

Hello, how can I assoc a new user to a variable?

sb16:03:36

That is works fine in repl, but just in the function changed the variable (binding). How can I modify the map (like global variable)?

sb16:03:28

because everytime I get back the original var (else case), could you help me?

sb16:03:56

(update-in users [username] assoc :username username :password password :role #{::user})

sb16:03:27

that is work too.. but not update the original variable which contains the user data (it loaded once from the database, when started the website)

donaldball16:03:00

You may be looking for atom and swap!

sb16:03:17

Yes, but the Friend not store in atom the user data..

sb16:03:50

Ohh.. maybe I can define a variable which use an atom?

donaldball16:03:56

alter-var-root! lets you change the value of a var, but many would advise only going down that path with very good reason

donaldball16:03:20

yes, that would be much more common, putting an atom value in a var

sb16:03:37

(def users @userdb) is correct?

donaldball16:03:01

That would set the value of the user var to the current value of the thing referenced by userdb

sb16:03:16

Friend use the users var

sb16:03:24

I would like to update this

manutter5118:03:15

@sb the documentation for Friend is using users as a substitute for a real database, so the example will be simple.

sb18:03:34

yes, but I can’t update

sb18:03:38

I don’t know why

sb18:03:30

I tried with that too

(let [user {"ewq" {:username "ewq" 
                            :password (creds/hash-bcrypt "pass") 
                            :roles #{::user}}}]           
            (friend/merge-authentication (ring.util.response/redirect "/testdb2") user))

manutter5118:03:30

If you are just trying to learn Friend, it’s ok to use an atom instead of an immutable variable

sb18:03:48

Yes, I would like to use Friend

manutter5118:03:11

I am looking at the Friend example here: https://github.com/cemerick/friend

manutter5118:03:40

If you would like to be able to make changes to that “toy” user database, you can define it like this:

manutter5118:03:01

Then you can update it with (swap users assoc username {:username “joe” :password “whatever” :roles #{::user}})

manutter5118:03:42

or (swap users assoc ”joe" {:username "joe" :password "whatever" :roles #{::user}})

sb18:03:02

Thank you very much! 👍 👍 👍

manutter5118:03:10

oops, make that swap! not swap, I always do that derp

sb18:03:26

👍👍👍👍👍 I really thank you for your answer, really helpful! I got the answer. thanks!!

manutter5118:03:38

by the way @sb if you haven’t looked at Buddy you might want to take a look, as a possible alternative to Friend https://github.com/funcool/buddy

sb18:03:23

Yes, I heard from many Clojure devs, they use buddy. I will check it. Thanks! :face_with_rolling_eyes:👍