Fork me on GitHub
#clojure
<
2019-05-24
>
aarkerio00:05:49

newbie question: in : "(wrap-cors :access-control-allow-origin [#"http://localhost:3000/"])

aarkerio00:05:55

what "#" means?

noisesmith00:05:50

user=> (class #"foo")
java.util.regex.Pattern

noisesmith00:05:53

#"" is a data reading literal for regular expressions, and can be used with things like string/replace, re-matches, re-find

👍 4
noisesmith00:05:30

@aarkerio a guide to various weird sigils in clojure programs https://clojure.org/guides/weird_characters

aarkerio00:05:29

cool! thanks a lot!

carkh08:05:37

Is there a way in a test to tell it to just fail ? like for instance if the wrong dispatch function is called

carkh08:05:30

and without resorting to (is (= 1 2)) or some (assert false ...) trickery

carkh08:05:58

hum maybe just throwing an exception would make it i guess

fmn10:05:11

Does anybody know who I have to contact if I want to delete my own package in clojars?

fmn12:05:45

Thank you. It seems deleting it just put another burden for the admin.

dangercoder12:05:10

Is there any Redis library that implements delayed task scheduling? I need to delay a task which is distributed and kept in redis, something like this one: https://stackoverflow.com/questions/10868552/scalable-delayed-task-execution-with-redis I currently listen to expire keyspace notifications.. not sure if that is so scalable.

jeroenvandijk12:05:39

hmmm funny sounds very similar to what i'm looking at right now (maybe i'm wrong)

jeroenvandijk12:05:38

you can put timestamps in redis keys so you are independent of Redis time constructs? (need to put the expiry on keys big enough so it doesn't interrupt with your own logic)

jeroenvandijk12:05:28

are you working in a particular domain?

dangercoder12:05:34

Not really, its just that I want to do it in a way that scales 🙂

jeroenvandijk13:05:03

then not use Redis 🙂

jeroenvandijk13:05:21

or maybe the wrong datastructure one sec

jeroenvandijk13:05:19

Anyway hard to say if that will solve your issue, and if Redis is the bottleneck at all

Noah Bogart13:05:36

in the card game I'm working on, I have a "card" object, which is just a map with certain properties. To make interacting with the objects easier, I have a bunch of "accessor"/getter functions: corp? returns true if the card is a Corp card, installed? returns true if the card is currently installed, etc. These functions are all solely reliant on the card map passed in

mloughlin14:05:04

for the basic ones you could do away with the fn and replace with keyword (:installed? card)

mloughlin14:05:55

given (def card {:installed? true})

Noah Bogart15:05:19

Sadly, a lot are more like (= "Hardware" (:type card)), which is a little more annoying and messy to write inline. And then of course, because it's a complex game, others are (or (= "Identity" (:type card)) (= "Fake-Identity" (:type card))), which is really annoying to write multiple times

mloughlin16:05:52

I feel like I've heard @U050P0ACR talk about this kind of decision on his podcast, http://Lispcast.com. I'm sure he's got way more insight than me 😉

👍 4
Noah Bogart19:05:22

thanks for the recommendation! i'll check it out

Noah Bogart13:05:21

Is there any "best practice" with organizing groups of functions like this? Seeing as I'm not creating multiple types, I don't see a benefit necessarily of using a protocol. if this was in java, these would all be normal "attributes": public isCorp() etc

Noah Bogart13:05:24

I've moved them into a card-properties namespace and [card-properties :refer :all] them, but I feel like I'm falling into a trap or a code smell, lol

Markus Åkerlund Larsson13:05:31

Collecting them in a namespace seems reasonable to me

👍 4
Jakub Holý (HolyJak)18:05:46

Can [pre|post]walk be used to extract selected leaves from a nested data structure? How? I want to descend only into some submaps and extract particular key from the leaf maps.

borkdude19:05:42

@holyjak do you want to prune the tree or get a series of values out of it?

borkdude19:05:43

(w/postwalk (fn [m] (if (map? m) (select-keys m [:a :b]) m)) {:a 1 :b 2 :c {:a 1 :b 2 :c 3}})
{:a 1, :b 2}

👍 4
noisesmith19:05:02

@holyjak I've used tree-seq plus a filter to select leaves for this sort of thing

👀 4
Jakub Holý (HolyJak)19:05:05

doesn't tree-seq return all nodes instead of only leaves?

noisesmith19:05:48

right, but you can take the final sequence of nodes and return only leaves in your branch? and children functions, you can prune nodes whose children are not wanted

noisesmith19:05:56

in fact the function to return only the leaves should just be (filter (complement branch?) ...) where branch? is the same function you passed to tree-seq initially

noisesmith19:05:35

(cmd)user=> (load-file "/tmp/foo.clj")
(1 4 6 7)
(ins)user=> (print (slurp "/tmp/foo.clj"))
(def input
  {:a 1
   :b {:a 2
       :b 3}
   :c {:a 4
       :b 5
       :c 6}
   :d {:a 7
       :b {}}
   :e {:c 8}})

(def unused-keys
  #{:b :e})

(def branch? coll?)

(def children
  #(map (fn [node]
             (if-not (map-entry? node)
               node
               (if (contains? unused-keys (key node))
                 []
                 [(val node)])))
           %))

(remove branch?
        (tree-seq branch?
                  children
                  input))
nil

noisesmith19:05:15

that declines to descend into keys and only returns vals out of key/value pairs, and removes all keys in a blacklist instead of descending deeper when found

Jakub Holý (HolyJak)19:05:30

I want to get out a seq of (leaf) values but exclude some branches

noisesmith19:05:43

how far above the leaves are the branch points you know you won't want?

borkdude19:05:57

something like:

(remove map? (tree-seq map? #(vals (select-keys % [:a :b])) {:a 1 :b 2 :c {:a 1 :b 2 :c 3}}))
(1 2)
?

borkdude19:05:48

taking a look at clojuredocs for those functions might give you an idea

Jakub Holý (HolyJak)19:05:20

Thanks, I think tree-seq doesn't do what I need but I can look at its implementation and copy that for my use case. (The thing is I have a nested data structure consisting of maps and seqs)

noisesmith19:05:30

usually with tree-seq my predicate is coll? which catches maps and seqs

noisesmith19:05:05

but instead of coll? you can use a predicate that both checks for coll? and removes branches you don't want

❤️ 4
noisesmith19:05:58

(fn [node] (and (coll? node) (not (ignored? node)))) - where ignored? checks for k/v pars with excluded keys, or whatever

Alan Thompson19:05:53

@holyjak You can easily process tree-like data structures with the Tupelo Forest library. See the Lightning Talk: https://youtu.be/RtavTnRr0oM

lilactown19:05:37

are there any libraries for doing bidirectional transformations of Clojure data?

val_waeselynck21:05:01

What do you mean by "bidirectional"?

lilactown21:05:50

ex. have a transformation t that takes some clojure data a and transforms it into b, and can also apply the transformation to take b into a.

lilactown21:05:37

one of the things that seems to come up in literature is taking an updated b and transforming it into an updated a as well

lilactown21:05:50

does that make sense? 😬

val_waeselynck05:05:50

Sure. I don't know of any library that does that, except of course for very narrow cases like serialization.

val_waeselynck05:05:24

Or, you know, inc and dec :p

wiseman20:05:18

are there any other clojure/clojurescript streamers? i know of https://www.twitch.tv/jplur_

👍 4
upgradingdave20:05:44

Hey @wiseman, I just recently challenged myself to try and build a twitch chatbot during livestreams on twitch: https://www.twitch.tv/upgradingdave

upgradingdave20:05:44

There’s also another clojure livestreamer here: https://www.twitch.tv/rhonin52/

upgradingdave20:05:55

I try to stream every M, W, F 7:30 eastern time. If you’re around, please stop by, love to have some help building the twitchbot!

wiseman04:05:41

thanks, i’ll check those out

seancorfield20:05:12

There's a #livestream channel where folks used to talk about that but it's been inactive for a long time 😐

seancorfield20:05:25

I think it would be fun if folks got that back up and running @wiseman... it's always very interesting to see different people's workflows!

👍 4
wiseman20:05:58

yeah, that’s mostly what i’m interested in. the details of workflows that don’t always get documented on github pages, etc.

seancorfield20:05:42

I can't remember what I tried to use to stream with back then... Not Twitch, for sure. But mostly I work on a proprietary code base so streaming isn't something I can really do much of the time.

seancorfield20:05:07

I did do a short YouTube video recently of my workflow with REBL (and Atom/Chlorine).

seancorfield20:05:23

(because folks kept asking about "how to use" REBL)

dpsutton20:05:58

someone livestreamed (and recorded) their advent of code solutions. I think @tonsky and @potetm?