This file contains 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
""" | |
Functions that implement some of the same functionality found in Matlab's bwmorph. | |
`thin` - was taken and adapted from https://gist.github.com/joefutrelle/562f25bbcf20691217b8 | |
`spur` - Not perfect but pretty close to what matlab does via LUTs | |
`endpoints` - lines up perfectly with matlab's output (in my limited testing) | |
`branches` - this results in more clustered pixels than matlab's version but it pretty close | |
""" | |
import numpy as np | |
import scipy.ndimage as ndi |
This file contains 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 default-maps | |
"Maps with default values, similar to how you can specify default values and blocks to Ruby's Hash. | |
Examples: | |
user> (def b (assoc-default {:foo 34 :bar 34} (fn [_ k] (str k)))) | |
#'user/b | |
user> (get b :foo-bar) | |
\":foo-bar\" | |
user> (def m (assoc-default {:foo 34 :bar 34} 343)) |
This file contains 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 monte-carlo-solitaire.card | |
(use [clojure.contrib.str-utils :only [re-split]])) | |
(defn- inverse-map | |
"Inverses map m so that the vals become the keys, and the keys become vals." | |
[m] | |
(zipmap (vals m) (keys m))) | |
(def suits [:hearts :diamonds :clubs :spades]) |
This file contains 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
; inspired from http://stackoverflow.com/questions/3906831/how-do-i-generate-memoized-recursive-functions-in-clojure | |
(defmacro memoize-fn | |
"Produces a memoized anonymous function that can recursively call itself." | |
[fn-name & fn-args] | |
`(with-local-vars | |
[~fn-name (memoize | |
(fn ~@fn-args))] | |
(.bindRoot ~fn-name @~fn-name) | |
@~fn-name)) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
;; SICP 1.4 | |
;; Exercise 1.4. Observe that our model of evaluation allows for | |
;; combinations whose operators are compound expressions. Use this | |
;; observation to describe the behavior of the following procedure: | |
(define (a-plus-abs-b a b) | |
((if (> b 0) + -) a b)) | |
This file contains 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
brew 'ack' | |
brew 'ag' | |
brew 'coreutils' | |
brew 'bash-completion' | |
brew 'openssl' | |
brew 'readline' | |
brew 'ispell' | |
brew 'wget' | |
brew 'tree' | |
brew 'autoenv' |
This file contains 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
;; Exercise 1.7. | |
;; The good-enough? test used in computing square roots will not be very effective for | |
;; finding the square roots of very small numbers. Also, in real computers, arithmetic operations are almost | |
;; always performed with limited precision. This makes our test inadequate for very large numbers. Explain | |
;; these statements, with examples showing how the test fails for small and large numbers. An alternative | |
;; strategy for implementing good-enough? is to watch how guess changes from one iteration to the | |
;; next and to stop when the change is a very small fraction of the guess. Design a square-root procedure | |
;; that uses this kind of end test. Does this work better for small and large numbers? | |
; The problem with the good-enough? procedure for small numbers is that there radicant is much smaller than |
This file contains 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 calculate-pi | |
"Calculates Pi using the approximation 4 * (1 - 1/3 + 1/5 - 1/7 + ...)" | |
[iterations] | |
(let [odd-numbers (filter odd? (iterate inc 1))] | |
(* 4.0 | |
(apply + (map / (cycle [1 -1]) (take iterations odd-numbers)))))) | |
(println "calculated pi =" (calculate-pi 100000)) | |
(println "Math/PI =" Math/PI) |
This file contains 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
(* see https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md#text-format-details *) | |
statements = (type-def | help | metric)* | |
type-def = <"# TYPE "> metric-name <space> type <newline>? | |
type = #"counter|gauge|histogram|summary|untyped" | |
help = <"# HELP "> metric-name <space> docstring <newline>? | |
metric = metric-name labels? <space> value (<space> timestamp)? <newline>? | |
labels = <'{'> label-name label-value {<','> label-name label-value} <','>? <'}'> | |
(* the below doesn't take into account escaping but probably not an issue for our use case *) |
NewerOlder