Fork me on GitHub
#beginners
<
2016-02-12
>
bridget00:02:41

I know exactly what you're talking about, drewverlee

bridget00:02:01

When I was first going through those, I followed some folks and tried to learn from the solutions

bridget00:02:33

But it seems that a lot of folks try for very, very terse answers (some kind of code golf, maybe?) which are hard to learn from

meow00:02:34

@bridget: I felt the same way when I tried to do those. Didn't get very far because of that.

bridget00:02:35

I was looking through who I followed to find someone who does not do that...

bridget00:02:21

Yeah, meow. I wonder if anyone here knows of someone whose answers are more helpful

meow00:02:27

That would be really helpful to know, thanks.

meow00:02:48

I don't know that, sorry.

bridget00:02:16

And not to say there isn't any value in the terse answers. There are things you can pick up from those, too

bridget00:02:37

thattommyhall's are ok

bridget00:02:48

I'm a fan of chouser's, but his are definitely of the terse sort

bridget00:02:12

I like going through my own and seeing the historical record of my learning simple_smile

meow00:02:09

Don't look too closely at any of my github history. I like to just dive in and create a big mess that barely works and then rework it over and over and over and, oh my why can't I wake up just once without realizing my code still sucks until I finally just give up and declare it good enough.

meow00:02:25

I've learned to shoot for (- 100 10).

meow00:02:47

¯\(ツ)

meow00:02:56

I'm so glad Slack lets you edit recent posts. So many typos! Can't type for shit half the time. 😉

meow00:02:20

The other half of the time Meow is on fleek. 😎

bridget00:02:47

I empathize

Drew Verlee01:02:51

@alexmiller, thanks I'll be sure to follow him!! Someone should make a opinionated list of ppl to follow for beginners.

bridget01:02:12

ha ha I have some pretty bad answers, meow. Thanks, though

akiva02:02:41

Be careful or we’ll end up with a #beginners-discuss channel.

olegakbarov18:02:06

i struggling with raw sql queries in Korma

olegakbarov18:02:20

i do appreciate any help

shaun-mahood19:02:34

@olegakbarov: Might not be helpful, but is there a particular reason to use Korma over just doing the raw query using clojure.java.jdbc?

olegakbarov19:02:33

i don’t know actually

olegakbarov19:02:59

i was working with korma and stumbled this problem with upsert

olegakbarov19:02:24

i think i’ll give a try clojure.java.jdbc if nothing will work with korma

shaun-mahood19:02:59

I'm sure korma has areas where it really shines (I've not tried it), but when I want to do raw queries I've found clojure.java.jdbc to be really solid. I've tried a bunch of the other SQL libraries and not found one I like better for raw sql.

olegakbarov19:02:52

excuse me (complete noob in both Clojure and SQL) but what method might for my case?

shaun-mahood19:02:13

insert! is what you want

olegakbarov19:02:11

thank you, i’ll give it a try

shaun-mahood19:02:49

Your query should be something like this

(jdbc/insert! db-spec ["INSERT INTO events ?, VALUES ? ON CONFLICT (id) DO UPDATE SET title = EXCLUDED.title" events values] )

olegakbarov19:02:31

thank you! 🙌

seancorfield19:02:38

jdbc/insert! takes hashmaps to insert which represent rows; jdbc/execute! will accept SQL for arbitrary updates.

seancorfield19:02:49

(disclaimer: I maintain clojure.java.jdbc and so far I’ve been the main contributor to the community docs as well)

chadhs19:02:26

i was using pmap to make applying a function to a collection parallel which is really handy

chadhs19:02:43

what would be the right way to limit the number of parallel threads?

polymeris19:02:06

(defn boolseq-> [boolseq things]
  (->> (map (fn [b r] (when b r)) boolseq things)
       (filter identity)))

(defn ->boolseq [coll things]
  (map (fn [n] (some #(= (nth things n) %) coll))
       (range (count things))))
There must be a cleaner way to do this...

polymeris20:02:21

(defn ->boolseq [coll things]
  (map (fn [t] (some #(= t %) coll)) things))
This works, apparently

seancorfield20:02:47

What exactly is it trying to do @polymeris ?

polymeris20:02:05

convert from a seq like [true true false false true] to ["a" "b" "e"], given a list of things ["a" "b" "c" "d" "e"]

seancorfield20:02:14

@chadhs: pmap is a bit of a sledgehammer — it doesn’t give you any knobs to control the behavior. You need to drop down to lower-level (Java) stuff to really control the threads I think…? Maybe fold in the reducers library provides more control… trying to think…

polymeris20:02:33

so filter the things by the seq of booleans

seancorfield20:02:34

@polymeris: So the seq of booleans and the things collection are the same length?

chadhs20:02:49

@seancorfield: perhaps a better way to ask my question is… is there a simple way to n operations x at a time?

shaun-mahood20:02:59

@seancorfield: Thanks for clojure.java.jdbc btw, I really like it

polymeris20:02:22

maybe I should convert the coll into a set first, then use contains? instead of some

seancorfield20:02:50

@chadhs: not really a simple way, no…

seancorfield20:02:32

@polymeris: Is the seq of things always a unique collection (i.e., every item different)?

polymeris20:02:06

both the coll and the things are unique collections

chadhs20:02:24

@seancorfield: do i need to think about my approach perhaps and looking at core.async and maybe putting commands on channels

seancorfield20:02:19

That at least lets you specify your partition size...

seancorfield20:02:28

@polymeris: I think my gut would be to zip the two collection and then run keep over the result to ensure they matched up positionally… (keep (fn [[yes? value]] (when yes? value)) (map vector coll things)) maybe?

adampash20:02:04

Hi everyone! I’m fairly new to Clojure and brand new to the Clojure community. In particular, I’ve been dipping a toe into Clojurescript and Om Next (I’ve got a lot of experience with vanilla React). Is this a good place to ask fairly beginner questions? (I’m making a leap based on the channel name.)

polymeris20:02:12

oh... keep is filter identity, cool

seancorfield20:02:32

Not quite, it keeps a sequence that is the result of applying the predicate, not the elements of the original sequence.

seancorfield20:02:38

But (filter identity (map #(when %1 %2) coll things)) would also work I believe?

seancorfield20:02:03

i.e., make the map produce either nil or the corresponding value from things

seancorfield20:02:50

Yep, beginner questions are welcome here and there are also #C03S1L9DN and #C0DT1AZD3 channels too.

polymeris20:02:25

yeah, it works, but doesn't look so nice

adampash20:02:42

Oh cool. My questions are mostly focused on using cljsjs packages in om next—does that seem better suited for #C0DT1AZD3?

seancorfield20:02:38

@adampash: Sorry, had to step away. I looked in #C0DT1AZD3 (I’m not a member) and it looks like #C06DT2YSY is actually where all Om / Om Next chatter happens (I’m not a member of #C06DT2YSY either).

adampash20:02:58

Hey, yeah, I saw that, too. simple_smile

adampash20:02:34

(and no problem)

seancorfield20:02:53

I haven’t touched ClojureScript for about a year at this point and it’s a space that moves pretty fast — and although we built a p.o.c. with Om at work, we then rebuilt it with Reagent, even tho’ we eventually abandoned that project altogether — so I think all my cljs knowledge is way out of date at this point 😞

adampash20:02:26

Well, thanks for pointing me in the right direction! 😄

coyotespike21:02:12

I'm building a fairly basic web scraper, my first. I'm trying to figure out how to submit cookies properly, so I'm authenticated. The Ring resources I found address how to set cookies for users, not so much how to get and send cookies. I copied the cookie from my browser and tried to encode it as a header, but no love. Any ideas?

coyotespike21:02:52

For instance, this didn't work:

(add-query-params ""
                                {:throw-exceptions true
                                 :headers {"Cookie" "cookie-from-browser-here"}})

donaldball22:02:25

Ring is library for helping build web servers. A web scraper requires the services of a web client. If you’re using clj-http, as is the most common choice, you’ll want to look at: https://github.com/dakrone/clj-http#cookies

coyotespike23:02:41

@donaldball: thanks! i saw clj-http but not the cookies section - I'll give that a shot