Skip to content

Instantly share code, notes, and snippets.

View marick's full-sized avatar

Brian Marick marick

View GitHub Profile
(ns getset.services.derp)
(require '[clojurewerkz.elastisch.rest :as esr]
'[clojurewerkz.elastisch.rest.index :as index]
'[clojurewerkz.elastisch.rest.document :as document])
(esr/connect! "http://localhost:9200")
(when (index/exists? "myapp2_development") (prn (index/delete "myapp2_development")))
(prn 1 (index/create "myapp2_development" :mappings {"person" {:properties {:age {:type "integer"}}}}))
(prn 2 (document/create "myapp2_development" "person" {:age 55}))

Let me explain what we're trying to do, which may be crazy. But if it's not crazy, perhaps someone can tell us how to use AMQP to do it.

We have a Rails app that talks to a growing number of backend Clojure services.

It could talk to them via HTTP, but many of the messages don't need to be synchronous. They're "fire and forget". Hence AMQP.

For the synchronous messages, we observed two things:

  • Serializing and deserializing HTTP is surprisingly annoying, especially given Rails conventions.

  • Most of the time when we send a message that updates a resource, we don't need a synchronous acknowledgement right away. We only need to know that the update has happened at some point before we next read the resource.

(fact "it's never called"
;; sure could use a better notation for "never called"
(let [mock (make-mock (f & anything) => irrelevant :times 0)]
(subject 3 mock) => 88
(mock-report mock)))
;; Mocks are described in "fake map": see midje.parsing.lexical-maps
;; The tools to build the mock functions are in midje.parsing.from-lexical-maps.from-fake-maps.
;; Reporting on what happened is done in midje.checking.checkables/report-incorrect-call-counts
;; The installation of fakes into vars happens in midje.data.prerequisite-state
(prerequisite (feeds:that-get-a-new-shared-stutter im/default-userid)
=> (shared-feeds im/default-userid)
(secret:pending-for-partner "pcom") => default-potential-secret-key
(secret:accepted-like (contains {:user_id im/default-userid}))
=> default-secret-key
(inquiries:all-orderings im/default-userid)
=> {:by-freshness "questions:partner:by-freshness"
:by-value "questions:partner:by-value"}
Jun 17 17:23:07 PROGRESS heroku/router: at=info method=GET path="/students/3005187/previous_activities?" host=getsetprogress.herokuapp.com request_id=8bdad3dc-d4fb-494f-b141-17e54c06d2a4 fwd="54.81.218.118" dyno=web.1 connect=3ms service=13ms status=200 bytes=167
Jun 17 17:23:07 DOJO app/web.2: 07.671 INFO Started POST "/honeybee_track/student_changed_view" for 64.79.144.10 at 2014-06-17 17:23:07 +0000
Jun 17 17:23:07 DOJO app/web.2: 07.675 INFO Parameters: {"data"=>{"name"=>"home", "params"=>{}}, "key"=>"student_changed_view", "honeybee"=>{"data"=>{"name"=>"home", "params"=>{}}}}
Jun 17 17:23:07 DOJO app/web.2: 07.681 INFO Publish {:signal_created=>"2014-06-17T17:23:07.680Z", :data=>{:name=>"home", :params=>{}}, :ip=>"64.79.144.10", :user_id=>3005187, :signal_type=>"student_changed_view"}
Jun 17 17:23:07 DOJO app/web.2: 07.690 INFO Cache hit on user:3005187.
Jun 17 17:23:07 DOJO app/web.2: 07.703 INFO Started GET "/feed/personal" for 64.79.144.10 at 2014-06-17 17:23:07 +0000
Jun 17 17:23:07 DOJ

In reply to a problem with a script that misprocessed a file whose name had spaces in it, I wrote:


If you want to have filenames with blanks in them, you have to enclose them in single or double quotes. It would be better not to have blanks in them. As H.P. Lovecraft wrote:

"[O]utside the ordered universe [is] that amorphous blight of nethermost confusion which blasphemes and bubbles at the center of all infinity—the boundless daemon sultan 'Aza thoth', whose name no sane computer can parse, and who gnaws hungrily in inconceivable, unlighted chambers beyond time and space amidst the muffled, maddening beating of vile drums and the thin monotonous whine of accursed flutes."

All numbers per 100,000
http://www.fbi.gov/about-us/cjis/ucr/crime-in-the-u.s/2012/crime-in-the-u.s.-2012
murder rate 1993 9.5
murder rate 2012 4.7
change -4.8
https://www.afsp.org/understanding-suicide/facts-and-figures
suicide rate (1993 12
2011 12.3
change 0.3
(require '[clojure.algo.monads :as m])
(defmacro when-maybe
"Like `when-let` except there can be multiple bindings. If any binding value
is nil, the remainder (plus the body) are not evaluated.
Note: unlike `when-let`, a `false` value does not short-circuit evaluation."
[bindings & body]
`(m/domonad m/maybe-m ~bindings (do ~@body)))
(stage3 (stage2 (stage1 data) :a-second-argument)))
(-> data
stage1
(stage2 :a-second-argument)
stage3)
;; returns the result of the final stage