Skip to content

Instantly share code, notes, and snippets.

cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
wget https://github.com/elasticsearch/elasticsearch/archive/v0.20.1.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
;; named arguments from the joy of clojure
;; the clojure version just feels not elegant, why?
;; clojure version
(defn slope
[& {:keys [p1 p2] :or {p1 [0 0] p2 {1 1}}}]
(float (/ (- (p2 1) (p1 1))
(- (p2 0) (p1 0)))))
(slope :p1 [4 15] :p2 [3 21])
(defstruct item :title :current-price)
(defstruct bid :user :amount)
(def ^:dynamic history ())
(def ^:dynamic droid (struct item "Droid X" 0))
(defn place-offer [offer]
(binding [history (cons offer history)
droid (assoc droid :current-price (get offer :amount))]
(println droid history)))
(place-offer {:user "Anthony" :amount 10})
(println droid)
(def d (delay (println "Running>>>")
:done!))
(deref d)
(defn get-document
[id]
{:content (delay (slurp "http://www.baidu.com"))})
(get-document "some-id")
(defmacro futures
[n & exprs]
(vec (for [_ (range n)
expr exprs]
`(future ~expr))))
(defmacro wait-futures
[& args]
`(doseq [f# (futures ~@args)]
@f#))
;; Lists
(def l (list))
(cons 1 l)
(conj (conj l 1) 1)
(rest (conj l 1))
(pop l)
;; vectors
(def v [1 2 3])
SET @center = GeomFromText('POINT(34 110)');
SET @radius = 30;
SET @bbox = CONCAT('POLYGON((',
X(@center) - @radius, ' ', Y(@center) - @radius, ',',
X(@center) + @radius, ' ', Y(@center) - @radius, ',',
X(@center) + @radius, ' ', Y(@center) + @radius, ',',
X(@center) - @radius, ' ', Y(@center) + @radius, ',',
X(@center) - @radius, ' ', Y(@center) - @radius, '))'
);
SELECT AsText(point)
(defn memoize [f]
(let [mem (atom {})]
(fn [& args]
(if-let [e (find @mem args)]
(val e)
(let [ret (apply f args)]
(swap! mem assoc args ret)
(prn @mem)
ret)))))
user> (+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M )
0.9M
user> (+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M )
1.0M
user> (+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1)
1.0
user> (+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1)
0.9
user> (+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1 0.1M)
1.0
102
103 server {
104 listen 80;
105 server_name bookmarking.curtis.io;
106
107 location / {
108 expires 24h;
109 proxy_pass http://localhost:3000/;
110 sendfile on;
111 proxy_redirect off;