This file contains hidden or 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
(defn remove-all-but-last | |
[pred coll] | |
(let [[_ count index] (reduce #(if (pred %2) | |
[(inc (% 0)) (inc (% 1)) (% 0)] | |
[(inc (% 0)) (% 1) (% 2)]) | |
[0 0 nil] | |
coll)] | |
(if (> count 1) | |
(keep-indexed #(and (or (not (pred %2)) (= index %1) nil) %2) coll) | |
coll))) |
This file contains hidden or 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
(import org.apache.pdfbox.pdmodel.PDDocument) | |
(import org.apache.pdfbox.text.PDFTextStripper) | |
(import java.net.URL) | |
(defn extract-pdf-text | |
[url] | |
(with-open [pd (PDDocument/load (.openStream (URL. url)))] | |
(let [stripper (PDFTextStripper.)] | |
(.getText stripper pd)))) |
This file contains hidden or 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
; data is a list of numbers | |
(let [deltas (loop [res '() rem data] | |
(if (empty? rem) | |
res | |
(recur (concat res | |
(map #(Math/abs (- % (first rem))) (rest rem))) | |
(rest rem)))) | |
total (count deltas) | |
mean (/ (reduce + 0 deltas) (count deltas)) | |
std-dev (-> (reduce #(+ % (Math/pow (- %2 mean) 2)) |
This file contains hidden or 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
monitor coso_mojo | |
bool enviando; | |
condition cond_enviar; | |
int cant_esperando; |
This file contains hidden or 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
(defrecord Right [value] | |
Either | |
(success? [_] | |
true) | |
; support destructuring: (let [[val err] (f/attempt->....))] ...) | |
clojure.lang.Indexed | |
(nth [_ i] | |
(case i 0 value 1 nil (throw (IndexOutOfBoundsException.)))) |
This file contains hidden or 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
;; Records are just types that provide default implementations of certain | |
;; key interfaces that allow them to stand in for maps. | |
;; This set of interfaces/protocols is not closed though; you can certainly make them | |
;; useful in places where maps aren't, e.g. w/ sequential destructuring: | |
=> (defrecord Point [x y] | |
clojure.lang.Indexed | |
(nth [_ i] (case i 0 x 1 y | |
(throw (IndexOutOfBoundsException.)))) | |
(nth [_ i default] |
This file contains hidden or 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 example.errors) | |
(defn clean-address [params] | |
"Ensure (params :address) is present" | |
(if (empty? (params :address)) | |
[nil "Please enter your address"] | |
[params nil])) | |
(defn clean-email [params] | |
"Ensure (params :email) matches *@*.*" |
This file contains hidden or 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
#!/bin/bash | |
$DATOMIC_DIR/bin/transactor \ | |
./resources/db/sql-transactor.properties & | |
sleep 1 | |
$DATOMIC_DIR/bin/console -p 8082 \ | |
docker "datomic:sql://?jdbc:postgresql://localhost:5432/DB_NAME?user=datomic&password=datomic" & |
This file contains hidden or 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 error-classifier | |
(:require [clojure.test :refer :all])) | |
(def known-errors ["Anonymous access not allowed" | |
"Invalid trace, not on the current datasource" | |
"sync placeholders were requested with a limit of" | |
"constraint \"company_campaign_dismisses_pkey\"" | |
"constraint \"company_placeholder_customers_reached_pkey" | |
"constraint \"company_campaign_banner_customers_reached_pkey\"" | |
"constraint \"company_channel_customers_reached_pkey\"" |
This file contains hidden or 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
;;;; | |
;; Client | |
;;;; | |
(defn stream-seq-response-with-more! | |
"Returns a lazy sequence that wraps the streaming of data from the server" | |
[conn results have-more?] | |
(lazy-seq | |
(if (empty? results) |