Skip to content

Instantly share code, notes, and snippets.

View ardumont's full-sized avatar

Antoine R. Dumont ardumont

View GitHub Profile
@ardumont
ardumont / prime-numbers.clj
Created September 21, 2011 18:22
Return the list of the n first prime numbers
(ns dojo-coding-0.core
(:use [clojure.test :only [run-tests]])
(:use [midje.sweet])
(:use [clojure.contrib.repl-utils :only [show]])
(:use [clojure.pprint :only [pprint]])
(:use [clojure.walk :only [macroexpand-all]]))
(defn prime-numbers "Return the list of the n first prime numbers"
[n]
(loop [candidate 2 current n primes []]
@ardumont
ardumont / gist:1557055
Created January 3, 2012 21:35
templating with noir via defpartial
(defpartial site-layout [& content]
(html5
[:head
[:title "my site"]
(include-css "/css/some-css-file.css"
(include-js "/js/some-js-file.js"]
[:body
[:div#wrapper content]]))
@ardumont
ardumont / use layout in a page
Created January 3, 2012 21:38
use layout in a page
(defpage "/my-page" []
(common/site-layout
[:h1 "Hello world!"]
[:p "loremipsum..."]))
@ardumont
ardumont / use layout in a page.clj
Created January 3, 2012 21:38
use layout in a page
(defpage "/my-page" []
(common/site-layout
[:h1 "Hello world!"]
[:p "loremipsum..."]))
@ardumont
ardumont / morse-dsl.clj
Created June 5, 2012 21:14
morse dsl in clojure
;; 0 represents short signal
;; 1 represents long signal
;; Intermational morse from http://en.wikipedia.org/wiki/Morse_code
(def letters-2-bits {\a [0 1]
\b [1 0 0 0]
\c [1 0 1 0]
\d [1 0 0]
\e [0]
\f [0 0 1 0]
\g [1 1 0]
@ardumont
ardumont / blink-led.clj
Created June 5, 2012 21:18
blinking the led
@ardumont
ardumont / write-morse-to-the-led.clj
Created June 5, 2012 21:21
signal to the led what to do
(defn write-morse
"Given a word, make the led blink in morse for each letter (no upper case, no punctuation)"
[board word]
(doseq [l word]
(blink-letter board (m/letters-2-bits l))))
@ardumont
ardumont / launch-hello-world-from-repl.clj
Created June 5, 2012 21:26
launch the hello world from the repl
(def device-board "/dev/ttyACM0")
;; this is a limitation on the underlying lib clodiuno uses. Indeed, it searches only for /dev/ttySxx serial devices
;; and on ubuntu GNU/Linux it's named /dev/ACM0
(System/setProperty "gnu.io.rxtx.SerialPorts" device-board)
;; now declaring the board
(def board (arduino :firmata device-board))
;; the led must be set in output mode
@ardumont
ardumont / blink-letter.clj
Created June 20, 2012 20:23
blink a led in morse according to a letter
@ardumont
ardumont / clojure-match.clj
Created September 6, 2012 06:56 — forked from cgrand/clojure-match.clj
Language Compare F#, Ocaml, Scala, Clojure, Ruby and Haskell - Simple AST example
(use '[clojure.core.match :only [match]])
(defn evaluate [env [sym x y]]
(match [sym]
['Number] x
['Add] (+ (evaluate env x) (evaluate env y))
['Multiply] (* (evaluate env x) (evaluate env y))
['Variable] (env x)))
(def environment {"a" 3, "b" 4, "c" 5})