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 pe1 [max] | |
(reduce + | |
(union | |
(set (range 0 max 3)) | |
(set (range 0 max 5))))) |
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
@Entity | |
public class Foo{ | |
@Id | |
public int id; | |
} |
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
public ItemProcessor extends IterativeProcessor<String> implements Processor { | |
@Override | |
public List<String> getItems(Request req) { | |
return req.getParameters("items"); | |
} | |
@Override | |
public void processItem(Request req, String item) { | |
Database.saveItem(item); |
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
;; A data-oriented approach. | |
;; Basic SMTP. Falls back to HELO if Extended SMTP isn't supported. | |
(def script | |
[[:CONNECT ["server.example.com" 587]] | |
[:EHLO ["client.example.com"] :on-reply {502 [:HELO ["client.example.com"]]}] | |
[:MAIL ["[email protected]"]] | |
[:RCPT ["[email protected]"]] | |
[:RCPT ["[email protected]"]] |
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. |
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
(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
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
(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
(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])) |
OlderNewer