Mercurial > lasercutter
changeset 2:5ed873917c34
enabled display
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 20 Aug 2010 00:39:50 -0400 |
parents | 6d9bdaf919f7 |
children | e6254010c95a |
files | src/clojureDemo/librlm.clj~ src/clojureDemo/project-euler.clj~ src/clojureDemo/project_euler.clj~ src/clojureDemo/rlm.clj~ src/clojureDemo/sys-utils.clj~ src/clojureDemo/sys_utils.clj~ src/laser/.#rasterize.clj src/laser/rasterize.clj |
diffstat | 8 files changed, 32 insertions(+), 767 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/src/clojureDemo/librlm.clj~ Fri Aug 20 00:32:44 2010 -0400 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,11 +0,0 @@ 1.4 -(ns clojureDemo.librlm) 1.5 - 1.6 -; (defmethod* - java.lang.Boolean [x] (not x)) 1.7 - 1.8 -; (defmethod + [java.lang.Boolean java.lang.Boolean] 1.9 -; [a b] (or a b)) 1.10 - 1.11 -; (defmethod * [java.lang.Boolean java.lang.Boolean] 1.12 -; [a b] (and a b)) 1.13 - 1.14 -; (defmethod / java.lang.Boolean [x] x)
2.1 --- a/src/clojureDemo/project-euler.clj~ Fri Aug 20 00:32:44 2010 -0400 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,16 +0,0 @@ 2.4 - 2.5 - 2.6 -(ns clojureDemo.project-euler) 2.7 - 2.8 - 2.9 -(use 'clojureDemo.rlm) 2.10 -(rlm-base-load) 2.11 - 2.12 -(defn range-sum 2.13 -"calculates the sum of a range. Takes the exact same arguments 2.14 - as clojure.core/range" 2.15 -([end] 2.16 - (/ (* end (- end 1) ) 2))) 2.17 - 2.18 - 2.19 -
3.1 --- a/src/clojureDemo/project_euler.clj~ Fri Aug 20 00:32:44 2010 -0400 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,559 +0,0 @@ 3.4 - 3.5 -(ns clojureDemo.project-euler 3.6 - 3.7 -(:refer-clojure :exclude [+ - / * 3.8 - assoc conj dissoc empty get into seq 3.9 - = < > <= >= zero? 3.10 - ]) 3.11 - 3.12 -(:use [clojure.contrib.generic 3.13 - arithmetic 3.14 - collection 3.15 - comparison 3.16 - ]) 3.17 - 3.18 -(:use [clojure.contrib 3.19 - combinatorics 3.20 - repl-utils 3.21 - def 3.22 - duck-streams 3.23 - shell-out 3.24 - import-static 3.25 - lazy-seqs 3.26 - logging 3.27 - map-utils 3.28 - math 3.29 - mock 3.30 - monads 3.31 - ns-utils 3.32 - seq-utils 3.33 - function-utils 3.34 - profile 3.35 - str-utils 3.36 - ]) 3.37 - 3.38 -(:use [clojure.contrib.pprint :exclude [write]]) 3.39 - 3.40 -(:use [clojure.contrib.pprint.examples 3.41 - hexdump 3.42 - json 3.43 - multiply 3.44 - props 3.45 - show-doc 3.46 - xml 3.47 - ]) 3.48 - 3.49 -(:import java.io.File) 3.50 -(:import [java.util Calendar Date]) 3.51 - 3.52 -) 3.53 - 3.54 - 3.55 - 3.56 - 3.57 - 3.58 -(defn range-sum 3.59 - "calculates the sum of a range. Takes the exact same arguments 3.60 - as clojure.core/range equilivent to (reduce + (range start end step)), but O(1)." 3.61 - ([end] 3.62 - (/ (* end (- end 1) ) 2)) 3.63 - 3.64 - ([start end] 3.65 - (- (range-sum end) (range-sum start))) 3.66 - 3.67 - ([start end step] 3.68 - (letfn [(zero-sum [end step] (* step (range-sum 0 (ceil (/ end step)))))] 3.69 - (+ (zero-sum (- end start) step) (* start (int (/ (- end start) step))))))) 3.70 - 3.71 - 3.72 - 3.73 -(defn range-sum-squares 3.74 - "equivalent to (reduce + (map #(expt % 2) (range start end step))), 3.75 - but runs in O(1) time." 3.76 - ([end] 3.77 - (let [n (- end 1)] 3.78 - (- (* (expt n 3) 1/3) ;continous volume 3.79 - (+ (* -1/6 n) (* -1/2 (expt n 2)))))) ;discrete correction 3.80 - 3.81 - ([start end] 3.82 - (- (range-sum-squares end) (range-sum-squares start))) 3.83 - 3.84 - ([start end step] 3.85 - ;; (letfn [(zero-sum-squares [end step] 3.86 - ;; (* step step (range-sum-squares 0 (ceil (/ end step)))))] 3.87 - ;; (+ 3.88 - ;; (* 2 step (range-sum (ceil (/ (- end start) step)))) 3.89 - ;; (zero-sum end step) 3.90 - ;; (* start start (int (/ (- end start) step))))))) 3.91 -)) 3.92 - 3.93 - 3.94 -(defn prime-factors 3.95 - "all the prime factors of the number n" 3.96 - [n] 3.97 - (filter #(= 0 (rem n %)) (for [p primes :while (<= p n)] p))) 3.98 - 3.99 -(defn factor? [a b] (= 0 (rem a b))) 3.100 - 3.101 -(defn factor-map [a b] 3.102 - (if (factor? a b) 3.103 - {b (quot a b)} 3.104 - nil)) 3.105 - 3.106 - 3.107 -(defn divides? [numerator divisor] (= (rem numerator divisor) 0)) 3.108 - 3.109 - 3.110 -(def != (comp not =)) 3.111 - 3.112 - 3.113 -(defn decompose [number factor] 3.114 - (loop [n number counter 0] 3.115 - (if (!= (rem n factor) 0) 3.116 - counter 3.117 - (recur (/ n factor) (inc counter))))) 3.118 - 3.119 - 3.120 - 3.121 - 3.122 - 3.123 - 3.124 - 3.125 -(defn single-factor [{num :current-num index :prime-index factors :prime-factors :as old-state}] 3.126 - (let [divisor (nth primes index) 3.127 - new-index (inc index) 3.128 - done? (= num 1)] 3.129 - (if (divides? num divisor) 3.130 - (let [new-num (/ num (expt divisor (decompose num divisor))) 3.131 - factors (assoc factors divisor (decompose num divisor))] 3.132 - [[factors done?] (assoc old-state 3.133 - :current-num new-num :prime-index new-index :prime-factors factors)]) 3.134 - 3.135 - [[factors done?] (assoc old-state 3.136 - :current-num num :prime-index new-index :prime-factors factors)]))) 3.137 - 3.138 - 3.139 -(defn wtf "a is not used" [a] (domonad state-m [part single-factor] part)) 3.140 - 3.141 -(defn fuck-it [] 3.142 - (domonad state-m 3.143 - [[factors done?] 3.144 - (state-m-until second wtf nil)] 3.145 - 3.146 - factors)) 3.147 - 3.148 -(defn prime-factor-map [num] 3.149 - 3.150 - (first ((fuck-it) {:prime-factors {} 3.151 - :prime-index 0 3.152 - :current-num num}))) 3.153 - 3.154 -(defn prime-factors-monad [num] 3.155 - (sort (keys (prime-factor-map num)))) 3.156 - 3.157 - 3.158 - 3.159 - 3.160 - 3.161 - 3.162 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3.163 -;; fun with state monad 3.164 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3.165 - 3.166 - 3.167 -(defn ++ [{num :num :as world}] 3.168 - (let [num++ (inc num)] 3.169 - [num++ (assoc world :num num++)])) 3.170 - 3.171 -(defn huh? [] 3.172 - (with-monad state-m 3.173 - (domonad [x ++ 3.174 - y ++] 3.175 - y))) 3.176 - 3.177 - 3.178 -(comment 3.179 - 3.180 -huh? 3.181 --> 3.182 -((let [m-bind (fn m-bind-state [mv f] 3.183 - (fn [s] 3.184 - (let [[v ss] (mv s)] 3.185 - ((f v) ss))))] 3.186 - (m-bind 3.187 - ++ (fn [x] ++))) {:num 1}) 3.188 - 3.189 - 3.190 -) 3.191 - 3.192 - 3.193 -(defn wordify [n] (cl-format nil "~R" n)) 3.194 - 3.195 -(defn british-letter-count-prof [n] 3.196 - (prof :total 3.197 - (let [and? (prof :rem-test (if (and (> n 99) (!= 0 (rem n 100))) 3 0)) 3.198 - word (prof :wordify (wordify n)) 3.199 - word-seq (prof :sequence (seq word)) 3.200 - word-filter (prof :filter (filter #(Character/isLetter %) word-seq)) 3.201 - word-count (prof :count (count word-filter)) 3.202 - answer (prof :add (+ and? word-count))] 3.203 - answer))) 3.204 - 3.205 -(defn british-letter-count-prof2 3.206 -"now this is faster, because it uses string manipulation. go profiling!" 3.207 -[n] 3.208 - (prof :total 3.209 - (let [and? (prof :rem-test (if (and (> n 99) (!= 0 (rem n 100))) 3 0)) 3.210 - word (prof :wordify (wordify n)) 3.211 - word-regex (prof :regex (re-gsub #"[\W-,]" "" word)) 3.212 - 3.213 - word-count (prof :count (.length word-regex)) 3.214 - answer (prof :add (+ and? word-count))] 3.215 - answer))) 3.216 - 3.217 - 3.218 - 3.219 - 3.220 - 3.221 - 3.222 - 3.223 - 3.224 - 3.225 - 3.226 - 3.227 - 3.228 - 3.229 - 3.230 - 3.231 - 3.232 - 3.233 - 3.234 - 3.235 -;pseudo code for primes 3.236 - 3.237 -;fn prime-decomposition 3.238 -; [n] 3.239 -; map = {} 3.240 -; 3.241 -; for x in primes 3.242 -; add to map (divide teh fick out n x) 3.243 -; n = n / prime-factors 3.244 -; if n == 1 BREAK; 3.245 -; 3.246 -; 3.247 - 3.248 - 3.249 - 3.250 -(defn rng [seed] 3.251 - (let [m 259200 3.252 - value (/ (float seed) (float m)) 3.253 - next (rem (+ 54773 (* 7141 seed)) m)] 3.254 - [value next])) 3.255 - 3.256 - 3.257 -(defn yeah! [] 3.258 - (let [name sequence-m 3.259 - m-bind (:m-bind name) 3.260 - m-result (:m-result name) 3.261 - m-zero (:m-zero name) 3.262 - m-plus (:m-plus name)] 3.263 - 3.264 - 3.265 - (m-bind (range 5) (fn [a] (m-bind [2 3] (fn [b] (m-result (+ a b)))))))) 3.266 - 3.267 - 3.268 -(defn ohhhh!! [] 3.269 - 3.270 - (let 3.271 - [name state-m 3.272 - m-bind (:m-bind name) 3.273 - m-result (:m-result name) ] 3.274 - 3.275 - (m-bind rng (fn [x1] (m-bind rng (fn [x2] (m-result (+ x1 x2)))))))) 3.276 - 3.277 - 3.278 - 3.279 -(defmulti palindrome? class) 3.280 - 3.281 -(defmethod palindrome? (class "string") [a] 3.282 - (= (seq a) (reverse a))) 3.283 - 3.284 -(defmethod palindrome? (class 500) [a] 3.285 - (palindrome? (str a))) 3.286 - 3.287 - 3.288 - 3.289 - 3.290 - 3.291 - 3.292 - 3.293 - 3.294 -(defn circulars 3.295 - "returns a vector of all the circular permutations of a number" 3.296 - [n] 3.297 - (map #(Integer. (apply str %)) (rotations (seq (str n))))) 3.298 - 3.299 - 3.300 -(defn prime-factors 3.301 - [n] 3.302 - (for [a primes :while (<= a n) :when (= (rem n a) 0)] a)) 3.303 - 3.304 - 3.305 -(defmethod = [nil java.lang.Integer] [ a b ] 3.306 - false) 3.307 - 3.308 - 3.309 - 3.310 -(def mil 1000000) 3.311 -(def bil 1000000000) 3.312 - 3.313 -(defn primes-under-million [] (apply hash-set (take 78498 primes))) 3.314 -(def primes-under-million (memoize primes-under-million)) 3.315 - 3.316 - 3.317 -(defn primes-under-billion [] (apply hash-set (take 664579 primes))) 3.318 -(def primes-under-billion (memoize primes-under-billion)) 3.319 - 3.320 - 3.321 - 3.322 - 3.323 - 3.324 -(defn prime? [n] (not (nil? (get (primes-under-billion) n)))) 3.325 - 3.326 - 3.327 -(defn circular-memoize 3.328 - "assumes that f is a predicate that takes in a number for which, 3.329 - if the predicate is true for the number, it is also true for all 3.330 - of the circular permutations of the number. Memoizes the result 3.331 - for all circular permutations so as to avoid subsequent computation." 3.332 - [f] 3.333 - (let [mem (atom {})] 3.334 - (fn [n] 3.335 - (if-let [e (find @mem n)] 3.336 - (val e) 3.337 - (let [ret (f n)] 3.338 - (dorun (for [circ (circulars n)] 3.339 - (swap! mem assoc n ret))) 3.340 - ret))))) 3.341 - 3.342 -(defn circularly-prime? 3.343 - [n] 3.344 - (not (some (comp not prime?) (circulars n)))) 3.345 - 3.346 -(def circularly-prime? (memoize circularly-prime?)) 3.347 - 3.348 - 3.349 -(defmethod = :default [& args] 3.350 - (apply clojure.core/= args)) 3.351 - 3.352 -(def logins 3.353 - (map str 3.354 - [319 680 180 690 129 620 762 689 762 318 3.355 - 368 710 720 710 629 168 160 689 716 731 3.356 - 736 729 316 729 729 710 769 290 719 680 3.357 - 318 389 162 289 162 718 729 319 790 680 3.358 - 890 362 319 760 316 729 380 319 728 716])) 3.359 - 3.360 -(defn remove-multiples [n] 3.361 - (reduce (fn [a b] (if (= (last a) b) a (conj a b))) [] n)) 3.362 - 3.363 -(defn insert [item n vect] 3.364 - (let [split (split-at n vect)] 3.365 - (apply vector (flatten [(first split) item (last split)])))) 3.366 - 3.367 -(defn expand-code [old-code [c b a]] 3.368 - (let [main-length (count old-code)] 3.369 - (for [x (range (inc main-length)) y (range (inc x)) z (range (inc y))] 3.370 - (insert c z (insert b y (insert a x old-code)))))) 3.371 - 3.372 -(defn domain-expand-contract [old-domain constraint] 3.373 - (let [new-domain 3.374 - (map remove-multiples 3.375 - (remove-multiples 3.376 - (sort 3.377 - (apply concat 3.378 - (map #(expand-code % constraint) old-domain))))) 3.379 - min-code-length (apply min (map count new-domain)) ] 3.380 - (map #(apply str %) (filter #(= (count %) min-code-length) new-domain)))) 3.381 -(def domain-expand-contract (memoize domain-expand-contract)) 3.382 - 3.383 - 3.384 - 3.385 -(defn lazy-fibo 3.386 - ([] (concat [0 1] (lazy-fibo 0 1))) 3.387 - ([a b] (let [n (+ a b)] (lazy-seq (cons n (lazy-fibo b n)))))) 3.388 - 3.389 - 3.390 -(defn collatz-seq [n] 3.391 - (lazy-seq 3.392 - (cond (= n 1) [1] 3.393 - (even? n) (lazy-seq (cons n (collatz-seq (/ n 2)))) 3.394 - (odd? n) (lazy-seq (cons n (collatz-seq (+ 1 (* 3 n)))))))) 3.395 -(def collatz-seq (memoize collatz-seq)) 3.396 - 3.397 - 3.398 - 3.399 -(defn pythagorean-triple? [a b c] 3.400 - (let [[a b c] (sort [a b c])] 3.401 - (= (+ (* a a) (* b b) ) (* c c)))) 3.402 - 3.403 - 3.404 -(defn sum-squares [coll] 3.405 - (reduce + (map #(* % %) coll))) 3.406 - 3.407 - 3.408 -(defn british-letter-count [n] 3.409 - 3.410 - (let [and? (if (and (> n 99) (!= 0 (rem n 100))) 3 0)] 3.411 - 3.412 - (+ and? (count (filter #(Character/isLetter %) (seq (wordify n))))))) 3.413 - 3.414 - 3.415 - 3.416 -(defmacro apply-macro 3.417 - "This is evil. Don't ever use it. It makes a macro behave like a 3.418 - function. Seriously, how messed up is that? 3.419 - 3.420 - Evaluates all args, then uses them as arguments to the macro as with 3.421 - apply. 3.422 - 3.423 - (def things [true true false]) 3.424 - (apply-macro and things) 3.425 - ;; Expands to: (and true true false)" 3.426 - [macro & args] 3.427 - (cons macro (flatten (map eval args)))) 3.428 - 3.429 -(defn fun1 [] (Thread/sleep 5000) 5) 3.430 - 3.431 -(defn fun2 [] (Thread/sleep 30000) 5) 3.432 - 3.433 - 3.434 -(def naturals (iterate inc 0)) 3.435 - 3.436 - 3.437 - 3.438 - 3.439 -(defn race [] 3.440 - (let [result (ref nil) 3.441 - threads [(Thread. (fn [] (try 3.442 - (let [answer (fun1)] 3.443 - (dosync (ref-set result answer))) 3.444 - (catch Exception _ nil)))) 3.445 - (Thread. (fn [] (try 3.446 - (let [answer (fun2)] 3.447 - (dosync (ref-set result answer))) 3.448 - (catch Exception _ nil))))]] 3.449 - 3.450 - (dorun (map #(.start %) threads)) 3.451 - (loop [] 3.452 - (if (!= (deref result) nil) 3.453 - (do (dorun (map #(.stop %) threads)) 3.454 - (deref result)) 3.455 - (recur))))) 3.456 - 3.457 - 3.458 - 3.459 - 3.460 - 3.461 - 3.462 - 3.463 -(defn make-date [year month day] (do (let [date (Calendar/getInstance)] (.set date year month day 0 0) date))) 3.464 - 3.465 -(def jan-1-1901 (make-date 1900 0 1)) 3.466 - 3.467 -(defn sunday? [#^java.util.Calendar date] (= 7 (.getDay (.getTime date)))) 3.468 - 3.469 - 3.470 - 3.471 - 3.472 - 3.473 - 3.474 -(comment 3.475 - 3.476 -;; ---------------------------------------------------------------------- 3.477 -;; Answers 3.478 -;; ---------------------------------------------------------------------- 3.479 - 3.480 -; Problem 1 3.481 -(+ (range-sum 0 1001 3) (range-sum 0 1001 5) (* -1 (range-sum 0 1001 15))) 3.482 - 3.483 -; Problem 2 3.484 -(reduce + (for [a (filter even? (fibs)) :while (<= a 4000000 )] a)) 3.485 - 3.486 -; Problem 3 3.487 -(apply max (prime-factors 600851475143)) 3.488 - 3.489 -; Problem 4 3.490 -(reduce max (for [a (range 100 1000) b (range 100 1000) :when (palindrome? (* a b))] (* a b))) 3.491 - 3.492 -; Problem 5 3.493 -(reduce lcm (range 1 21)) 3.494 - 3.495 -; Problem 6 3.496 -(- (expt (range-sum 101) 2) (range-sum-squares 101)) 3.497 - 3.498 -; Problem 7 3.499 -(nth primes 10000) 3.500 - 3.501 - 3.502 -; Problem 9 3.503 -(reduce * (first (for [a (range 1 1000) b (range 1 a) c [(sqrt (sum-squares [a b]))] 3.504 - :when (= (+ a b c) 1000)] [a b c]))) 3.505 - 3.506 -; Problem 10 3.507 -(reduce + (for [a primes :while (< a 2000000)] a)) 3.508 - 3.509 - 3.510 - 3.511 - 3.512 - 3.513 -; Problem 14 3.514 -(first (reduce (fn [a b] (if (> (count a) (count b)) a b)) [] (map collatz-seq (range 1 mil)))) 3.515 - 3.516 - 3.517 -; Problem 16 3.518 -(reduce + (map #(Character/getNumericValue %) (seq (str (expt 2 1000))))) 3.519 - 3.520 -; Problem 17 3.521 -(reduce + (map british-letter-count (range 1 1001))) 3.522 - 3.523 - 3.524 -; Problem 24 3.525 -(nth (lex-permutations [ 0 1 2 3 4 5 6 7 8 9]) (- mil 1)) 3.526 - 3.527 -; Problem 33 3.528 -(reduce * (for [num (range 1 10) 3.529 - den (range 1 10) 3.530 - weird (range 1 10) 3.531 - top [(+ num (* 10 weird))] 3.532 - bottom [(+ weird (* 10 den))] 3.533 - :when (and (> (/ top bottom) 1) (= (/ top bottom) (/ num den)))] 3.534 - (/ bottom top))) 3.535 - 3.536 -; Problem 35 3.537 -(count (filter circularly-prime? (primes-under-million))) 3.538 - 3.539 -; Problem 40 3.540 -(let [fff (apply str (take 1030000 naturals))] 3.541 - (reduce * (map #(Character/getNumericValue (nth fff %)) 3.542 - (map (fn [x] (expt 10 x)) (range 7)) ))) 3.543 - 3.544 - 3.545 - 3.546 - 3.547 - 3.548 - 3.549 -; Problem 79 3.550 -(reduce domain-expand-contract [""] logins) 3.551 - 3.552 -) 3.553 - 3.554 - 3.555 - 3.556 - 3.557 - 3.558 - 3.559 - 3.560 - 3.561 - 3.562 -
4.1 --- a/src/clojureDemo/rlm.clj~ Fri Aug 20 00:32:44 2010 -0400 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,67 +0,0 @@ 4.4 -(ns clojureDemo.rlm 4.5 - 4.6 -(:refer-clojure :exclude [+ - / * 4.7 - assoc conj dissoc empty get into seq 4.8 - = < > <= >= zero? 4.9 - ]) 4.10 - 4.11 -(:use [clojure.contrib.generic 4.12 - arithmetic 4.13 - collection 4.14 - comparison 4.15 - ]) 4.16 - 4.17 -(:use [clojure.contrib 4.18 - accumulators 4.19 - combinatorics 4.20 - repl-utils 4.21 - def 4.22 - duck-streams 4.23 - shell-out 4.24 - import-static 4.25 - lazy-seqs 4.26 - logging 4.27 - map-utils 4.28 - math 4.29 - mock 4.30 - monads 4.31 - ns-utils 4.32 - ]) 4.33 - 4.34 -(:use [clojure.contrib.pprint :exclude [write]]) 4.35 - 4.36 -(:use [clojure.contrib.pprint.examples 4.37 - hexdump 4.38 - json 4.39 - multiply 4.40 - props 4.41 - show-doc 4.42 - xml 4.43 - ]) 4.44 - 4.45 -(:import java.io.File) 4.46 - 4.47 - 4.48 - 4.49 -) 4.50 - 4.51 - 4.52 - 4.53 - 4.54 - 4.55 - 4.56 - 4.57 -(defn rlm-extra-load [] 4.58 - (use :reload-all 4.59 - '[ clojureDemo 4.60 - rlm 4.61 - project-euler 4.62 - ])) 4.63 - 4.64 - 4.65 -(defn rlm-switch [] 4.66 - (in-ns 'rlm) 4.67 - (rlm-extra-load)) 4.68 - 4.69 -(defn switch-rlm [] 4.70 - (rlm-switch))
5.1 --- a/src/clojureDemo/sys-utils.clj~ Fri Aug 20 00:32:44 2010 -0400 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,49 +0,0 @@ 5.4 -(ns clojureDemo.sys-utils 5.5 - 5.6 -:use [clojure.contrib duck-streams str-utils shell-out] 5.7 -:import java.io.File 5.8 -) 5.9 - 5.10 - 5.11 - 5.12 - 5.13 -(defn escape-spaces 5.14 - [string] 5.15 - (re-gsub #" " (str \-) string)) 5.16 - 5.17 - 5.18 -(defn view 5.19 - [string] 5.20 - (seq (char-array string))) 5.21 - 5.22 -(defn parent-source [target file] 5.23 - (File. (str target "/" (.getName (.getParentFile file))"-" (.getName file)))) 5.24 - 5.25 - 5.26 -(defn rsync [file1 file2] 5.27 - (let [*out* nil] 5.28 - (sh "rsync" "-avz" (str file1) (escape-spaces(str file2))))) 5.29 - 5.30 -(defn shunt-file [target file] 5.31 - (rsync (str file) (str (parent-source target file)))) 5.32 - 5.33 - 5.34 - 5.35 -(defn extract-files 5.36 - [regex source destination] 5.37 - 5.38 - (map (partial shunt-file destination) 5.39 - (filter (comp not nil? (partial re-matches regex) str) (file-seq source)))) 5.40 - 5.41 -(defn test-extract 5.42 - [] 5.43 - ((partial extract-files #".*\.JPG" 5.44 - (file-str " /home/r/Desktop/judy_yates_computer_archive/MyDocuments/dallas townhome") 5.45 - (file-str "/home/r/Desktop/judyates_admin/archive-source-images/")))) 5.46 - 5.47 - 5.48 -(defn judy-jpg-extract 5.49 - [] 5.50 - ((partial extract-files #".*\.JPG" 5.51 - (file-str "/home/r/Desktop/judy_yates_computer_archive") 5.52 - (file-str "/home/r/Desktop/judyates_admin/archive-source-images/"))))
6.1 --- a/src/clojureDemo/sys_utils.clj~ Fri Aug 20 00:32:44 2010 -0400 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,61 +0,0 @@ 6.4 - 6.5 -(ns clojureDemo.sys-utils 6.6 - 6.7 -(:use [clojure.contrib duck-streams str-utils shell-out]) 6.8 -(:import java.io.File) 6.9 -) 6.10 - 6.11 - 6.12 - 6.13 - 6.14 -(defn escape-spaces 6.15 - [string] 6.16 - (re-gsub #" " (str \-) string)) 6.17 - 6.18 - 6.19 -(defn view 6.20 - [string] 6.21 - (seq (char-array string))) 6.22 - 6.23 -(defn parent-source [target file] 6.24 - (File. (str target "/" (.getName (.getParentFile file))"-" (.getName file)))) 6.25 - 6.26 - 6.27 -(defn rsync [file1 file2] 6.28 - (let [*out* nil] 6.29 - (sh "rsync" "-avz" (str file1) (escape-spaces(str file2))))) 6.30 - 6.31 -(defn shunt-file [target file] 6.32 - (rsync (str file) (str (parent-source target file)))) 6.33 - 6.34 - 6.35 - 6.36 -(defn extract-files 6.37 - [regex source destination] 6.38 - 6.39 - (dorun (map (partial shunt-file destination) 6.40 - (filter (comp not nil? (partial re-matches regex) str) (file-seq source))))) 6.41 - 6.42 - 6.43 -(defn file-count [#^java.io.File file] 6.44 - (count (file-seq file))) 6.45 - 6.46 - 6.47 - 6.48 - 6.49 -(comment 6.50 - 6.51 -(defn test-extract 6.52 - [] 6.53 - ((partial extract-files #".*\.JPG" 6.54 - (file-str " /home/r/Desktop/judy_yates_computer_archive/MyDocuments/dallas townhome") 6.55 - (file-str "/home/r/Desktop/judyates_admin/archive-source-images/")))) 6.56 - 6.57 - 6.58 -(defn judy-jpg-extract 6.59 - [] 6.60 - ((partial extract-files #".*\.JPG" 6.61 - (file-str "/home/r/Desktop/judy_yates_computer_archive") 6.62 - (file-str "/home/r/Desktop/judyates_admin/archive-source-images/")))) 6.63 - 6.64 -)
7.1 --- a/src/laser/.#rasterize.clj Fri Aug 20 00:32:44 2010 -0400 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,1 +0,0 @@ 7.4 -r@RLM.3097:1282277171 7.5 \ No newline at end of file
8.1 --- a/src/laser/rasterize.clj Fri Aug 20 00:32:44 2010 -0400 8.2 +++ b/src/laser/rasterize.clj Fri Aug 20 00:39:50 2010 -0400 8.3 @@ -7,7 +7,7 @@ 8.4 (import '(java.awt Color BorderLayout)) 8.5 (import '(ij ImagePlus IJ)) 8.6 (import '(java.lang Math)) 8.7 - 8.8 +(import '(java.awt Graphics2D Panel)) 8.9 (import '(ij Macro)) 8.10 8.11 (import '(java.io BufferedReader InputStreamReader)) 8.12 @@ -38,7 +38,30 @@ 8.13 (def cut_feed 20) 8.14 (def corner_radius 0) 8.15 8.16 +(defmulti display "Creates a JFrame and displays a buffered image" class) 8.17 8.18 +(defn- makePanel [image] (proxy [Panel] [] (paint [g] (.drawImage g image 0 0 nil)))) 8.19 + 8.20 +(defmethod display 8.21 + BufferedImage [image] 8.22 + (let [panel (makePanel image) 8.23 + frame (JFrame. "Oh Yeah!")] 8.24 + (.add frame panel) 8.25 + (.pack frame) 8.26 + (.setVisible frame true ) 8.27 + (.setSize frame(.getWidth image) (.getHeight image)))) 8.28 + 8.29 +(defmethod display 8.30 + ImagePlus [image] 8.31 + (display (.getBufferedImage image))) 8.32 + 8.33 +(defmethod display 8.34 + clojure.lang.PersistentHashMap [frame-hash] 8.35 + (display (frame-hash->bufferedImage frame-hash))) 8.36 + 8.37 +(defmethod display 8.38 + clojure.lang.PersistentArrayMap [frame-hash] 8.39 + (display (frame-hash->bufferedImage frame-hash))) 8.40 8.41 8.42 (defn raster-preamble [] 8.43 @@ -48,8 +71,6 @@ 8.44 "M101" 8.45 "M3 S1"])) 8.46 8.47 - 8.48 - 8.49 (defn frame-hash 8.50 "yields a convienent representation for the pixles in an image. 8.51 Because of the size of the structvre generated, this must only be used 8.52 @@ -97,6 +118,14 @@ 8.53 8.54 8.55 8.56 + 8.57 + 8.58 + 8.59 + 8.60 + 8.61 + 8.62 + 8.63 + 8.64 8.65 8.66