Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created July 21, 2014 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/334f773ab55a9aee6aa0 to your computer and use it in GitHub Desktop.
Save alandipert/334f773ab55a9aee6aa0 to your computer and use it in GitHub Desktop.
Hoplon rot13
(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)))))
@r0t13
Copy link

r0t13 commented Jul 22, 2014

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 of 26, [ and { get included by mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment