- Craig Andera
- Cognitect
- craig@cognitect.com
- http://cognitect.com/podcast
- Sending values between applications
| ;; This has to be a separate function. The way we had it before, with | |
| ;; a loop inside a future, creates a closure that captures the head of | |
| ;; the sequence. Locals clearing here saves us from that. | |
| (defn- enqueue-transactions | |
| "Transact a (potentially infinite) sequence of transactions on `q`, | |
| reporting status via `status`. Pause for `delay` (if non-nil) | |
| between each transaction." | |
| [conn [tx & more] q status delay] | |
| (if (or (not tx) (:done @status)) | |
| (.put q (future :done)) |
| (defn- cpu-stats | |
| "Returns measures of the various types of CPU usage to date" | |
| [] | |
| (->> (-> (clojure.java.shell/sh "cat" "/proc/stat") | |
| :out | |
| (clojure.string/split #"\n") | |
| first | |
| (clojure.string/split #"\s")) | |
| (remove clojure.string/blank?) | |
| (drop 1) |
| import time | |
| class Utils: | |
| @staticmethod | |
| def mapmouse(val): | |
| if abs(val) <= 13: | |
| return val * 128 | |
| elif abs(val) <= 25: | |
| return val * 256 |
| (defn dir-descendants | |
| "Creates a lazy sequence of files by recursively walking | |
| a directory tree and returning all the files it finds." | |
| [dir] | |
| (let [children (.listFiles (File. dir))] | |
| (lazy-cat | |
| (map (memfn getPath) (filter (memfn isFile) children)) | |
| (mapcat dir-descendants | |
| (map (memfn getPath) (filter (memfn isDirectory) children)))))) |
| (defn cartes5 | |
| [a b & [c & ds :as more]] | |
| (let [so-far | |
| (for [x a y b] | |
| [x y])] | |
| (if more | |
| (recur so-far c ds) | |
| (map flatten so-far)))) |
| (defn nfe-test [] | |
| (try | |
| (let [nums (map #(Integer/parseInt %) ["1" "2" "1234123412341234"])] | |
| (when (every? #(< 3 %) nums) | |
| nums)) | |
| (catch NumberFormatException nfe nil))) | |
| (nfe-test) ;; throws NumberFormatException, but I would expect it to | |
| ;; return nil |
| (ns repro.core | |
| (:use [clojure.contrib.io :only [reader]]) | |
| (:gen-class)) | |
| (defn -main [& args] | |
| (println (line-seq (reader (first args))))) |
| git push heroku master | xclip -selection clipboard | |
| Counting objects: 70, done. | |
| Delta compression using up to 2 threads. | |
| Compressing objects: 100% (53/53), done. | |
| Writing objects: 100% (57/57), 6.97 KiB, done. | |
| Total 57 (delta 29), reused 0 (delta 0) | |
| -----> Heroku receiving push | |
| -----> Clojure app detected | |
| -----> Installing Leiningen |