Skip to content

Instantly share code, notes, and snippets.

View cataska's full-sized avatar
😱
🥺😢😭

Wen-Chun Lin cataska

😱
🥺😢😭
  • Taipei, Taiwan
View GitHub Profile
(setf *random-state* (make-random-state t))
(defun dice ()
(random 2))
(defun roll (n)
(let ((x 0)
(count 0))
(loop while (< x n) do
(incf count)
(defconstant +words-filename+ "words.txt")
(defun date-to-ms (year month day)
(* (encode-universal-time 0 0 0 day month year) 1000))
(defvar *base-date* (date-to-ms 2021 6 19))
(defvar *day-in-ms* 86400000)
(defun parse-words-input (pathname)
(uiop:read-file-lines pathname))
(def hundred-times (partial * 100))
;; => #'hundred-times
(hundred-times 5)
;; => 500
(def times (partial *))
;; => #'times
(times 1)
(def sum-str (comp str +))
;; => #'sum-str
(sum-str 8 8 8)
;; => "24"
(filter (comp not zero?) [0 1 0 2 0 3 0 4])
;; => (1 2 3 4)
(def countif (comp count filter))
@cataska
cataska / closure.cljs
Last active September 25, 2018 08:18
(ns hello-world.core
(:require [goog.dom :as dom]
[goog.date :refer [getNumberOfDaysInMonth]]
[goog.events :refer [listen]])
(:import [goog.events EventType]
goog.Promise))
(def element (dom/getElement "body"))
(js/console.log (getNumberOfDaysInMonth 2018 9))
alert("ClojureScript")
console.log("Hello")
el.innerHtml
el["innertHtml"]
el.innerHtml = "ClojureScript"
el["innerHtml"] = "ClojureScript"
;; Invoking methods
(js/alert "ClojureScript")
(.log js/console "Hello")
;; Accessing properties
(.-innerHtml el)
(aget el "innerHtml")
;; Modifying properties
(set! (.-innerHtml el) "ClojureScript")
(let [c (chan)]
(go (dotimes [x 3]
(>! c x)
(println "Put: " x)))
(go (dotimes [x 3]
(println "Take: " (<! c)))))
;; => Put: 0
;; => Take: 0
;; => Put: 1
(def ch (chan)) ;; ==> Create channel
(take! ch #(println "Got a value:" %))
;; => Take value from channel, Asynchronously
(put! ch 42) ;; => Asynchronously put value from channel
(def numbers (iterate inc 1))
;; => #'numbers
(defn square [x] (* x x))
;; => #'square
(def squared (map square numbers))
;; => #'squared
(take 5 squared)