View snippets.clj
;; Extract values from hashmaps of hashmaps
;; { :anything { :the-key "a" :another-key "b" } :something { :the-key "aa" :another-key "bb" } ... }
;; we want all the `:the-key` values, i.e. `("a" "aa")`.
(map #(:the-key %) (vals my-collection))
$ ab -n 1000 -c 10 -l http://localhost:3000/nhs-trusts
  • Server Software: Jetty(7.6.13.v20130916)
  • Server Hostname: localhost
  • Server Port: 3000
  • Document Path: /nhs-trusts
  • Document Length: Variable
  • Concurrency Level: 10
View api.json
{"questions":[{"id":1,"question_html":"By Friday of this week, how many extra people will be living on our planet?","facts":"At the current rate of population growth there will be an extra 1,000,000 people on earth in the next 5 days. That's a lot! Can't picture 1 million people? Imagine 100 people, or enough people to fill a Boeing 737, arriving in your back garden... every day, for the next 30 years. All between now and Friday.\r\n\r\nFind out more about population growth here:","answers":[{"answer_html":"xxddd","fake":false},{"answer_html":"sfsf","fake":true}]},{"id":2,"question_html":"hello","facts":"asdasdasd","answers":[{"answer_html":"False","fake":false},{"answer_html":"True","fake":false}]},{"id":3,"question_html":"asdfasd","facts":"asdasdasd","answers":[{"answer_html":"True","fake":true},{"answer_html":"False","fake":false}]}]}
View a better

Instead of inheritence we can use a mixin, since this is Rails a concern will do nicely.

module Other
  module RailsConfig
    extend ActiveSupport::Concern

    included do

Error: No such file or directory - Cannot find Elasticsearch launch script from [elasticsearch] -- did you pass a correct path? When using ElasticSearch gems.

Ubuntu elasticsearch package changed, so no longer does which elasticsearch return anything, which means the gem can not find the binary.

Solution: suppy command option to ES to tell it where the binary is, either use the existing binary, mine was at /usr/shared/elasticsearch/bin/elasticsearch, or symlink the same binary to somewhere in $PATH or install a new version to $PATH.

To install a new version download and untar to somewhere in $PATH, e.g. ~/bin You can find downloads such as this one:

View a.rb
class MyThing
post :total, :must_be -> { |res| res > 10 }
def total
# ...
class MyListener
   on_event "recruitment/monthly_total_updated" do |payload|
     # ...


broadcast("recruitment/monthly_total_updated", payload)
module Meta
  def meta
    @meta ||= {}

[String Hash Array].each { |klass| klass.include(Meta) }
name = "Kris"
View example.clj
(require '[ :as j])
;; file
(j/execute! { :subprotocol "hsqldb" :subname "file:./db/testdb"} ["CREATE TABLE changes(id INT)"])
;; in memory
(j/execute! { :subprotocol "hsqldb" :subname "file:./db/testdb"} ["CREATE TABLE changes(id INT)"])
if(document.queryCommandSupported('copy')) {
        if(text=='') { text = ' '; } // empty inputs do not get selected

        // copy text to off-screen input

        // 1.) does copy empty inputs, but adds newline before content
        var range = document.createRange();