Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000| #_( | |
| Let's say you have a threadpool doing work that requires access to some shared resource. | |
| And this resource needs to be refreshed at times. E.g. an OAuth bearer token that can expire or be revoked. | |
| If this resource were expensive to refresh, or subject to rate limiting (OAuth tokens are often both) | |
| then it's desirable to refresh as little as possible. | |
| It's undesirable, however, to mix complicated synchronization code for updating the resource in | |
| with the business logic consuming it. | |
| Enter the lock less monster, a lock free method for coordinating updates to a shared reference. |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000| (deftype FinalizeReporter [x] | |
| Object | |
| (finalize [this] (println "Finalizing" x)) | |
| clojure.lang.IDeref | |
| (deref [this] x)) | |
| (defn leaker [n] | |
| (with-open [_ (reify java.io.Closeable (close [this]))] | |
| (let [s (map #(FinalizeReporter. %) (take 10 (iterate inc 0)))] | |
| (when (> n -1) |
| No implementation of method: :lb of protocol: #'clojure.core.logic/IInterval found for class: clojure.lang.Keyword | |
| java.lang.IllegalArgumentException | |
| Restarts: | |
| 0: [CONTINUE] Pass exception to program | |
| 1: [ABORT] Abort request. | |
| 2: [IGNORE] Do not enter debugger for this exception type | |
| 3: [IGNORE-MSG] Do not enter debugger for this exception message | |
| 4: [IGNORE-CATCH] Do not enter debugger for exceptions with catch location clojure.lang.LazySeq.* | |
| 5: [IGNORE-LOC] Do not enter debugger for exceptions with throw location clojure.core.* |
This gist is a collection of my rough notes from Strange Loop 2012.
| ; y has upper bound x, z has upper bound (Seqable y) | |
| typed.core=> (ann foo (All [x [y :< x] [z :< (Seqable y)]] | |
| [x y z -> Any])) | |
| [typed.core/foo (All [x [y :< x] [z :< (clojure.lang.Seqable y)]] (Fn [x y z -> Any]))] | |
| typed.core=> (declare foo) | |
| #'typed.core/foo | |
| ;cf = check-form | |
| typed.core=> (cf (foo 2 2 [2])) | |
| Any |
| ;; based on core.logic 0.8-alpha2 or core.logic master branch | |
| (ns sudoku | |
| (:refer-clojure :exclude [==]) | |
| (:use clojure.core.logic)) | |
| (defn get-square [rows x y] | |
| (for [x (range x (+ x 3)) | |
| y (range y (+ y 3))] | |
| (get-in rows [x y]))) |
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| (def users [{:name "Brian" :age 22} {:name "Ben" :age 19}]) | |
| ;; Takes a "path", returns a function that takes an "object" and | |
| ;; returns a "costate" | |
| (defn lens [p] | |
| (fn [o] | |
| {:get (get-in o p) | |
| :set #(assoc-in o p %1)})) | |
| (def myAgeLens (lens [0 :age])) |
| -- | Lock-step folding. | |
| -- | |
| -- This module presents an elegant way of executing multiple left folds | |
| -- on one list using constant memory. For example, the mean can be | |
| -- expressed as: | |
| -- | |
| -- @ | |
| -- average = foldLeft $ (/) <$> sumF <*> lengthF | |
| -- @ |