Skip to content

Instantly share code, notes, and snippets.

View iantruslove's full-sized avatar

Ian Truslove iantruslove

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Dumping Datomic data into a local (free) transactor

Create a database dump from the server running the transactor

bin/datomic backup-db "datomic:ddb://us-east-1/rest/of/url?aws_access_key_id=<ACCESS_KEY_ID>&aws_secret_key=<SECRET_KEY>" file:/home/ian/datomic-backup-`date +"%Y%d%m"`

Transfer the dump to your local machine

{:uri "/foo"
:http-method :post
:headers {"content-type": "application/json"
"accept": "*/*"}
:body <InputStream ...>}
@iantruslove
iantruslove / general-case-middleware.clj
Last active August 29, 2015 14:05
Ring: from the ground up
(defn wrap-generic-middleware-example [handler & [other-args]]
(fn [request]
;; Early side-effects:
(log/info "Wrapping incoming request...")
(let [;; Modify request here:
req (assoc request :new-req-key "some value for handlers")
;; Run the handlers:
resp (handler req)]
;; Late side-effects:
(log/info "My middleware is almost done.")
(ns node-cljs-pos.core
(:require [cljs.nodejs :as node]))
(node/enable-util-print!)
(def pos (node/require "pos"))
(defn pos-lexer [s]
(let [Lexer (.-Lexer pos)
lexer (Lexer.)]
(ns introspect.core
(:require [clojure.core.match :as match]
[clojure.java.io :as io]
[clojure-mail.core :as mail]
[clojure-mail.message :as message]
[opennlp.nlp :as onlp]
[opennlp.treebank :as treebank]
[opennlp.tools.filters :as filters]
[corenlp :as nlp])
(:import (org.apache.tika Tika)
@iantruslove
iantruslove / gorilla-repl-helpers.el
Last active August 29, 2015 14:19
Emacs function to remove results from a Gorilla REPL clojure notebook file
(defun gorilla-empty-all-results* ()
(while (re-search-forward
";; @@\n\\(;; ->\n\\)?\\(;;;.*\n\\)*\\(;; <-\n\\)?;; =>\n\\(;;;.*\n\\)+;; <="
nil t)
(replace-match ";; @@")))
(defun gorilla-empty-all-results ()
"Empty all Gorilla REPL result blocks"
(interactive)
(save-excursion
@iantruslove
iantruslove / StopAnalyzer.java
Created May 11, 2015 22:29
English stop words in Lucene (lucene-5.1.0/analysis/common/src/java/org/apache/lucene/analysis/core/StopAnalyzer.java)
static {
final List<String> stopWords = Arrays.asList(
"a", "an", "and", "are", "as", "at", "be", "but", "by",
"for", "if", "in", "into", "is", "it",
"no", "not", "of", "on", "or", "such",
"that", "the", "their", "then", "there", "these",
"they", "this", "to", "was", "will", "with"
);
final CharArraySet stopSet = new CharArraySet(stopWords, false);
ENGLISH_STOP_WORDS_SET = CharArraySet.unmodifiableSet(stopSet);
@iantruslove
iantruslove / DoC-sep-2015-Jupiter.org
Last active September 10, 2015 23:49
Den of Clojure | Real Projects | Jupiter

Den of Clojure

REAL PROJECTS

Jupiter

Den of Clojure, 2015-09-10

Ian Truslove@iantruslove

@iantruslove
iantruslove / math-test.clj
Last active October 13, 2015 14:38
Numerically stable math
(ns jupiter.test.utils.math
(:require [clojure.test :refer :all]
[jupiter.utils.math :refer :all]))
(defn float=
([x y] (float= x y 0.000001))
([x y epsilon]
(let [scale (if (or (zero? x) (zero? y)) 1 (Math/abs x))]
(<= (Math/abs (- x y)) (* scale epsilon)))))