This file contains 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 simple.core | |
(:require [reagent.dom :as rdom] | |
[clojure.string :as str] | |
[re-frame.db :as db] | |
[re-frame.core :as rf])) | |
;; A detailed walk-through of this source code is provied in the docs: | |
;; https://github.com/Day8/re-frame/blob/master/docs/CodeWalkthrough.md | |
;; -- Domino 1 - Event Dispatch ----------------------------------------------- |
This file contains 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 choice [a b] | |
(clojure.string/join (or (seq a) (seq b)))) | |
(defn fizzbuzz [n] | |
(let [fizzes (cycle ["" "" "Fizz"]) | |
buzzes (cycle ["" "" "" "" "Buzz"]) | |
words (map str fizzes buzzes) | |
numbers (map str (rest (range)))] | |
(take n (map max words numbers)))) |
This file contains 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 my.test | |
(:require [cljs.math :as m] | |
[clojure.test.check :as tc] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.properties :as prop :include-macros true])) | |
(defn d= [a b] (or (= a b) (and (js/isNaN a) (js/isNaN b)))) | |
(def safe-integer (gen/choose js/Number.MIN_SAFE_INTEGER js/Number.MAX_SAFE_INTEGER)) | |
This file contains 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
;; 1. hello worlds | |
;; 1.1. Write a function that receives a name and prints to the console Hello <name>! | |
;; 1.2. Write a function that receives several names and prints to the console Hello <name>! for each name | |
;; 1.3. Write of code that checks your functions work properly (layman unit tests) | |
(defn hello [name] | |
(str "Hello, " name "!")) |
This file contains 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 foo.me | |
(:require [clojure.test :refer [deftest is are run-tests]])) | |
(defn me [x] | |
(+ x 2)) | |
(deftest test-me | |
(is (= 4 (me 2)))) | |
This file contains 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
;; https://guides.rubyonrails.org/association_basics.html | |
(def book-info {:title "Seven Habits of Highly Effective People"}) | |
(def author {:name "Stephen Covey" | |
:id "steph"}) | |
(def association {:association-field :author-id | |
:parent-field :id}) | |
(defn add-to [parent child association] |
This file contains 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
;; https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy | |
(defn proxy [m] | |
(js/Proxy. m #js {:get (fn [target prop] | |
(let [prop' (if (vector? target) | |
(js/parseInt prop) | |
(keyword prop))] | |
(let [v (or (get target prop') | |
(get target prop))] | |
(if (coll? v) | |
(proxy v) |
This file contains 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": "object", | |
"required": ["firstName", "lastName"], | |
"properties": { | |
"firstName": {"type": "string"}, | |
"lastName": {"type": "string"}, | |
"bookList": {"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { |
This file contains 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 ( | |
"fmt" | |
"math/big" | |
) | |
func factorial(x *big.Int) *big.Int { | |
n := big.NewInt(1) | |
if x.Cmp(big.NewInt(0)) == 0 { | |
return n | |
} |
This file contains 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
;; Godel Escher Bach - G fractal from Chapter 5 | |
(set! | |
(.-innerHTML js/klipse-container) | |
"<canvas style='width:100%; height:100%'></canvas>") | |
(def canvas (aget (js/document.getElementsByTagName "canvas") 0)) | |
(set! (.-height canvas) (.-innerHeight js/window)) | |
(def ctx (.getContext canvas "2d")) |
NewerOlder