Fork me on GitHub
#clojure
<
2019-02-25
>
potetm12:02:18

@grzegorzrynkowski_clo At first I was going to suggest getting rid of the as-> threader, but after looking at it, I think the following is most straightforward:

(let [b (ServerBuilder/forPort port)]
  (doseq [h handlers]
    (.addService b h))
  (.start (.build b)))

potetm12:02:31

In general, I prefer using side-effecty constructs for side-effecty operations.

👍 1
Greg Rynkowski21:02:14

make sense, thanks

potetm12:02:01

For example, doseq for adding services to a mutable object.

potetm12:02:55

If you wanna keep the startup msg, I would do:

potetm12:02:58

(let [b (ServerBuilder/forPort port)
      srvr (do (doseq [h handlers]
                 (.addService b h))
               (.start (.build b)))]
  (println "gRPC server started listening on port" port)
  srvr)

cddr13:02:20

One thing I've found useful to build into functions like these is a promise that is delivered once the service has started. It can either be passed in by the caller, or returned as part of a map that wraps the server object. This makes it possible for tests to use it to ensure the service is ready for requests before the test starts hitting it.

👍 1
bcambel15:02:40

Anyone has an experience with Multi-part uploads with Amazonica ? Context: I am trying the merge 30K+ files into a single file in a Lambda function.

dtsiedel17:02:12

Why does transit-cljs allow you to read/write directly from/to strings, but transit-clj require the construction of ByteArrayInputStream/`ByteArrayOutputStream`? Is there a way to read and write strings directly in the Clojure version?

noisesmith18:02:30

@dts.siedel because String is the right abstraction in a js runtime, but not in the java runtime. It's simple to call the String constructor on a byte-array, but you end up doing a bunch of pointless work in common use cases if you convert to string (because often your target isn't a String in memory, it's an output destination like a File or socket which provides and OutputStream to write to directly). Similarly for input, the thing that you get the transit data from will almost always offer an input-stream, getting a String first then translating reduces flexibility and adds pointless layers of work.

dtsiedel18:02:41

That's fair. It just seemed very non-Clojurey to be creating and mutating this odd Java object, but it makes sense in that context. I'll just make a wrapper for my purposes that dumps to an in-memory string.

dtsiedel18:02:00

Thanks for the response @U051SS2EU

noisesmith18:02:11

yeah - it's very easy to convert a byte-array to string or string to byte-array

noisesmith18:02:17

I think there's a good comparison to the various collection operations here - it would be trivial to provide a function that scans a collection for a matching key, but it's not provided in order to make using a set or hash-map the low-friction path

noisesmith18:02:17

(compare to common-lisp or scheme which have sets/hash-maps but many programs use lists instead with O(n) access because it has less friction with a normal coding style)

dtsiedel18:02:43

It makes a lot of sense from that perspective

Audrius18:02:58

How to automatically construct spec from data structure?

JIacheng Yang19:02:32

is that even doable for a highly dynamic and flexible thing like spec?

dottedmag20:02:31

Is there a Markdown parser in Clojure (or Java) than can parse Markdown with GH extensions?

dottedmag20:02:11

@U4YGF4NGM That's what I'm playing with (via commonmark-hiccup), though it does not seem to be handling tables in my test files even after adding an extension ta parse them.

Braden Shepherdson20:02:01

I'm pondering what best to do with a vanilla java.util.concurrent.Future I'm getting from the Firebase API. trying to .get() it seems to be blocking my REPL thread forever? not sure.

Braden Shepherdson20:02:20

is there a way to wrap it into a Clojure future that will play nicer?

noisesmith20:02:07

the functions that work on a clojure future also work on that object

noisesmith20:02:29

realized?, deref (with optional time-out arg), future-cancel

Braden Shepherdson20:02:55

oh, I didn't think I could deref it.

noisesmith20:02:21

deref will block the same way .get will, except you can optionally provide that time-out arg

noisesmith20:02:19

I was wrong about realized?, but deref will work

egret.run=> (doto (java.util.concurrent.FutureTask. #(+ 1 1)) (.run))
#object[java.util.concurrent.FutureTask 0x2fa829be "[email protected]"]
egret.run=> (def f *1) 
#'egret.run/f
egret.run=> (realized? f)
ClassCastException java.util.concurrent.FutureTask cannot be cast to clojure.lang.IPending  clojure.core/realized? (core.clj:7453)

egret.run=> @f
2

rodsenra20:02:00

Hi, I am trying to use DynamoDB (dockerized local) with com.cognitect.aws/api. I am struggling to override the endpoint to match the local one. I am doing this:

(def db (aws/client {:api :dynamodb :endpoint-override "local" }))
(aws/invoke db {:op :ListTables})
But I get:
=> #:cognitect.anomalies{:category :cognitect.anomalies/not-found, :message "local"}
(meta *1)
=>
{:http-request {:request-method :post,
                :scheme :https,
                :server-port 443,
                :uri "/",
                :headers {"x-amz-date" "20190225T205047Z",
                          "x-amz-target" "DynamoDB_20120810.ListTables",
                          "content-type" "application/x-amz-json-1.0",
                          "host" "local",
                          "authorization" "AWS4-HMAC-SHA256 Credential=AKIAIEJE6SPXIMLB7VRA/20190225/us-east-1/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=2099f67eb5a11b49446bf3cbcf89202d94f3d0cf9973d1d6f5c37e85db202e63"},
                :body "{}",
                :server-name "local"},
 :http-response {:cognitect.anomalies/category :cognitect.anomalies/not-found,
                 :cognitect.anomalies/message "local",
                 :body nil}}

noisesmith20:02:30

is "local" a placeholder here? I'd expect at least a valid name like "localhost" otherwise

noisesmith20:02:55

and the credential pointing to something on us-east-1 is suspicious

rodsenra21:02:10

"dynamodb" : {
        "defaults" : {
          "protocols" : [ "http", "https" ]
        },
        "endpoints" : {
          "local" : {
            "credentialScope" : {
              "region" : "us-east-1"
            },
            "hostname" : "localhost:8000",
            "protocols" : [ "http" ]
          },

alexmiller21:02:36

I believe this is a known issue