Created
July 21, 2014 21:29
-
-
Save alandipert/334f773ab55a9aee6aa0 to your computer and use it in GitHub Desktop.
Hoplon rot13
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
(page "rot13.html") | |
(defn make-rot13 [start] | |
(->> (for [from (range 27), | |
:let [to (mod (+ 13 from) 26)]] | |
[(char (+ start from)) (char (+ start to))]) | |
(into {}))) | |
(let [table (merge (make-rot13 97) (make-rot13 65))] | |
(defn rot13 [s] | |
(get table s s))) | |
(html | |
(head | |
(link :rel "stylesheet" :type "text/css" :href "css/main.css")) | |
(body | |
(let [plaintext (cell "") | |
encoded (cell= (apply str (map rot13 plaintext)))] | |
(div | |
(input | |
:type "text" | |
:input #(reset! plaintext (.val (js/jQuery (.-target %))))) | |
(span encoded))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, @alandipert! My latest version benefited greatly from this example:
https://github.com/r0t13/rot13.io/blob/hoplon/src/index.cljs.hl
Oh, and I caught an off-by-one bug on line 4: with
27
instead of26
,[
and{
get included by mistake.