Skip to content

Instantly share code, notes, and snippets.

(require '[spec-tools.core :as st])
(require '[spec-tools.spec :as st.s])
(require '[clojure.spec.alpha :as s])
(s/def ::cheese st.s/string?)
(s/def ::stuff st.s/int?)
(s/def ::bar (st/spec (s/keys :req-un [::cheese])))
(s/def ::foo (st/spec (s/keys :req-un [::stuff])))
(s/def ::response (s/or :b ::bar :f ::foo))
brew 'ack'
brew 'ag'
brew 'coreutils'
brew 'bash-completion'
brew 'openssl'
brew 'readline'
brew 'ispell'
brew 'wget'
brew 'tree'
brew 'autoenv'
@bmabey
bmabey / joblib_numpy_memoziation_bug.ipynb
Created September 8, 2016 17:56
Notebook illustrating a bug in joblib
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bmabey
bmabey / sandbox.clj
Last active June 17, 2016 19:36
macros to stop a loop and timeouts in core.async
(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)]
@bmabey
bmabey / simple.clj
Last active December 29, 2015 18:59
(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)]
@bmabey
bmabey / async.clj
Last active December 25, 2015 02:39
(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)))
(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}))
(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))))
@bmabey
bmabey / sqlmagic.py
Last active December 11, 2015 10:18
Simple cell and line IPython Notebook magics for connecting to a ODBC DB and querying
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
@bmabey
bmabey / user_agent.clj
Created October 24, 2012 15:55
Example of using the java lib UserAgentUtils in clojure to parse user agent strings
(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)