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
package main | |
import "code.google.com/p/go-tour/tree" | |
import "fmt" | |
func Walk2(t *tree.Tree, ch chan int) { | |
if t.Left != nil { | |
Walk2(t.Left, ch) | |
} | |
ch <- t.Value |
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 get-line | |
[reader] | |
(loop [last-cr? false line (StringBuilder.)] | |
(let [i (.read reader)] | |
(if (neg? i) | |
(str line) | |
(let [c (char i)] | |
(if (and last-cr? (= c \newline)) | |
(.substring line 0 (dec (.length line))) | |
(recur (= c \return) (.append line c)))))))) |
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
;; Straighforward | |
(defn handle-helo | |
[session command] | |
[(-> session | |
(reset-session) | |
(assoc :client-host (:domain command))) | |
{:code 250 :text (:server-host session)}]) | |
;; State monad style | |
;; Not sure if command needs to be closed over, though. |
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
(require '[paprika.core] :as adn) | |
;; Assume t is your access token. | |
(def at {:access-token t}) | |
;; The simple case allows the first argument to be a string. | |
(adn/create-post "This is a test" at) | |
;; For every other case, pass in a map. | |
(adn/create-post {:text "This is a test" :reply-to "123"} at) |
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
(require '[paprika.core :as adn]) | |
;; This returns a sequence your of vectors, one for each of the people you follow. | |
;; Each vector contains the user's username and the date of their last post. | |
;; The sequence is in ascending order by the date of their last post | |
;; Careful, though. The lookup is N+1. | |
(sort-by first | |
(map (juxt :created-at #(get-in % [:user :username])) |
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 fibonacci | |
([] (fibonacci 1 1)) | |
([x y] (cons x (lazy-seq (fibonacci y (+ x y)))))) | |
(defn fizz-buzz | |
[n] | |
(let [fizz (zero? (mod n 3)) buzz (zero? (mod n 5))] | |
(cond | |
(and fizz buzz) "FizzBuzz" | |
fizz "Fizz" |
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
user> `inc | |
clojure.core/inc | |
user> 'inc | |
inc | |
user> (defmacro inc1 [n] `(inc ~n)) | |
#'user/inc1 | |
user> (inc1 3) | |
4 | |
user> (defmacro inc2 [n] (list 'inc n)) | |
#'user/inc2 |
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
(let [d [["a" " 1 "] ["b " "2"] ["c" " 3"]]] | |
(reduce (partial apply assoc) {} (map (partial map clojure.string/trim) d))) | |
;=> {"c" "3", "b" "2", "a" "1"} |
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
(defmacro thing | |
[id & body] | |
`(do | |
(foo ~id) | |
(let [result# (do ~@body)] | |
(bar ~id) | |
result#))) | |
(defmacro sum | |
[nums] |
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
(require '(lime [smtp :as smtp])) | |
;; You can define the client yourself. | |
(def send-mail | |
(-> (smtp/base-smtp "smtp.gmail.com" 587) | |
(smtp/with-auth :PLAIN "username" "password") | |
(smtp/with-starttls))) | |
;; Perhaps have "batteries included" client that you configure with a map. |