Back
slurp (clj)
(source)function
(slurp f & opts)
Opens a reader on f and reads all its contents, returning a string.
See clojure.java.io/reader for a complete list of supported arguments.
Examples
cognitect-labs/aws-api
(ns s3-examples
(:require [clojure.core.async :as a]
[clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[clojure.java.io :as io]
[clojure.repl :as repl]
[cognitect.aws.client.api :as aws]))
;; check it!
(slurp (:Body *1))
PrecursorApp/precursor
(ns pc.http.routes.api
(:require [cemerick.url :as url]
[cheshire.core :as json]
[clojure.core.memoize :as memo]
[clojure.string :as str]
[clojure.tools.reader.edn :as edn]
[crypto.equality :as crypto]
[defpage.core :as defpage :refer (defpage)]
[pc.auth :as auth]
[pc.crm :as crm]
[pc.datomic :as pcd]
[pc.early-access]
[pc.http.doc :as doc-http]
[pc.http.team :as team-http]
[pc.http.handlers.custom-domain :as custom-domain]
[pc.models.chat-bot :as chat-bot-model]
[pc.models.doc :as doc-model]
[pc.models.flag :as flag-model]
[pc.models.team :as team-model]
[pc.profile :as profile]
[ring.middleware.anti-forgery :as csrf]
[slingshot.slingshot :refer (try+ throw+)]))
(defpage new [:post "/api/v1/document/new"] [req]
(let [params (some-> req :body slurp edn/read-string)
read-only? (:read-only params)
doc-name (:document/name params)]
(if-not (:subdomain req)
(let [cust-uuid (get-in req [:auth :cust :cust/uuid])
intro-layers? (:intro-layers? params)
doc (doc-model/create-public-doc!
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when cust-uuid {:document/creator cust-uuid})
(when read-only? {:document/privacy :document.privacy/read-only})
(when doc-name {:document/name doc-name})))]
(when intro-layers?
(doc-http/add-intro-layers doc))
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
(if (and (:team req)
(auth/logged-in? req)
(auth/has-team-permission? (pcd/default-db) (:team req) (:auth req) :admin))
(let [doc (doc-model/create-team-doc!
(:team req)
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when-let [cust-uuid (get-in req [:cust :cust/uuid])]
{:document/creator cust-uuid})
(when read-only?
{:document/privacy :document.privacy/read-only})
(when doc-name
{:document/name doc-name})))]
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
{:status 400 :body (pr-str {:error :unauthorized-to-team
:redirect-url (str (url/map->URL {:host (profile/hostname)
:protocol (if (profile/force-ssl?)
"https"
(name (:scheme req)))
:port (if (profile/force-ssl?)
(profile/https-port)
(profile/http-port))
:path "/new"
:query (:query-string req)}))
:msg "You're unauthorized to make documents in this subdomain. Please request access."})}))))
(defpage create-team [:post "/api/v1/create-team"] [req]
(let [params (some-> req :body slurp edn/read-string)
subdomain (some-> params :subdomain str/lower-case str/trim)
coupon-code (some-> params :coupon-code)
cust (get-in req [:auth :cust])]
(cond (empty? cust)
{:status 400 :body (pr-str {:error :not-logged-in
:msg "You must log in first."})}
(defpage early-access [:post "/api/v1/early-access"] [req]
(if-let [cust (get-in req [:auth :cust])]
(do
(pc.early-access/create-request cust (edn/read-string (slurp (:body req))))
(pc.early-access/approve-request cust)
{:status 200 :body (pr-str {:msg "Thanks!" :access-request-granted? true})})
{:status 401 :body (pr-str {:error :not-logged-in
:msg "Please log in to request early access."})}))
cloojure/tupelo
; Copyright (c) Alan Thompson. All rights reserved.
; The use and distribution terms for this software are covered by the Eclipse Public License 1.0
; (http://opensource.org/licenses/eclipse-1.0.php) which can be found in the file epl-v10.html at
; the root of this distribution. By using this software in any fashion, you are agreeing to be
; bound by the terms of this license. You must not remove this notice, or any other, from this
; software.
(ns tst.tupelo.string
(:refer-clojure :exclude [take drop])
;---------------------------------------------------------------------------------------------------
; https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html
; http://blog.fikesfarm.com/posts/2015-12-18-clojurescript-macro-tower-and-loop.html
#?(:cljs (:require-macros [tupelo.test]))
(:require
[clojure.test] ; sometimes this is required - not sure why
[clojure.core :as cc]
[tupelo.core :as t :refer [spy spyx spyxx spyx-pretty forv]]
[tupelo.chars :as char]
[tupelo.string :as str]
[tupelo.test :refer [testing is verify verify-focus
is isnt is= isnt= is-set= is-nonblank= is-nonblank-lines=
throws? throws-not?
]]
))
(is= "abc" (slurp (str/string->stream "abc"))))
FundingCircle/jackdaw
(ns jackdaw.serdes.avro.integration-test
(:require [clj-uuid :as uuid]
[clojure.core.cache :as cache]
[clojure.java.io :as io]
[clojure.test :refer [deftest is testing]]
[jackdaw.client :as jc]
[jackdaw.client.log :as jcl]
[jackdaw.data :as jd]
[jackdaw.serdes.avro :as avro]
[jackdaw.serdes.avro.schema-registry :as reg]
[jackdaw.test.fixtures :as fix])
(:import [org.apache.kafka.common.serialization Serde Serdes]))
(def +topic-config+
{:key? false
:avro/schema (slurp (io/resource "resources/example_schema.avsc"))})
(def +test-schema-v1+ (slurp (io/resource "foo-1.avsc")))
(def +test-schema-v2+ (slurp (io/resource "foo-2.avsc")))
(def +test-schema-v3+ (slurp (io/resource "foo-3.avsc")))
findmyway/plotly-clj
;; @@
(ns scatter
(:require [clojure.core.matrix :as m]
[clojure.core.matrix.dataset :as d]
[clojure.core.matrix.random :as rnd]
[clojure.data.csv :as csv])
(:use [plotly-clj.core] :reload-all))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
;; @@
(def data
(let [in-file (slurp "https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv")
data (doall (csv/read-csv in-file))]
(m/emap #(Float/parseFloat %) (d/dataset (rest data)))
))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#'scatter/data</span>","value":"#'scatter/data"}
;; <=