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
(ns challenge | |
" via http://www.infoq.com/presentations/rx-async | |
Two input streams with the following values: | |
stream1: 7, 1, 0, 2, 3, 1, ... | |
stream2: 0, 7, 0, 4, 6, 5, ... | |
Task: | |
Create a new output stream that | |
• yields, for each value of stream1, the sum of the previous 3 | |
• values of stream1,except if the sum is greater than some threshold in | |
which case the next value of stream2 should be subtracted. |
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
(ns simple-sim | |
(require [clojure.core.async :as async] | |
[clojure.tools.logging :as log] | |
criterium.core | |
[com.benmabey.clj-sim :as sim])) | |
;; Andreas' code | |
(defn event [env type val] | |
(let [rc (async/chan)] |
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
(ns rbl.utils.async | |
(:require [clojure.core.async :refer :all] | |
[clojure.tools.macro :refer [macrolet]])) | |
(defn batch-until-pause | |
"Batches values from the `in` channel into a single a vec of values up until no | |
messages have appeared in `timeout-pause` milliseconds. `max-batch-time` is the | |
number of milliseconds to wait overall before sending a batch." | |
([timeout-pause max-batch-time in] | |
(batch-until-pause timeout-pause max-batch-time in (chan))) |
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
(ns schema-helpers | |
(:require [schema.core :as s])) | |
(defn tuple | |
"Returns a schema for a sequence containing exactly the schema/name pairs. | |
To denote an optional element use {schema name} instead of [schema name]. | |
Example: | |
(def t (tuple [String 'foo] [s/Keyword 'bar] {Number 'num})) |
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
(ns rbl.utils.async | |
(:require [clojure.core.async :refer :all])) | |
(defmacro sleep | |
([ms & stop-channels] | |
(let [to (list 'timeout ms)] | |
`(alts! ~(into [to] stop-channels)))) | |
([ms] | |
`(<! (timeout ~ms)))) |
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
(require '[clojure.core.async :as async :refer :all]) | |
(defmacro sleep | |
([ms stop-channel] | |
`(alts! [(timeout ~ms) ~stop-channel])) | |
([ms] | |
`(<! (timeout ~ms)))) | |
(defmacro go-loop [bindings & body] | |
(let [stop (first bindings)] |
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
(ns default-maps | |
"Maps with default values, similar to how you can specify default values and blocks to Ruby's Hash. | |
Examples: | |
user> (def b (assoc-default {:foo 34 :bar 34} (fn [_ k] (str k)))) | |
#'user/b | |
user> (get b :foo-bar) | |
\":foo-bar\" | |
user> (def m (assoc-default {:foo 34 :bar 34} 343)) |
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
from IPython.core.magic import (Magics, magics_class, line_magic, | |
cell_magic, line_cell_magic) | |
import pyodbc | |
import pandas.io.sql as sql | |
@magics_class | |
class SQLMagic(Magics): | |
con = None |
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
(ns rbl.feature-extraction.user-agent | |
(:use [clojure.core.memoize :only [memo]]) | |
(:require [clojure.tools.logging :as log]) | |
(:import [nl.bitwalker.useragentutils UserAgent DeviceType Browser OperatingSystem])) | |
(defn str->features [string] | |
(try | |
(let [user-agent (UserAgent. (or string ""))] | |
{:browser_group (-> user-agent .getBrowser .getGroup .getName) | |
:os_group (-> user-agent .getOperatingSystem .getGroup .getName) |