Skip to content

Instantly share code, notes, and snippets.

View abarnash's full-sized avatar

Alicia Barnash abarnash

  • Washington D.C.
View GitHub Profile
@abarnash
abarnash / probability.js
Last active October 31, 2020 23:22
basic probability utility
//-----------------------------------
// Discrete Probability Distributions
let expectation = (xvals, pfn) => xvals.reduce((sum, x) => sum + x * pfn(x), 0)
let variance = (xvals, pfn) => {
const expect = expectation(xvals, pfn)
return xvals.reduce((sum, x) => sum + pfn(x) * (x - expect) ** 2, 0)
}
@abarnash
abarnash / es-data-model.md
Last active February 14, 2019 19:18
Elastic Data Modelling

With this data model, you can scroll through each interaction/source/channel demographic index directly for each demographic bucket + combination of buckets you want, without having to run through the overhead of traversing a large graph on every run.

INDEX /consumer-demo

Create an index for all consumers with all their relevant demographic attributes. Whatever process(es) that determine these values will update this index

@abarnash
abarnash / duration-to-ms.clj
Created August 16, 2016 18:53
Converts an ISO duration string to Millisecond value in clojure
(ns duration-to-ms)
(defn string->millis [duration-str]
(.getMillis (.toStandardDuration (org.joda.time.Period. duration-str))))
;; Example
;;=> (string->millis "PT8M56S")
;;53600
;;=>
@abarnash
abarnash / promise-all.clj
Last active March 10, 2020 12:36
Clojure implementation of all(promises).then(...) pattern from JavaScript
(defn getPromiseFn
[aPromise]
(fn [num] (Thread/sleep 10000)
(deliver aPromise (str num " done"))))
(def proms [(promise) (promise) (promise)])
(def promFns (map getPromiseFn proms))
(future (map deref proms))
(future (map promFn (range 0 (count proms))))
@abarnash
abarnash / array_subtract
Last active February 27, 2016 17:01
ES5 implementation of set difference for JS arrays.
var array_subtract = function(arr,values) {
return arr.filter(function(x) {
var remove = values.filter(function(v){
return x == v;
});
return !remove.length>0;
});
};