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 my-assoc-in | |
"Implement built-in assoc-in in the way I get it. It nicely inserts a value in the nested map and doesn't overwrite." | |
[map keys value] | |
(let [[k & keys] (reverse keys)] | |
(loop [[key & keys] keys | |
final map | |
initial (assoc {} k value)] | |
(if (not (empty? keys)) | |
(recur keys | |
final |
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 regex-for-hex-range | |
(:use clojure.test)) | |
(defn dec-to-hex | |
[number] | |
(clojure.string/upper-case (format "%x" number))) | |
(defn hex-to-dec | |
[string] | |
(let [conversion-table (zipmap |
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 firstshot.chessknightmove | |
(:refer-clojure :exclude [== >= <= > < =]) | |
(:use clojure.core.logic | |
clojure.core.logic.arithmetic)) | |
(defn knight-moves | |
"Returns the available moves for a knight (on a 8x8 grid) given its current position." | |
[x y] | |
(let [xmax 8 ymax 8] | |
(run* [q] |
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
;; I have defined a function, let's call it modifier, which has a | |
;; specific logic inside. I want core.logic to deal with it in order to | |
;; find the correct parameters for this function to output the | |
;; result I want. | |
;; Let's define two states. The goal is to find out how to go from the | |
;; depart state to the arrival one. These states are not that very | |
;; difficult structures, they're basically maps. | |
(def depart-state {:a {:a 1 :c 4} :b {:a 2 :b 3 :c 6} :c 3}) | |
(def arrival-state {:a {:a 1 :b 2 :c 4} :b {:a 2 :b 3 :c 6} :c 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
(def firsts | |
'((rand-nth [:a :b :c]) | |
(rand-nth ["TW" "DE" "UK" "FR" "US" "JP"]) | |
(rand-nth [:bob :alice :charles :georges :matz :is :nice]))) | |
(def key-length 2) | |
(def sample-depth 300) | |
(def sample | |
(->> (repeat (+ key-length 2) '(rand-int 10)) |
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.exports = { | |
config: { | |
// default font size in pixels for all tabs | |
fontSize: 14, | |
// font family with optional fallbacks | |
fontFamily: '"Fira Code", Menlo, "DejaVu Sans Mono", "Lucida Console", monospace', | |
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk) | |
cursorColor: 'rgba(100,255,229,0.75)', |
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
;; We have a problem because of json serialisation / deserialisation: in its | |
;; narrow way, when a map keyed with integers is sent over the network, the | |
;; deserialised result contains keys like :1, :234, which are integers | |
;; represented by keywords. There are good reasons to this but we also have | |
;; good reasons to find integers are more properly represented by numbers. | |
;; | |
;; There can be numerous ways to avoid this problem. The first one here is | |
;; very narrow and focus on our mere goal: box keys to integers. | |
(defn- deep-key-cast |
- Re-frisk Visualize re-frame pattern data or reagent ratom data as a tree structure, watch re-frame events and export state in the debugger
- Dirac A Chrome DevTools fork for ClojureScript developers
- BinaryAge custom formatters for ClojureScript
This is a short code snippet from a pet project I used to have fun with five or six months ago. It may not work as I just pasted code from it but I hope it shows the main ideas.
This gist takes as granted you know the documentation of re-frame. It give an example to this part of the documentation: subscribing to external data Poke me if you want help about it.
OlderNewer