Fork me on GitHub
#clojure
<
2017-05-03
>
danburton00:05:23

Is there a "community recommended" way to consume yaml in clojure?

hagmonk01:05:39

@danburton I would just check https://crossclj.info and see what yaml libs seem to used in projects you recognize or respect, and/or review the libraries available and pick one that suits your coding preferences

tvalerio01:05:37

Hi, can anyone give a little help? I'm trying to figure it out how can I search for a nested value inside a list and I haven't done yet

tvalerio01:05:45

I have the above list:

({:receivable-response {:identifier UX00126, :status 01, :message Recebivel já foi importado para o sistema}} {:receivable-response {:identifier UX00127, :status 00, :message Recebivel importado com sucesso}} {:receivable-response {:identifier UX00128, :status 00, :message Recebivel importado com sucesso}})

tvalerio01:05:53

how can I verify if there's a status equals to 01 in this structure?

tvalerio01:05:05

I've tried to use filter, but I could not realize how to access the nested status value

tvalerio01:05:46

I did something like this:

john01:05:56

if the map is always in a list, and there's only ever one item in that list, you can just do (first processados) before passing it to filter

john01:05:47

Oh, but your map is nested and your code isn't looking an extra layer deep.

john01:05:32

oh, you have multiple maps in there. wrap your code in three backticks "`" to make it a code block

tvalerio01:05:09

oh, sorry! I edited the message

john02:05:58

that's a little ugly

john02:05:39

huh, you'd think clojurebot would print the original source :thinking_face:

john02:05:17

so, something like

(defn- mount-message
  [processados]
  (let [filtered (filter #(= (:status (:receivable-response %)) "01") processados)]
    (println "filtered: " filtered)
  ))
untested ^^

tvalerio02:05:48

thanks! It worked this way:

(defn- mount-message
  [processados]
  (let {filtered (filter #(= (get-in % [:receivable-response :status]) "01") processados)]
     (println "filtered: " filtered)
  ))

melindazheng03:05:56

Calling all fellow Singaporean Clojurians, please search #clojure-sg to join Singapore Clojure slack channel, we have regular Singapore Clojure Meetup monthly, do come and join us.😀

kauko04:05:23

I have a test utils namespace, that has a function that does some checks and uses is. I want to use that function, but I want to write a test that checks that an assertion that should fail, does fail. Is there a way to do that, other than remove the is call from the helper function?

kauko04:05:33

I'd need a way to a complement is 🙂

kauko04:05:26

Hmm, maybe I could use a dynamic var or something like that. If it is true, the helper function does the is assertion. If not, it just does the checks and returns the result.

elena.poot05:05:20

I know I've seen a library that had some enhanced testing tools, including an is-not macro, but I can't find it via google. I think it was in one of the big "useful utilities" libraries, rather than something specifically focused on testing.

elena.poot05:05:43

personally, I just use (is (not ...)) 🙂

qqq06:05:20

how do I get the ascii code corresponding to a char ?

qqq06:05:34

that works on the clj side of cljc

qqq06:05:41

does not appear to work on the cljs side of cljc

jumar06:05:42

yeah, probably because in cljs it's "a", not pure char

jumar06:05:07

don't know of better way than (.charCodeAt \a 0)

skylar07:05:00

Does anyone have any experiences with hara: https://github.com/zcaudate/hara who would like to share?

danielgrosse08:05:49

I want to execute shell commands and receive there feedback when their done, but I can't get manifolds chain to recognize it. Do you now sources, where I can look at on this topic?

mccraigmccraig09:05:35

@danielgrosse how are you executing the shell commands ?

danielgrosse09:05:13

Actually i experimenting with conch from raynes

noisesmith16:05:24

danielgrosse: my experience is that if what I want wasn’t directly offered by conch, it was easier to use ProcessBuilder and Process - eg. if I wanted to make an interactive process and read it’s stdout and send data to stdin, or run an async command and get its output later

noisesmith16:05:46

the java apis for these is simpler than conch is

mccraigmccraig09:05:41

looks like conch returns a lazy-seq of output lines ? so you would need a thread to convert that to a stream (or deferred)

carter.andrewj10:05:33

What's the reasoning for why (get-in {:foo {:bar "stuff"}} nil :not-found) returns {:foo {:bar "stuff"}} instead of :not-found?

moxaj11:05:05

@carter.andrewj my guess: nil is interpreted as an empty sequence of keys, so you get back the initial data structure

jtth13:05:23

Is there a straightforward way of renaming a Leiningen project, or do I need to use some Cursive magic to do that?

quoll13:05:54

@carter.andrewj that answer from @moxaj is correct. get-in starts with the provided map, and keeps descending down through the nested maps until the sequence of keys has been exhausted. An empty seq is an “already exhausted” sequence of keys, so there is no more descent required, and the entire map is returned.

elevi14:05:24

When dealing with long running timeout channels in Go, to avoid memory leaks, I use the Stop() method to clean resources and to close the background goroutine, e.g:

c := make(chan bool,1)
t := time.NewTimer(time.Hour)

c <- true

// this select returns immediately (c has message inside)
select {
  case <-c:
  // handle message
  case <-t.C:
  // timeout
}
// stop the one-hour timer
t.Stop()

How can I mimic this behavior in core async, does the GC know how to clean timeout channels that aren't in use any more ?
(use 'clojure.core.async)
(def c (chan 1))
(>!! c true)
(alts!! [(timeout 100000000) c])
# what happen to the timeout channel ? its still running in the backgroud ?

tbaldridge14:05:12

Go blocks, are callbacks that are attached to channels. Channels are just queues + a few locks. All of that can be GC'd

tbaldridge14:05:22

so yes, in a round-about way it can all be GC'd

tbaldridge15:05:14

And here's a video that goes into way too much detail on the subject if you care to learn more 🙂 https://www.youtube.com/watch?v=VrwVc-saWLw

elevi15:05:27

it make sense, since they aren't green threads, just a state machine 🙂 thanks a lot

zylox15:05:48

TIL the term green threads

blueberry15:05:08

@jtth Just edit the name of the project in project.clj in any text editor.

jtth15:05:12

blueberry: that renames it in every namespace throughout the project?

blueberry15:05:01

The name of project is not directly connected with the namespace. You can call the project foo, containing only namespace bar.

blueberry15:05:05

On the other hand, leiningen doesn't have anything to do with actual namespaces in clj files...

jtth15:05:33

Ah, I didn’t know if there was some pattern-matching lein script I could run like lein rename or something. Thanks.

hagmonk16:05:16

@tbaldridge I want more of those videos, I bought access to your ones on <https://tbaldridge.pivotshare.com> 🙂

hagmonk16:05:58

oh god, how do I squelch the huge wall o' text

hagmonk16:05:18

there we go

theikkila17:05:45

you know if there is some function which does following:

(when (some-do
       (operation-1)
       (operation-2)
       (operation-3))
  (run-if-any-operation-returned-anything-else-than-nil))
I’m seeking for the some-do-function

noisesmith17:05:40

@theikkila (when (or …) …)

theikkila17:05:09

hmm good one, thanks 🙂

noisesmith17:05:18

that stops on the first truthy one of course

theikkila17:05:20

hmm, well i would like to get all the operations executed either way

tanzoniteblack17:05:50

@theikkila if you want to run all the operations, and then only run another operation if any return nil you could do (when (some nil? ((juxt opt1 opt2 opt3) <insert-val>)) (only-if-any-nil))

tanzoniteblack17:05:11

or some variation of things on that idea, don’t think there’s a built in function for this though 🙂

theikkila17:05:21

well actually all of those operation-*-functions are side effects into database and the “after”-function is trigger if any of those had any results

theikkila17:05:53

otherwise juxt would be perfect but I don’t have same arguments with every function

tanzoniteblack17:05:17

then presumably you know the functions at the time of writing this code? and you can just do something like:

(when (some (complement nil?)
            [(fn1 <arg-list>)
             (fn2 <arg-list>)
             (fn3 <arg-list>)])
  (my-only-if-something-not-nil-fn))

theikkila17:05:08

I will go with that

tanzoniteblack17:05:20

side note: (complement nil?) might be the same as some?

donaldball17:05:20

some? is equivalent to (complement nil?)

tanzoniteblack17:05:17

😄 most of my use cases don’t involve differentiating between is definitely not nil, but is some value (including false) and it's falsey, so I tend to forget about some?

mkeathley18:05:35

has EDN been deprecated, or is it still something people use?

mkeathley18:05:40

Or did it never take off?

qqq18:05:22

I use EDN.

mattly18:05:10

I use EDN for simple things typically done at compile- or app start time, but recently migrated other runtime stuff to transit

mkeathley18:05:47

Any advantage to Transit other than being in JSON?

mattly18:05:02

you can use Transit with MessagePack as well

mattly18:05:07

there's a few advantages:

mattly18:05:31

1), for cljs, JSON + transit deserializing can be a lot faster than EDN parsing

noisesmith18:05:11

it is able to exploit structural sharing as well

mattly18:05:31

2) I think it's easier to build custom types that you can share across clj/cljs

mattly18:05:17

the main disadvantage IMO is that I kept writing the same pattern around a writer in JVM-land over and over again

mattly18:05:28

until I just made my own projectname.transit namespace to wrap that

noisesmith18:05:50

I wonder how many times we’ve done this collectively, heh

noisesmith18:05:44

fyi .toString is str

mattly18:05:44

I stripped out the parts for reading/writing custom types

mkeathley18:05:50

Seems like you could stick that on clojars

mattly18:05:02

simple-transit

mattly18:05:26

is there any advantage to re-using a BAOS ?

noisesmith18:05:54

the disadvantage is coordinating access if you use threads at all

noisesmith18:05:00

I guess you skip the allocation cost?

noisesmith18:05:09

but in a local scope you can reuse one for sure

mattly18:05:16

hm, where's the vomit emoji?

mkeathley18:05:19

What’s a BAOS? 😊

mattly18:05:26

ByteArrayOutputStream

mkeathley18:05:43

Create a BAOS pool 😛

noisesmith18:05:46

I’d reuse in a let where it never escapes scope or enters another thread

mattly18:05:06

yeah, I suppose if you had to do a lot of serialization in serial

noisesmith18:05:09

eg. if you might have multiple transit messages coming on one stream and you are looping

mattly18:05:23

while eating cereal

noisesmith18:05:23

which would make sense with eg. a websocket or kafka

mattly18:05:57

and listening to Serial

mattly18:05:02

(ok I'll stop)

mkeathley18:05:16

No, please keep going

mattly18:05:11

I don't want to be a serial offender

dominicm18:05:19

Cap'n proto is good for serial I hear

tbaldridge19:05:53

@mkeathley one of the key reasons for Transit is that it's much faster than EDN, especially in CLJs.

tbaldridge19:05:04

And EDN really only has parsers for .NET, JVM and JS. The EDN readers in Python/Ruby are super buggy. But Cognitect maintains readers/writers for Transit on JS, Java, Clojure, CLJS, Python and Ruby. And transit libs exist for other platforms as well.

dpsutton19:05:32

got transit for emacs-lisp coming down the pipeline?

tbaldridge19:05:32

I haven't heard about anything like that from Cognitect, but the format is out there, and if you have a JSON parser for a platform, writing a transit impl probably takes 10-16 hours of dev work.

tbaldridge19:05:05

That was also a goal of Transit, make it simple to implement on new platforms.

dpsutton19:05:58

i was just kidding

mkeathley19:05:37

thanks @tbaldridge that makes sense

mkeathley19:05:53

@dpsutton You kid, but watch it happen 😛

noisesmith20:05:57

hey, vim supports json now, I bet I could make a vim transit plugin

arthur21:05:32

hi folks, I'm trying to get ring/piped-input-stream to actually stream text when i call .write like this:

(response/response
             (ring-io/piped-input-stream
              #(let [w (io/make-writer % {:encoding "UTF-8"})]
                 (.write w "start\n" 0 4)
                 (Thread/sleep 1000)
                 (.write w "done\n")
                 (.flush w))))
which waits a full second and then prints
start
done
so it appears not to be streaming

hiredman21:05:26

ring is not the thing to use if you want to stream data

hiredman21:05:56

it can sort of work

hiredman21:05:36

if you move the flush before the sleep, it may work for you

hiredman21:05:21

streams created by http://clojure.java.io tend to be buffered

arthur21:05:05

@hiredman hmm and wrapping this in a middleware that flushed the stream returned from piped-input-stream seems not to work either

hiredman21:05:35

so it may be dependent on what ring server server you are using

hiredman21:05:46

it has been a few years, but I think I recall jetty having a buffer

hiredman21:05:18

e.g. if your data is smaller that some number of k, jetty won't send it until the stream is closed

arthur21:05:37

by exparamentation is seems that 7k is required to get anything to push

hiredman21:05:00

the latest ring release has some support for async responses, I am not sure how that works with all the buffers, you might try that

hiredman21:05:32

aleph and http-kit are the two main http servers people go with for streaming data

tbaldridge22:05:15

and Pedestal...

tbaldridge22:05:07

But I agree with @hiredman ring doesn't handle streaming data very well, and doesn't handle async at all.

dergutemoritz22:05:37

Immutant also has support for streaming on top of Ring

dergutemoritz22:05:51

@tbaldridge As @hiredman just pointed out, apparently there is async support now in the latest Ring, though!

tbaldridge22:05:34

Yeah, but to be fair it's new, and it's basically callbacks chained together. While other solutions have been around for years.

tbaldridge22:05:11

And the way it's designed you have to write your middleware twice, or support two calling conventions 😐

dergutemoritz22:05:30

Yeah, certainly not the most recommendable option as of yet 🙂

dergutemoritz22:05:57

I see, that's too bad 😞

weavejester22:05:06

Pedestal was designed from the ground up with async in mind, so if you require a lot of asynchronous I/O that might be worth taking a look at.

weavejester22:05:42

Ring 1.6.0 supports asynchronous handlers, but not non-blocking I/O. However, it’s easier to go from a simple synchronous design to a performant asynchronous one with Ring.

weavejester22:05:33

Ring asynchronous handlers are made to be backward compatible, so you can transition when necessary.