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 get-squares [cells] | |
(let [p (partition 3 cells) | |
q (for [x [0 1 2]] (drop x p))] | |
r (map #(take-nth 3 %) q) | |
(partition 9 (flatten r)))) |
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
def update(item_original, attr, value): | |
""" | |
Returns a new dict with attr=value | |
item = {"name": "+5 Dexterity Vest", "sell_in": 10, "quality": 20} | |
=> {'sell_in': 10, 'quality': 20, 'name': '+5 Dexterity Vest'} | |
update(item, 'quality', 5) | |
=> {'sell_in': 10, 'quality': 5, 'name': '+5 Dexterity Vest'} | |
""" | |
item = item_original.copy() | |
item[attr] = value |
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
; gilded.clj | |
; (def item {:name "Aged Brie" :sell-in 12 :quality 3}) | |
(defn force-range [quality] | |
(cond | |
(< quality 0) 0 | |
(> quality 50) 50 | |
:else quality)) | |
(defn backstage [quality sell-in] |
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 random | |
board = ["GO", "A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3", "JAIL", | |
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3", "FP", | |
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3", "G2J", | |
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"] | |
double_board = board * 2 | |
visits = [0] * len(board) | |
cc_cards = ["GO", "JAIL"] + ["NOP"] * 14 |
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
(def game-results {:rock {:rock :tie, :paper :lose, :scissor :win} | |
:paper {:rock :win, :paper :tie, :scissor :lose} | |
:scissor {:rock :lose, :paper :win, :scissor :tie}}) | |
(defn create-game-command | |
[{:keys [aggregate-id player move]} state] | |
[{:event :game-created :game-id aggregate-id :creator player | |
:state-change {:state :started :creator player}} | |
{:event :move-decided :game-id aggregate-id :player player :move move | |
:state-change {:move move}}]) |
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
;; Mouse move handler | |
(let [el "#only-mouse" | |
ch (Bacon.fromEventTarget js/window "mousemove")] | |
(-> ch | |
(.map (ƒ [e] (str (.-offsetX e) ", " (.-offsetY e)))) | |
(.onValue (js/$ el) "text"))) | |
(defn location [ch] | |
(.map ch (ƒ [[tag e]] | |
[tag {:x (.-offsetX e) :y (.-offsetY e)}]))) |
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
;; http://docs.racket-lang.org/reference/mpairs.html | |
(defprotocol IMCons | |
(mcar [p]) | |
(mcdr [p]) | |
(set-mcar! [p val]) | |
(set-mcdr! [p val])) | |
(deftype MCons [^{:volatile-mutable true} car ^{:volatile-mutable true} cdr] | |
IMCons |
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
;; MCons Hack - https://gist.github.com/fredyr/6341286 | |
;; Haskell MVars - http://chimera.labs.oreilly.com/books/1230000000929/ch07.html | |
;; http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html | |
defn empty-mvar [] | |
(let [take-sem (java.util.concurrent.Semaphore. 1) | |
put-sem (java.util.concurrent.Semaphore. 1)] | |
(.acquire take-sem) | |
(mcons nil (mcons take-sem put-sem)))) |
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
(evil-leader/set-leader ",") | |
(evil-leader/set-key | |
"f" 'ido-find-file | |
"b" 'ido-switch-buffer | |
"w" 'save-buffer | |
"s" 'save-buffer | |
"K" 'kill-buffer | |
"k" 'kill-this-buffer | |
"T" 'eshell |
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 interp.core) | |
(defn get-var [var env] (@env var)) | |
(defn set-var! [var val env] | |
(swap! env conj {var val})) | |
(def global-env (atom {})) | |
(defn ext-env [vars vals env] | |
(->> (zipmap vars vals) |
OlderNewer