Back
file (clj)
(source)function
(file arg)
(file parent child)
(file parent child & more)
Returns a java.io.File, passing each arg to as-file. Multiple-arg
versions treat the first argument as parent and subsequent args as
children relative to the parent.
Examples
jepsen-io/jepsen
(ns jepsen.report
"Prints out stuff."
(:require [jepsen.util :as util]
[clojure.java.io :as io]
[clojure.pprint :refer [pprint]]))
(defmacro to
"Binds stdout to a file for the duration of body."
[filename & body]
`(let [filename# ~filename]
(io/make-parents filename#)
(with-open [w# (io/writer filename#)]
(try
(binding [*out* w#] ~@body)
(finally
(println "Report written to" filename#))))))
babashka/babashka
(require '[clojure.java.io :as io]
'[clojure.java.shell :refer [sh]]
'[clojure.string :as str])
(def version (str/trim (slurp (io/file "resources" "BABASHKA_VERSION"))))
(sh "lein" "with-profiles" "+reflection" "run")
(io/copy (io/file "resources/META-INF/native-image/babashka/babashka/reflect-config.json") (io/file (str "babashka-" version "-reflection.json")))
babashka/babashka
(import (java.net ServerSocket))
(require '[clojure.java.io :as io]
'[clojure.string :as string])
(with-open [server-socket (new ServerSocket 8080)
client-socket (.accept server-socket)]
(loop []
(let [out (io/writer (.getOutputStream client-socket))
in (io/reader (.getInputStream client-socket))
[req-line & _headers] (loop [headers []]
(let [line (.readLine in)]
(if (string/blank? line)
headers
(recur (conj headers line)))))
[_ _ path _] (re-find #"([^\s]+)\s([^\s]+)\s([^\s]+)" req-line)
f (io/file (format "./%s" path))
status (if (.exists f)
200
404)
html (fn html-fn [tag & body]
(let [attrs? (map? (first body))
attrs-str (str (when attrs?
(format " %s" (string/join " " (for [[k v] (first body)]
(format "%s=%s" (name k) (name v)))))))]
(format "<%s%s>%s</%s>"
(name tag)
attrs-str
(string/join (if attrs? (rest body) body))
(name tag))))
body (cond
(not (.exists f)) (str path " not exist")
(.isFile f) (slurp f)
(.isDirectory f) (format "<!DOCTYPE html>\n%s"
(html :html
(html :head
(html :title path))
(html :body
(html :h1 path)
(html :tt
(apply html :pre
(for [i (.list f)]
(html :div
(html
:a
{:href
(str (when (> (count path) 1) path) "/" i)} i)))))))))]
(prn path)
(.write out (format "HTTP/1.1 %s OK\r\nContent-Length: %s\r\n\r\n%s"
status
(count body)
body))
(.flush out))
(recur)))
hyperfiddle/electric
(ns dustin.y2022.file-watcher
(:require [clojure.java.io :as io]
[clojure.java.data :as j]
[clojure.datafy :refer [datafy]]
[leo.file-watcher :refer [watch-dir
read-edn-forms
watch-file
path]]
[hyperfiddle.rcf :as rcf :refer [tests % tap]]
[missionary.core :as m]))
(comment
(slurp (io/file "deps.edn"))
(slurp (io/file "scratch/dustin/y2022/file_watcher.clj"))
(def cancel
((m/reactor
(m/stream!
(m/ap
(let [x (m/?< (watch-dir (path "./")))]
#_(reset! !x x)
(println (str x)))))
(m/stream! (m/ap (println (m/?< (watch-file (io/file "bro.edn")))))))
prn prn))
(cancel)
(def it ((watch-file (io/file "scratch/dustin/y2022/file_watcher.clj"))
#(prn :ready) #(prn :done)))
@it
(it)
cljsjs/packages
(require '[cljsjs.boot-cljsjs.packaging :refer :all]
'[boot.core :as boot]
'[boot.tmpdir :as tmpd]
'[clojure.java.io :as io]
'[boot.util :refer [sh]])
(deftask build-msgpack-lite []
(let [tmp (boot/tmp-dir!)]
(with-pre-wrap
fileset
;; Copy all files in fileset to temp directory
(doseq [f (->> fileset boot/input-files)
:let [target (io/file tmp (tmpd/path f))]]
(io/make-parents target)
(io/copy (tmpd/file f) target))
(binding [boot.util/*sh-dir* (str (io/file tmp (format "msgpack-lite-%s" +lib-version+)))]
(dosh "npm" "install")
(dosh "./node_modules/.bin/browserify" "--debug" "--standalone" "msgpack" "./lib/browser.js" "--outfile" "./dist/msgpack.browserify.js"))
(-> fileset (boot/add-resource tmp) boot/commit!))))