Skip to content

Instantly share code, notes, and snippets.

somemethod: function() {
var _this = this;
return function() {
return _this.someCall();
};
}
foo = => @bar
var foo,
_this = this;
foo = function() {
return _this.bar;
};
defn average
numbers
/
apply + numbers
count numbers
defn average
numbers
/
apply + numbers
count numbers
defn average
numbers
/
apply + numbers
count numbers
@robkuz
robkuz / gist:6132845
Last active December 20, 2015 12:39
Some really bad play on words with clojure
(defn even-or-odd []
(let [x (atom 1)]
(fn []
(cond
(even? @x) (println "I am even")
(odd? @x) (println "I am odd"))
(swap! x inc))))
(def I-am-even-odder (even-or-odd))
(I-am-even-odder)
@robkuz
robkuz / gist:6689840
Last active December 23, 2015 20:29
Run on Linux. I completely do not understand why this gives me an error
(require '[clojure.java.shell :as shell])
(require '[clojure.contrib.string :as string])
(def foo (-> (shell/sh "df" "-P")
(:out)
(string/split-lines)
(map (fn [z] z))))
foo
; IllegalArgumentException Don't know how to create ISeq from: user$fn__2690 clojure.lang.RT.seqFrom (RT.java:505)
@robkuz
robkuz / Example1.clj
Last active December 25, 2015 04:29
I have an adjust-state fn which I use to, well adjust the state ;-) thru which I stream all my events. And then I have a changedx fn (basically its the riemann.streams.changed fn with added debug output). Now If I run this I get multiple outputs for every host/service combination event thou the state hasn't changed. If I stream events directly f…
(defn transform-event [event options]
(let [ event-path (event-to-vector event)
state-values (find-state-thresholds event-path options)
state (find-state (:metric event) state-values)
new-event (assoc event :state state)]
new-event))
(defn adjust-state [options & children]
(fn [e]
(let [ new-event (transform-event e options)]
@robkuz
robkuz / gist:03d4900eb9c2fd5ad641
Created September 1, 2014 09:31
A Elixir Parser - Transforming a List of Tokens into a "Tree" (List of List)
defmodule Parser do
def read(input) do
tokens = Tokenizer.tokenize(input)
parse tokens, []
end
def parse([], stack) do
stack
end