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
(require '[clojure.string :as str]) | |
(defn remove-punc [s] | |
(clojure.string/replace s #"[.!?\\-]" "")) | |
(defn split-to-words [s] | |
(clojure.string/split s #" ")) | |
(defn sort-by-alpha [coll] | |
(sort-by clojure.string/lower-case coll)) ; call lower-case in the comparator (x y) |
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
; (deftest large-addition | |
; (is (= (wordy/evaluate "What is 123 plus 45678?") 45801))) | |
; (deftest addition-and-multiplication | |
; (is (= (wordy/evaluate "What is -3 plus 7 multiplied by -2?") -8))) | |
(ns wordy (:use clojure.string)) | |
(defn remove-question-mark [query] | |
(clojure.string/join "" (drop-last query))) |
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
; (deftest large-addition | |
; (is (= (wordy/evaluate "What is 123 plus 45678?") 45801))) | |
; (deftest addition-and-multiplication | |
; (is (= (wordy/evaluate "What is -3 plus 7 multiplied by -2?") -8))) | |
(ns wordy (:use clojure.string)) | |
(defn remove-question-mark [query] | |
(clojure.string/join "" (drop-last query))) |
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 map-every-nth [f coll n] | |
(map-indexed #(if (zero? (mod (inc %1) n)) (f %2) %2) coll)) | |
(defn convert-to-number-seq [num-string] | |
(map #(Integer/parseInt %) (re-seq #"\d" num-string))) | |
(defn double-every-second-digit [coll] | |
(map-every-nth #(* 2 %) (reverse coll) 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
# Example of concurrency issue: | |
class Account | |
attr_accessor :amount | |
def initialize | |
@amount = 0 | |
end | |
def get_balance |
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 bank-account) | |
(defn open-account [] | |
(atom 0) | |
) | |
(defn close-account [account] | |
(reset! account nil) | |
) |
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 puzzle [ 3 0 0 0 0 5 0 1 0 | |
0 7 0 0 0 6 0 3 0 | |
1 0 0 0 9 0 0 0 0 | |
7 0 8 0 0 0 0 9 0 | |
9 0 0 4 0 8 0 0 2 | |
0 6 0 0 0 0 5 0 1 | |
0 0 0 0 4 0 0 0 6 | |
0 4 0 7 0 0 0 2 0 | |
0 2 0 6 0 0 0 0 3 ]) |
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
;; Objective ; print out x rows of pascals trianlge | |
;; https://www.mathsisfun.com/pascals-triangle.html | |
;; (factorial 4) => 4 * 3 * 2 * 1 = 24 | |
(defn factorial [n] | |
(reduce * (range 1 (inc n)))) | |
;; (binomial-coefficient n k) => n! / k!(n-k)! | |
;; | |
;; (binomial-coefficient 4 2) => 24 / 2 * 2 => 24 / 4 => 6 |
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 icp-api.core | |
(:require [org.httpkit.server :as s] | |
[clojure.data.json :as json] | |
[clj-http.client :as client] | |
[inflections.core :as i])) | |
(def api-key "XXXXXXXXXXXXXXXXXXXXX") | |
(def uri "https://emi.azure-api.net/ICPConnectionData/single") | |
(defn- get-icp |
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
# EMI::ICPConnectionDataClient.new.find(id) | |
module EMI | |
class ICPConnectionDataClient | |
include HTTParty | |
class ICP < OpenStruct; end; | |
base_uri 'https://emi.azure-api.net/ICPConnectionData' |