This file contains hidden or 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
;; this file is a walkthrough of Moustache features, a web framework for Clojure | |
;; http://github.com/cgrand/moustache/tree/master | |
;; Moustache allows to declare routes, apply middlewares and dispatch on http methods. | |
;; Moustache is compatible with all frameworks built on Ring, including Compojure | |
(ns demo | |
(:use net.cgrand.moustache) | |
(:use [ring.adapter.jetty :only [run-jetty]])) ;; hmmm Ring without servlets | |
This file contains hidden or 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 fn-pre-post | |
(:refer-clojure :exclude (defn fn defn-))) | |
(clojure.core/defn- insert-arg | |
"Insert arg in the second position of the form cond." | |
[arg cond] | |
(cons (first cond) (cons arg (rest cond)))) | |
(clojure.core/defn- parse-params | |
"Parse a parameter vector, possibly containing nested vectors for |
This file contains hidden or 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
;;; All Kinds of Destructuring ;;; | |
(let [foo 1] foo) | |
; => 1 | |
(let [[foo bar] [1 2 3]] [foo bar]) | |
; => [1 2] | |
(let [[foo bar & baz] [1 2 3]] [foo bar baz]) | |
; => [1 2 (3)] |
This file contains hidden or 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
(comment | |
(:b (DefaultMap. :foo {:a 1})) | |
; => :foo | |
(:a (DefaultMap. :foo {:a 1})) | |
; => 1 | |
(merge-with conj (DefaultMap. [] {}) {:a 1} {:a 2} {:a 3}) | |
; => {:a [1 2 3]} | |
) | |
;;; method implementations basically taken from clojure.core/emit-defrecord |
This file contains hidden or 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
(defprotocol Pair (a [_]) (b [_])) | |
(defmethod print-method user.Pair [o w] | |
(.write w (str "#<Pair[" (.getName (class o)) "] " (a o) ", " (b o) ">"))) | |
(deftype PairType [a b] | |
Pair | |
(a [_] a) | |
(b [_] b)) |
This file contains hidden or 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
(defn some-name [f] ;; Takes a function that | |
(fn [& fns] ;; Returns a function that takes a list of functions that returns | |
(fn [& args] ;; A function that calls the original function with identity over applying each function to the args of this anonymous function #ohgod | |
(f identity (map apply fns (repeat args)))))) |
This file contains hidden or 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
(defn itunes [command] | |
(let [mgr (javax.script.ScriptEngineManager.) | |
engine (.getEngineByName mgr "AppleScript")] | |
(.eval engine (str "tell application \"iTunes\" to " command)))) | |
(itunes 'pause) | |
(itunes 'play) | |
(itunes 'stop) | |
;; ... |
This file contains hidden or 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
(defprotocol Spinnable | |
(spin [this] "Return a seq walking the opposite direction as this")) | |
(defn iter-bi [x f b] | |
(reify | |
Spinnable | |
(spin [_] (iter-bi x b f)) | |
clojure.lang.ISeq | |
(first [_] x) | |
(more [_] (iter-bi (f x) f b)) |
This file contains hidden or 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
* Which browsers does it work in? | |
** We've tested in modern versions of Firefox, Chrome and Safari. It currently doesn't work in IE. | |
We plan to improve browser support in future. | |
* Does IRCCloud act as a BNC/bouncer and stay connected when I go offline? | |
** Yes it does - you will stay connected to IRC even if you shutdown your computer or log out of IRCCloud.com | |
This means when you come back, you'll be able to see what happened on IRC whilst you were away. | |
* What will it cost? | |
** Free currently, will roll out monthly subscription as the beta progresses. |
This file contains hidden or 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
(defn with-default-args [f & default-args] | |
(fn [& args] | |
(apply f (->> default-args | |
(drop (count args)) | |
(concat args))))) | |
(comment ; usage | |
(def f (with-default-args + 1 2)) |
OlderNewer