This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- sdw_500.java 2023-04-14 17:55:38 | |
+++ sdw_523.java 2023-04-14 17:56:20 | |
@@ -32,17 +32,18 @@ | |
import java.nio.charset.StandardCharsets; | |
import java.util.Iterator; | |
+import org.apache.logging.log4j.LogManager; | |
+import org.apache.logging.log4j.Logger; | |
import org.apache.poi.ss.usermodel.Cell; | |
import org.apache.poi.ss.usermodel.CellStyle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [addr (java.net.UnixDomainSocketAddress/of "/tmp/222") | |
sc (doto (java.nio.channels.ServerSocketChannel/open java.net.StandardProtocolFamily/UNIX) | |
(.bind addr))] | |
(while true | |
(let [c (.accept sc)] | |
(future | |
(let [in (java.nio.channels.Channels/newInputStream c) | |
out (java.nio.channels.Channels/newOutputStream c)] | |
(binding [*in* (clojure.lang.LineNumberingPushbackReader. | |
(clojure.java.io/reader in)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns dev.nocommit.pprint-middleware | |
(:require [honeysql.core :as hsql] | |
[sql-honey.core :as sqlhoney] | |
[metabase.models.database :refer [Database]] | |
[clojure.string :as str]) | |
(:import org.apache.openjpa.lib.jdbc.SQLFormatter)) | |
(let [formatter (SQLFormatter.)] | |
(println | |
(.prettyPrint formatter "select * from orders"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(require '[clojure.core.server :as server]) | |
#_(peek (str/split (str *ns*) #"\.")) ; foo.bar.quux> is just displayed as quux> | |
(clojure.main/repl | |
;; keep prompts shorter | |
:prompt (fn [] (printf "%s=> " (peek (str/split (str *ns*) #"\.")))) | |
;; allow easily ending this sub repl watching for :repl/quit | |
:read server/repl-read) | |
;; fantastic reveal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; use a heap to keep only the max N (here 10) items in memory at a time. imagine reducing over a | |
;; quite large result set. don't want to realize it all, sort, and then take N. Just keep discarding | |
;; compared to our heap's min item. | |
(let [threshold 10 | |
cmp (reify java.util.Comparator | |
(compare [_ x y] | |
;; score is second so want to compare [score item] | |
(compare (vec (reverse x)) (vec (reverse y))))) | |
xf (comp (map (fn [{:keys [name]}] [name (count name)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; shadow-cljs.edn: {:dependencies [[org.clojure/test.check "1.1.0"]]} | |
;; npm i shadow-cljs | |
;; cider-jack-in-cljs | |
;; shadow | |
;; node-repl | |
foo> (require '[clojure.spec.test.alpha :as spec]) | |
nil | |
foo> (spec/check) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ‘C-x r s <register-key>’ save to register | |
;; 'C-c C-j x <register-key' to send to repl | |
(defun cider-insert-register-contents (register) | |
(interactive (list (register-read-with-preview "From register"))) | |
(let ((form (get-register register))) | |
;; could put form into a buffer and check if its parens are | |
;; balanced | |
(if form | |
(cider-insert-in-repl form (not cider-invert-insert-eval-p)) | |
(user-error "No saved form in register")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let (defcustoms) | |
(dolist (file (directory-files "/Users/dan/projects/dev/cider" t "\.el")) | |
(unless (string-match-p "dir-locals" file) | |
(with-current-buffer (find-file file) | |
(goto-char (point-min)) | |
(while (re-search-forward "defcustom" nil t) | |
(let ((custom (substring-no-properties (progn (paredit-forward 1) | |
(thing-at-point 'sexp)))) | |
(docstring (substring-no-properties (progn (paredit-forward 2) | |
(or (thing-at-point 'sexp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; thanks ghadi from #clojure.beginners | |
(defn into-str | |
"reduce coll into a String, given a transducer" | |
[xf coll] | |
(transduce (comp xf (map str)) | |
(fn | |
([] (StringBuilder.)) | |
([^StringBuilder sb] (.toString sb)) | |
([^StringBuilder sb s] (.append sb ^String s))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(reify FileVisitor | |
(visitFile [_ p attrs] | |
(let [f (.relativize src p) | |
last-mod (Files/getLastModifiedTime p (make-array LinkOption 0))] | |
(when *verbose* (println (str (.toString src) "/" (.toString f)))) | |
(with-open [is (Files/newInputStream p (make-array OpenOption 0))] | |
(copy! (.toString f) is (.resolve dest (.toString f)) last-mod))) | |
FileVisitResult/CONTINUE) | |
(preVisitDirectory [_ p attrs] | |
(Files/createDirectories (.resolve dest (.toString (.relativize src p))) |
NewerOlder