Record of experiments, readings, links, videos and other things that I find on the long road.
Registro de experimentos, lecturas, links, vídeos y otras cosas que voy encontrando en el largo camino.
Saturday, January 30, 2016
Interesting Talk: "Concurrency Is Not Parallelism"
I've just watched this wonderful talk by Rob Pike:
These are the talk slides.
Friday, January 29, 2016
Kata: Alphabet Cipher in Clojure
I just redid the Alphabet Cipher kata from the fantastic Carine Meier's Living Clojure book.
I had done it some time ago with Eloi Poch and Rafa Gómez (thanks guys I had a great time) at a Clojure Developers Barcelona event.
These are the tests using Midje:
and this is the final code:
I used a mix of TDD and REPL-driven development committing after each green and each refactoring.
What I did was tinkering in the REPL to get rough versions of encode, decode and decipher functions. This kind of tinkering is getting more and more fun, the more I get used to working in the REPL.
Once I had the rough version I just copied it directly on the code, stabilized it with some tests and started to refactor it until it seemed a bit more readable to me.
See all the commits here if you want to follow the process.
You can find all the code on GitHub.
I had done it some time ago with Eloi Poch and Rafa Gómez (thanks guys I had a great time) at a Clojure Developers Barcelona event.
These are the tests using Midje:
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 alphabet-cipher.coder-test | |
(:require | |
[midje.sweet :refer :all] | |
[alphabet-cipher.coder :refer :all])) | |
(facts | |
"about Alphabet cipher" | |
(fact | |
"can encode given a secret keyword" | |
(encode "v" "m") => "h" | |
(encode "vigilance" | |
"meetmeontuesdayeveningatseven") => "hmkbxebpxpmyllyrxiiqtoltfgzzv" | |
(encode "scones" | |
"meetmebythetree") => "egsgqwtahuiljgs") | |
(fact | |
"can decode an encrypted message given a secret keyword" | |
(decode "v" "h") => "m" | |
(decode "vigilance" | |
"hmkbxebpxpmyllyrxiiqtoltfgzzv") => "meetmeontuesdayeveningatseven" | |
(decode "scones" | |
"egsgqwtahuiljgs") => "meetmebythetree") | |
(fact | |
"can extract the secret keyword given an encrypted message and the original message" | |
(decipher "o" "t") => "v" | |
(decipher "opkyf" "thequ") => "vigil" | |
(decipher "opkyfipmfmwcvqoklyhxywgeecpvhelzg" | |
"thequickbrownfoxjumpsoveralazydog") => "vigilance" | |
(decipher "hcqxqqtqljmlzhwiivgbsapaiwcenmyu" | |
"packmyboxwithfivedozenliquorjugs") => "scones")) |
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 alphabet-cipher.coder) | |
(declare encode) | |
(def ^:private alphabet | |
(map char (range (int \a) (inc (int \z))))) | |
(defn- rotate-str [str n] | |
(take (count str) (drop n (cycle str)))) | |
(defn- rotate-alphabet-to-start-with [c] | |
(rotate-str alphabet (.indexOf alphabet c))) | |
(defn- encode-char [keyword-c msg-c] | |
(nth (rotate-alphabet-to-start-with keyword-c) | |
(.indexOf alphabet msg-c))) | |
(defn- decode-char [keyword-c c] | |
(nth alphabet | |
(.indexOf (rotate-alphabet-to-start-with keyword-c) c))) | |
(defn- decipher-char [encoded-c msg-c] | |
(nth alphabet | |
(.indexOf (rotate-alphabet-to-start-with msg-c) encoded-c))) | |
(defn- possible-keywords [enlarged-keyword] | |
(map #(take % enlarged-keyword) | |
(range 1 (inc (count enlarged-keyword))))) | |
(defn- find-first [pred coll] | |
(some #(when (pred %) %) coll)) | |
(defn- decipher-enlarged-keyword [encoded-msg msg] | |
(apply str (map decipher-char encoded-msg msg))) | |
(defn encode [keyword msg] | |
(apply str (map encode-char (cycle keyword) msg))) | |
(defn decode [keyword encoded-msg] | |
(apply str (map decode-char (cycle keyword) encoded-msg))) | |
(defn decipher [encoded-msg msg] | |
(->> (decipher-enlarged-keyword encoded-msg msg) | |
possible-keywords | |
(find-first #(= (encode % msg) encoded-msg)) | |
(apply str))) |
What I did was tinkering in the REPL to get rough versions of encode, decode and decipher functions. This kind of tinkering is getting more and more fun, the more I get used to working in the REPL.
Once I had the rough version I just copied it directly on the code, stabilized it with some tests and started to refactor it until it seemed a bit more readable to me.
See all the commits here if you want to follow the process.
You can find all the code on GitHub.
Thursday, January 28, 2016
Tuesday, January 26, 2016
Interesting Podcast: "Ruby Antipatterns"
I've just listened to this great
Ruby Rogues podcast
talking about antipatterns in Ruby:
Interesting Talk: "DDD & Microservices: At Last, Some Boundaries!"
I've just watched this great talk by Eric Evans:
Interesting Paper: "Programming as Theory Building"
I've just read this great paper by Peter Naur:
Thanks to Álvaro García for recommending it to me.
Saturday, January 23, 2016
Interesting Talk: "lein-voom: Projects Want to Be Values"
I've just watched this awesome talk by Aaron Brooks:
Saturday, January 16, 2016
Interesting Paper: "The Humble Dialog Box"
I've just read this great paper by Michael Feathers:
It describes a design technique to facilitate testing of GUIs, which is also described by Martin Fowler in Humble View.
Interesting Talk: "Despliegue continuo con Docker y Ansible"
I've just watched this wonderful talk by Nestor Salceda:
Thursday, January 7, 2016
Interesting Talk: "Condition Systems in an Exceptional Language"
I've just watched this great talk by Chris Houser:
Tuesday, January 5, 2016
Interesting Talk: "Leveling Up, Taking your engineering & operations role to the next level"
I've just watched this great talk by Kate Matsudaira:
Interesting Talk: "Specter: overcome your fear of nested Clojure data"
I've just watched this great talk by Nathan Marz:
Subscribe to:
Posts (Atom)