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
;; fake-io is a function that returns a promise and sets a future to deliver a random int after 5 seconds | |
user> (time (doall (take 3 (map deref (map (fn [_] (fake-io)) (vec (range 1000))))))) | |
"Elapsed time: 5006.289 msecs" | |
(183 475 390) | |
user> (time (doall (take 32 (map deref (map (fn [_] (fake-io)) (vec (range 1000))))))) | |
"Elapsed time: 5003.565 msecs" | |
(12 45 407 497 446 329 398 80 134 286 351 136 307 170 324 288 197 357 337 481 462 480 324 468 304 141 328 247 445 118 211 0) | |
user> (time (doall (take 33 (map deref (map (fn [_] (fake-io)) (vec (range 1000))))))) | |
"Elapsed time: 10008.503 msecs" |
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
;; Original from | |
;; https://github.com/aphyr/prism/blob/d59aa8cc3b59b44f5241e53d452340bfc3936343/src/com/aphyr/prism.clj#L63 | |
(defn slur | |
"Takes a unary function f, and a time in ms. Returns a function g such that | |
(g x) causes (f x) to be invoked unless (g x) had been invoked less than dt | |
ms ago." | |
[dt f] | |
; Maintain a map of args to invocation times. | |
(let [ts (atom {})] |
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
(def from-chan) | |
(def to-chan) | |
(dotimes [_ num-threads] | |
(let [rf (fn [_ x] (>!! to-chan)) | |
f (xform rf)] | |
(thread | |
(loop [] | |
(when-some [x (<!! from-chan)] | |
(f x)))))) |
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
;; Taken from https://github.com/Prismatic/eng-practices/blob/master/clojure/20130821-testing-principles.md | |
(defmacro test-double | |
"Creates a test double of a function given a fully qualified function name. | |
Behaves like a function, and then stores arguments values in a map, | |
with key as the argument name" | |
([] `(gensym)) | |
([fqfn] ; fully qualified function for argument naming | |
(let [args (first (:arglists (meta (resolve fqfn)))) |
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
lein deps :tree | |
[clojure-complete "0.2.3" :exclusions [[org.clojure/clojure]]] | |
[org.clojure/clojure "1.6.0"] | |
[org.clojure/tools.nrepl "0.2.3" :exclusions [[org.clojure/clojure]]] |
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
desc "tail production log files" | |
task :tail_logs, :roles => :app do | |
trap("INT") { puts 'Interupted'; exit 0; } | |
run "tail -f #{shared_path}/log/production.log" do |channel, stream, data| | |
puts # for an extra line break before the host name | |
puts "#{channel[:host]}: #{data}" | |
break if stream == :err | |
end | |
end |
- Ubuntu 12.04
- Name: 099720109477/ubuntu/images/ebs/ubuntu-precise-12.04-i386-server-20120822
- AMI ID: ami-057bcf6c
- Graphite 0.9.10
- https://launchpad.net/graphite/0.9/0.9.10
- Statsd
- https://github.com/etsy/statsd
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
def self.staging_url(url) | |
if Rails.env == "staging" | |
url.sub('.', '-staging.') | |
else | |
url | |
end | |
end |
heroku pgbackups --app APP_NAME
heroku pgbackups:capture --expire --app APP_NAME # Force a new backup
curl `heroku pgbackups:url --app APP_NAME` -o ~/Desktop/dump #download last backup
pg_restore -c -U username -d database_name_env ~/Desktop/dump # load dump into db (cleanly)
NewerOlder