Skip to content

Instantly share code, notes, and snippets.

@rab
Forked from gigasquid/swarmcoding
Created May 8, 2012 22:14
Show Gist options
  • Save rab/2639850 to your computer and use it in GitHub Desktop.
Save rab/2639850 to your computer and use it in GitHub Desktop.
Swarm coding instructions
(ns cincyfp.hello)
(+ 1 1)
;; given 3 integers in a sequence
;; generate the number of lights that are on in a berlin clock,
;; returning 5 rows
(defn make-counts [[hours minutes seconds]]
[
(- 1 (mod seconds 2))
(int (/ hours 5))
(mod hours 5)
(int (/ minutes 5))
(mod minutes 5)
]
)
(defn make-line [active total]
(clojure.string/join
(concat (repeat active "*") (repeat (- total active) "."))))
;; given counts for 5 lines in a berlin clock
;; return sequence of 5 strings with the proper number of lights on
(defn make-lines [counts]
(map-indexed (fn [i x] (make-line (nth counts i) x))
'(1 4 4 11 4))
)
;; takes a sequence of 3
;; integers hours minutes seconds and returns string of berlin clock
(defn berlin-clock-print [time-parts]
(clojure.string/join "\n" (make-lines (make-counts time)))
)
;; return sequence of 3 integers
(defn parse-time [time-str]
(map #(Integer/parseInt %) (re-seq #"\d\d" time-str))
)
(println (parse-time "12:13:14"))
(println (berlin-clock-print (parse-time "21:22:05")))
(println (berlin-clock-print (parse-time "01:15:02")))
(println (berlin-clock-print (parse-time "01:00:01")))
(println (berlin-clock-print (parse-time "12:00:00")))
(defun find-next-koan-file (this-filename)
"Get the koan file that lexicographically follows"
(interactive)
(let* ((pattern (format "%02d_*" (1+ (string-to-int (car (split-string this-filename "_"))))))
(filename (car (file-expand-wildcards pattern)))
)
(and filename (file-exists-p filename) (find-file filename) (goto-char (point-min)))
)
)
(defun next-koan ()
"Find the next __ in a koan (which may be in a different file)"
(interactive)
(while (not (search-forward "__" nil t))
(unless (find-next-koan-file (file-name-nondirectory buffer-file-name))
(error "your meditation appears complete (i.e., no more koans found)"))
)
)
(global-set-key (kbd "C-c k") 'next-koan)
(provide 'rab-koans)
  1. Get a browser open to http://23.23.246.103:8080 (you will need this later)
  2. Download the private key for swarming http://23.23.246.103:8080/keys/cincyfp
    1. http://agileconsultingllc.com/cincyfp (save as ~/.ssh/cincyfp on your machine)
  3. chmod go= cincyfp
  4. ssh -i cincyfp swarm@23.23.246.103
  5. The SSH password is:
cincyfp

Or, if you have this in your ~/.ssh/config

Host swarm
  Hostname 23.23.246.103
  User     swarm
  PasswordAuthentication no
  IdentityFile  ~/.ssh/cincyfp

you can just say: ssh swarm

Follow the instructions when you get in!

If you want to run on your local machine and you use Emacs, you can use the rab-koans.el file to provide the same next-koan function bound to C-c k as on the swarm coding config.

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