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 clj-sleuth.crawl | |
(:require [jsoup.soup :as c] | |
[clojure.pprint :as p] | |
[clojure.tools.logging :as log])) | |
(Thread/setDefaultUncaughtExceptionHandler | |
(reify Thread$UncaughtExceptionHandler | |
(uncaughtException [_ thread ex] | |
(log/error ex "Uncaught exception on" (.getName thread))))) |
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 birthday-collision? | |
"Generates a birthday (0-364) for person-count | |
number of people. Returns a boolean value | |
indicating whether there were two or more | |
people with the same birthday." | |
[person-count] | |
(let [rand-days | |
(for [x (range person-count)] | |
(rand-int 365))] | |
(let [matches (->> (frequencies rand-days) |
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
(reduce | |
(fn [m word] | |
(assoc m word (inc (get m word 0)))) | |
{} | |
["foo", "bar", "car", "car"]) |
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 Html exposing (text) | |
type alias User = | |
{ name : String | |
, age : Maybe Int | |
} | |
canBuyAlcohol : User -> Bool | |
canBuyAlcohol user = | |
case user.age of |
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
def interest(principal, rate, times, years) | |
principal * (1 + rate.to_f/times.to_f) ** (times.to_f * years.to_f) | |
end | |
1.upto(50) do |y| | |
puts sprintf("%.02f", interest(1000, 0.05, 1, y)) | |
end |
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 Constant [value]) | |
(defrecord BinaryPlus [lhs rhs]) | |
(defmulti evaluate class) | |
(defmethod evaluate Constant | |
[c] (:value c)) | |
(defmethod evaluate BinaryPlus | |
[bp] (+ (evaluate (:lhs bp)) (evaluate (:rhs bp)))) |
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
module RPS exposing (main) | |
import Html exposing (Html, div, text, button) | |
import Html.Events exposing (onClick) | |
import Random | |
-- MODEL | |
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
(def jira-time-format (f/formatter "yyyy-MM-dd HH:mm")) | |
(def short-time-format (f/formatter "yyyy-MM-dd")) | |
(defn get-time-series | |
([start-date end-date] | |
(let [start-date (f/parse jira-time-format start-date) | |
end-date (f/parse jira-time-format end-date)] | |
(get-time-series start-date end-date start-date []))) | |
([start-date end-date current-date series] | |
(if-not (t/within? (t/interval start-date end-date) current-date) |
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
-- TYPE MISMATCH --------------------------------------------------------------- | |
The argument to function `toFullName` is causing a mismatch. | |
6│ toFullName { fistName = "Hermann", lastName = "Hesse" } | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
Function `toFullName` is expecting the argument to be: | |
{ …, firstName : … } |
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
A few other small pieces of advice that I'll be applying to any project I ever start from scratch again. | |
1) Think about how the service will scale from day-1, and don't box yourself in with any vertical architectural decisions (think about keys and things like that early). | |
2) Design your service so that any node can fail without consequence to the overall operation of the system. | |
3) Host it somewhere sane ;-). | |
4) Leverage as much existing technology as humanly possible (orchestration, monitoring, deployment, etc... are all "solved" problems). |