This file contains hidden or 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
| (get-in {:k :v} [:k]) ;; => :v | |
| (update-in {:k :v} [:k] (constantly :x)) ;; => {:k :x} | |
| (get-in {:k :v} []) ;; => {:k :v} | |
| (update-in {:k :v} [] (constantly {:k :x})) ;; => {nil {:k :x}, :k :v} |
This file contains hidden or 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.pprint 'clojure.set) | |
| (def clojuresphere-top "http://www.clojuresphere.com/api/projects?limit=500&sort=dependents&output=clojure") | |
| (defn exec | |
| [& shell-tokens] | |
| (.. Runtime getRuntime (exec (into-array String shell-tokens)) waitFor)) | |
| (defn namespace-usage | |
| [git-path clone-path namespaces] |
This file contains hidden or 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 rxjava-datomic.query | |
| (:require [datomic.api :as d]) | |
| (:use [clojure.repl :only [pst]]) | |
| (:import [rx Observable] | |
| datomic.Peer)) | |
| (defn query [qry & inputs] | |
| (Observable/toObservable | |
| (Peer/q qry (object-array inputs)))) |
This file contains hidden or 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
| -----------= Tales of Yore =----------- | |
| * Hackers: Heroes of the Computer Revolution | |
| (http://www.amazon.co.uk/Hackers-Heroes-Computer-Revolution-Anniversary/dp/1449388396) | |
| * The soul of a new machine | |
| (http://www.amazon.co.uk/Soul-New-Machine-Tracy-Kidder/dp/0140062491/ref=sr_1_2?s=books&ie=UTF8&qid=1363772696&sr=1-2) | |
| * The brainmakers | |
| (http://www.amazon.co.uk/Brainmakers-Scientists-Moving-Beyond-Computers/dp/067151055X/ref=sr_1_1?s=books&ie=UTF8&qid=1363772724&sr=1-1) |
This file contains hidden or 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
| def list=[1,"nan",new Whatever()] // neat! | |
| def nan="nan" | |
| def one=1 | |
| one+nan | |
| "1nan" | |
| one-nan | |
| // No signature of method: java.lang.Integer.minus() is applicable for argument types: (java.lang.String) | |
| Object nan2="nan2" | |
| Object two=2 |
This file contains hidden or 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 foo.schema | |
| (:require [datomic.api :refer [tempid]])) | |
| ;; Datomic schema is wordy, so apply some sane defaults and allow overriding where needed. | |
| (defn- attribute [ident & options] | |
| (let [defaults {:db/id (tempid :db.part/db) | |
| :db/ident ident | |
| :db/valueType :db.type/string | |
| :db/cardinality :db.cardinality/one |
This file contains hidden or 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
| tenemos una lista ordenada (por :priority) de objetos. debe poder accederse por índice (lo que al menos en clj, descarta la posibilidad de usar un set). | |
| puede haber múltiples objetos con el mismo valor :priority. | |
| [{:priority 1} {:priority 1} {:priority 3} {:priority 3} {:priority 3} {:priority 5} {:priority 5} {:priority 8} {:priority 8} {:priority 8}] | |
| en mi dominio, cada objeto tiene más claves aparte de :priority, pero son irrelevantes en este problema. | |
| lo que deseamos es un método que nos dé el índice de acceso de un elemento al azar, un azar influido por las prioridades. | |
| digamos que dos objetos con la misma :priority tienen elegibilidad equiprobable, |
This file contains hidden or 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 async-test.core | |
| (:require [cljs.core.async :refer [chan]] | |
| [clojure.string :as string]) | |
| (:require-macros | |
| [cljs.core.async.macros :as m :refer [go alt! alts!]])) | |
| (def c (chan)) | |
| (def loc-div (.getElementById js/document "location")) | |
| (.addEventListener js/window "mousemove" |
This file contains hidden or 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 'clojure.core.async) | |
| (def output (atom [])) | |
| (defn producer [ctrl k] | |
| (go (loop [i 0] | |
| (when-let [c (<! ctrl)] | |
| (>! c [k i]) | |
| (>! ctrl c) | |
| (recur (inc i)))))) |
This file contains hidden or 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
| (defn with-local-redefs-fn | |
| [a-var its-new-value func] | |
| (cast clojure.lang.IFn @a-var) | |
| (alter-meta! a-var | |
| (fn [m] | |
| (if (::scope-count m) | |
| (update-in m [::scope-count] inc) | |
| (assoc m | |
| ::scope-count 1 | |
| ::thread-local-var (doto (clojure.lang.Var/create @a-var) |