Skip to content

Instantly share code, notes, and snippets.

(let [workers nil]
(defn monitor-and-pyramid [src dest steps]
(if (empty? @workers)
(let [monitor (monitor-and-pyramid src dest)
pyramid (make-image-pyramid dest steps)]
(set! workers (list monitor pyramid))
(doseq [w workers] (.execute w)))
(do (doseq [w workers] (.cancel w true))
(set! workers nil)))))
(let [workers (ref [])]
(defn monitor-and-pyramid [src dest steps]
(if (empty? @workers)
(let [monitor (monitor-directory src dest)
pyramid (make-image-pyramid dest steps)]
(dosync (doseq [w [monitor pyramid]] (.execute w))
(ref-set workers [monitor pyramid])))
(dosync (doseq [w @workers] (.cancel w true))
(println "Cancelled")
(ref-set workers [])))))
(defn thumbnail-info [dir i]
(let [thumbs (.listFiles dir (with-suffix i))]
(when-not (empty? thumbs)
(let [image (IJ/openImage (.getAbsolutePath (first thumbs)))]
{:width (.getWidth image)
:height (.getHeight image)}))))
int count;
byte [] data = new byte [DATA_BLOCK_SIZE];
while ((count = input.read (data, 0, DATA_BLOCK_SIZE)) != -1) {
output.write (data, 0, count);
}
(defn write [name data]
(let [buf (make-array Byte/TYPE 1024)
dest (FileOutputStream. name)]
(with-open [r (BufferedInputStream. data)
w (BufferedOutputStream. dest)]
(loop [bytes (.read r buf 0 1024)]
(when-not (= bytes -1)
(.write w buf)
(recur (.read r buf 0 1024)))))
(println "Wrote" name)))
(defn calculate-offset [value file s r c]
(println "Calculating offset for" (.getName file) "at" [s r c])
(condp #(%1 %2)
(or (neg? s) (neg? r) (neg? c)) [-1 -1]
(tile-exists? s r c) :>> #(really-calculate-offset file (:file %))
(do (Thread/sleep 60000)
(recur value file s r c))))
(defn calculate-offset [value file s r c]
(println "Calculating offset for" (.getName file) "at" [s r c])
(if-let [tile (get-tile s r c)]
(really-calculate-offset file (:file tile))
(do (Thread/sleep 60000)
(recur value file s r c))))
(defn make-offset [file sec row col]
(let [->offset #(calculate-offset %1 file sec %2 %3)
row-1 (dec row) row+1 (inc row)
(defn calculate-offset [value file section row column direction]
(let [tile (get-tile section row column)]
(cond
(out-of-bounds? row column) [-1 -1]
(not (false? tile)) (really-calculate-offset file (:file tile) direction)
:else
(do (Thread/sleep 60000)
(recur value file section row column direction)))))
(defn make-agent [section row column action direction]
(defn find-edge [image cx cy]
(let [width (.getWidth image)
height (.getHeight image)
ip (-> image .getProcessor .duplicate)]
(.findEdges ip)
(doall
(for [x (range width)
y (range height)
:let [value (.get ip x y)]
:when (not (zero? value))]
//find PK column
List<String> pkColList = new ArrayList<String>();
DatabaseMetaData dbMetaData = con.getMetaData();
ResultSet pkRs = dbMetaData.getPrimaryKeys(null, schema, table);
while(pkRs.next()) {
pkColList.add(pkRs.getString(4));
}
pkRs.close();
if (pkColList.size() != 1) {
throw new InvalidTableException("Table " + schema + "." + table + " has " + pkColList.size() + " PK columns - only allowed 1");