Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,13 @@
(require '[clojure.java.io :as jio]
'[clojure.string :as str])
(defn remove-lines1 [filepath start nskip]
(let [lines (str/split-lines (slurp filepath))
new-lines (concat (take (dec start) lines)
(drop (+ (dec start) nskip) lines))
diff (- (count lines) (count new-lines))]
(when-not (zero? diff)
(println "WARN: You are trying to remove lines beyond EOF"))
(with-open [wrt (jio/writer (str filepath ".tmp"))]
(.write wrt (str/join "\n" new-lines)))
(.renameTo (jio/file (str filepath ".tmp")) (jio/file filepath))))

View file

@ -0,0 +1,17 @@
(require '[clojure.java.io :as jio]
'[clojure.string :as str])
(defn remove-lines2 [filepath start nskip]
(with-open [rdr (jio/reader filepath)]
(with-open [wrt (jio/writer (str filepath ".tmp"))]
(loop [s start n nskip]
(if-let [line (.readLine rdr)]
(cond
(> s 1) (do (doto wrt (.write line) (.newLine))
(recur (dec s) n))
(pos? n) (recur s (dec n))
:else (do (doto wrt (.write line) (.newLine))
(recur s n)))
(when (pos? n)
(println "WARN: You are trying to remove lines beyond EOF"))))))
(.renameTo (jio/file (str filepath ".tmp")) (jio/file filepath)))