Fork me on GitHub
#beginners
<
2019-01-05
>
JanisOlex12:01:02

hey, when site runs on Ring, is different users handled by different threads?

JanisOlex12:01:13

I mean different requests?

orestis15:01:54

It’s not ring-dependent. Different web servers handle this differently, but most web servers will indeed handle requests with different threads.

orestis15:01:32

In most cases, you don’t need to worry about it - but also never assume the same thread is going to be used for another user, so don’t store things in thread locals.

adc1717:01:01

Hi 👋 , I love that the Clojure ecosystem is into combining libraries on a per-app basis—that's a skill I want to build. Can anyone recommend resources on application architecture? They don't need to be written in Clojure, I'm just looking for something that will help me get better at combining a set of libraries together to meet the needs of a given project. (I want to learn to do this myself, so I'm not after library suggestions.) Thanks!

sova-soars-the-sora17:01:28

@alexchalk17 i recommend taking a look at the source code for strong template projects like sente. what are you interested in building? if it is web i have recommendations, other things different people may be more savvy.

Eccentric J17:01:27

Luminus and duct might be good examples as well to study architecture not necessarily use

sova-soars-the-sora17:01:41

I was wondering.... I want to conj a map onto a vector of maps. But! I only want to conj a fresh map on if there is no map with 2 keys matching. However, if these 2 keys do in fact match, I want to just update the entry. Should I reduce-kv / keep-indexed on the vector of maps, filter it (?) on those two keys, and then if it exists / is not empty update the extant entry, and if it's not just conj? I want to have tweezers that let me update in the vector or append, but it seems like having a seek is inexorable.

andy.fingerhut17:01:44

Do you care about the relative order of the maps in your vector of maps at all?

andy.fingerhut17:01:23

If you do not, you could instead have a map of maps, where the values are the maps, and the keys are some values that contain the 2 keys that you want to be unique.

sova-soars-the-sora17:01:56

maybe i'm not communicating my need correctly. map of maps? o.o

andy.fingerhut17:01:57

e.g. a vector containing those 2 key values only, or a map containing those 2 values as values.

andy.fingerhut17:01:25

It is possible to have maps where the keys and/or values are themselves maps, or other kinds of immutable values.

andy.fingerhut17:01:51

immutable values can nest in arbitrary ways.

kari17:01:19

If I build a jar with command lein with-profile +single-node ring uberjar ... and then run the jar with command: java -jar target/uberjar/simple-server-1.0-standalone.jar ... everything works just fine - application finds the environmental variables defined in file profiles.clj: :single-node { :env { :ss-env "single-node" :my-env "dev" ... *BUT* if I bake the same jar into a Docker image and then start the application exactly the same way in a Docker container the app does not find the environmental variables defined in that profile. Really weird. I first thought I have done some stupid configuration error but I have checked this many times.

kari18:01:42

I was wondering what differences there are. I suddenly realized that the profiles.clj is not in the Docker image. I somehow assumed that it is baked into the jar somehow.

kari18:01:41

Yep. That's it. I just copied the app into another directory in my host - not working there either.

kari18:01:54

The lesson: Never assume anything. 🙂

kari18:01:48

... but I'm still puzzled how the app reads the profile env variables in the project directory but not in some other directory.

kari19:01:30

Ok. I think I got it. There is this .lein-env file (by Environ) that apparently gets generated when building the jar.

andy.fingerhut17:01:35

You do not have to do this, but if I understand your desired behavior correctly, it would be a very natural way to take advantage of the characteristics of maps, for keeping the maps unique on the 2 keys you want to keep them unique on.

sova-soars-the-sora17:01:01

Hmm.. so the key for each map is a combo term of the keys I want to demand uniqueness on?

andy.fingerhut18:01:24

And there are choices in that. The key you want uniqueness on could be itself a map, with only the 2 key/value pairs from the original map that you care about uniqueness for.

sova-soars-the-sora18:01:06

That's a cool idea. How do you suggest I compose these keys? It's like usernames and article IDs to enforce the fact that a user may only rate an article once (or update their rating to something new, but all in all, one rating per article per user)

andy.fingerhut18:01:11

i.e. you could construct that using select-keys on the original map you want to put in the collection.

sova-soars-the-sora18:01:29

tell me more about that?

andy.fingerhut18:01:34

user=> (select-keys {:username "a" :article-id 17 :other-stuff "foo"} [:username :article-id])
{:username "a", :article-id 17}

andy.fingerhut18:01:13

You give it a map, and a sequence of key values, and it returns a map containing only those key/value pairs from the original that have a key from the sequence.

sova-soars-the-sora18:01:14

hmm.. i'm not sure how i would incorporate this into my current toolkit,

sova-soars-the-sora18:01:48

almost all my maps in the vector have the same keys

sova-soars-the-sora18:01:52

just different values for them

andy.fingerhut18:01:06

So you have many maps in your vector, and they all have different values for the user name and article id, as you wish?

andy.fingerhut18:01:53

If you had such a vector, you can create a map of maps from it, indexed by the "2 element maps" described above, like this:

andy.fingerhut18:01:38

First define a little helper function that creates the 'unique key' you want from your maps: (defn make-key [m] (select-keys m [:username :article-id]))

andy.fingerhut18:01:19

Then some code like this can create a map of maps:

andy.fingerhut18:01:28

(def vector-of-maps [{:username "a" :article-id 7 :other-stuff "foo"} {:username "b" :article-id 7 :other-stuff "bar"}])

andy.fingerhut18:01:36

(def map-of-maps (into {} (for [m vector-of-maps] [(make-key m) m])))

1
spirosbax20:01:30

does anyone know any ML companies / open source projects using clojure, elixir or FP in general ?

eggsyntax21:01:33

There are certainly folks doing ML stuff in Clojure lately. @U04VAD6RL has been writing a lot of interesting blog posts on the topic; her blog is at http://gigasquidsoftware.com This list of companies (& see linked success stories / community stories pages) is one place to start looking: https://clojure.org/community/companies

irfan22:01:23

Hi. I come from the JavaScript / NodeJs world. Should I use Leiningen or Boot?

eggsyntax00:01:39

There are plenty of folks who like each, but I recommend starting with Leiningen. There’s a lot more beginner’s documentation that uses it, and it’s pretty user-friendly to get started with.