Fork me on GitHub
#babashka
<
2021-11-01
>
Karol Wójcik07:11:42

Thanks @borkdude. Works like a charm:

(defn hl:update-bb-tasks
  "     \033[0;31m>\033[0m Update \033[0;31m:sha\033[0m of \033[0;31mio.github.FieryCod/holy-lambda-babashka-tasks\033[0m to latest stable version"
  []
  (print-task "hl:update-bb-tasks")
  (let [new-version (new-available-tasks-version)]
    (if (= new-version TASKS_VERSION_SHA)
      (hpr "You're using the latest tasks :sha. No update necessary!")
      (do
        (hpr "Updating from tasks version:" (accent TASKS_VERSION_SHA) "to:" (accent (new-available-tasks-version)))
        (let [edn (r/parse-string BB_EDN_STRING)]
          (spit "bb.edn" (r/update-in edn [:deps 'io.github.FieryCod/holy-lambda-babashka-tasks]
                                      (fn [x]
                                        (if-not (:sha (r/sexpr x))
                                          x
                                          (assoc (r/sexpr x) :sha new-version))))))))))

Karol Wójcik12:11:36

I need IPersistentList type in babashka: @borkdude

Karol Wójcik12:11:02

Btw do you think I can use clojure.lang.PersistenList in this example instead:

(extend-protocol RingResponseBody
  ByteArrayInputStream
  (to-hl-response-body [^ByteArrayInputStream body]
    {:body     (new String ^bytes (.encode ^Base64$Encoder @base64-encoder (.readAllBytes body)))
     :encoded? true})

  InputStream
  (to-hl-response-body [^InputStream body]
    {:body     (new String ^bytes (.encode ^Base64$Encoder @base64-encoder (.readAllBytes body)))
     :encoded? true})

  File
  (to-hl-response-body [^File body]
    {:body     (new String ^bytes (.encode ^Base64$Encoder @base64-encoder ^bytes (Files/readAllBytes (.toPath body))))
     :encoded? true})

  String
  (to-hl-response-body [^String body]
    {:body     body
     :encoded? false})

  URL
  (to-hl-response-body [^URL body]
    {:body     (new String ^bytes (.encode ^Base64$Encoder @base64-encoder ^bytes (.readAllBytes (.getInputStream (.openConnection body)))))
     :encoded? true})

  IPersistentSet
  (to-hl-response-body [^IPersistentSet body]
    {:body     body
     :encoded? false})

  PersistentVector
  (to-hl-response-body [^PersistentVector body]
    {:body     body
     :encoded? false})

  IPersistentMap
  (to-hl-response-body [^IPersistentMap body]
    {:body     body
     :encoded? false})

  IPersistentList
  (to-hl-response-body [^IPersistentList body]
    {:body     body
     :encoded? false})

  ISeq
  (to-hl-response-body [^ISeq body]
    {:body     (s/join "\n" (map str body))
     :encoded? false})

  Object
  (to-hl-response-body [^Object body]
    {:body     (str body)
     :encoded? false})

  nil
  (to-hl-response-body [_]
    {:body     nil
     :encoded? false}))

borkdude12:11:20

or maybe IPersistentCollection since that is a super interface?

Karol Wójcik12:11:07

Yeah. That way I would not need to specify PersistentVector Set etc 😄

Karol Wójcik13:11:40

Thx for the merge

borkdude13:11:34

Amazing work @eugen.stan and @imdad.ahmed!

👍 1
aw_yeah 1
agold15:11:05

Trying to install babashka with homebrew on M1 Mac yields the following error: Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)! Please create a new installation in /opt/homebrew using one of the “Alternative Installs” from: https://docs.brew.sh/Installation

borkdude15:11:56

This seems to be a policy of homebrew or mac, not much babashka can do about this I think?

Bob B16:11:35

a quick google search turns up this: <https://stackoverflow.com/questions/64963370/error-cannot-install-in-homebrew-on-arm-processor-in-intel-default-prefix-usr> - definitely a function of brew and hardware architectures

Benjamin17:11:34

how do you usually deal with file names in spaces? I have file names that I'd like to put as args to a shell/sh call

borkdude17:11:33

@benjamin.schwerdtner You can provide separate strings or quote the file name with single quotes

borkdude17:11:03

"ls" "foo bar" or "ls 'foo bar'"

partywombat 1
borkdude22:11:22

Some defrecord tweaks coming up soon. 1) The printing of a record is more like in JVM Clojure. 2) You can read the printed record back as a record using read-string like in Clojure. 3) You can override toString

$ ./bb -e "(defrecord A [x] Object (toString [this] (str :dude))) (prn (->A 1)) (println (str (->A 1)))"
#user.A{:x 1}
:dude

1
👍 5