This file contains 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
// To detect native support for the HTML5 placeholder attribute | |
var fakeInput = document.createElement("input"), | |
placeHolderSupport = ("placeholder" in fakeInput), | |
clearValue = function () { | |
if (searchField.val() === originalText) { | |
searchField.val(""); | |
} | |
}; | |
This file contains 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
;;; save-layout before killing emacs. (needs revive.el) https://github.com/nunb/revive-mode-config | |
(defun save-state-kill-emacs (&optional arg) | |
"Save state, buffers and kill emacs" | |
(interactive "p") | |
(emacs-save-layout) | |
(save-buffers-kill-emacs)) | |
(global-set-key (kbd "C-x C-c") 'save-state-kill-emacs) |
This file contains 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-last [vect] | |
(first (reverse (seq vect)))) | |
(get-last [1 3 2]) | |
(get-last '(1 3 2)) |
This file contains 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 map->querystring [params] | |
(str | |
"?" | |
(reduce | |
#(str % "&" %2) | |
(map | |
#(str (first %) "=" (second %)) | |
params)))) | |
(map->querystring {"foo" 1 "bar" 2 "baz" "test"}) |
This file contains 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 vecs->map [coll1 coll2] | |
(apply hash-map (mapcat vector coll1 coll2))) | |
(vecs->map [1 2 3] [\a \b \c]) | |
;; => {"1" \a, "2" \b, "3" \c} |
This file contains 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 drop-items [coll x] | |
(loop [coll coll | |
x x | |
res [] | |
c 1] | |
(if (empty? coll) | |
res | |
(recur (rest coll) | |
x | |
(if (= c x) |
This file contains 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
(fn step-reduce | |
([f coll] | |
(step-reduce f (first coll) (rest coll))) | |
([f x coll] | |
(if (seq coll) | |
(let [next-coll (rest coll) | |
next-x (f x (first coll))] | |
(cons x (lazy-seq (step-reduce f next-x next-coll)))) | |
(cons x (lazy-seq '()))))) |
This file contains 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 smallest-common-number [& seqs] | |
(letfn [;; Get max of first items of seqs | |
(max-first [seqs] | |
(apply max (map first seqs))) | |
;; Test if first elemets are equal | |
(first-equal? [seqs] | |
(apply = (map first seqs))) | |
;; Filter values less than x | |
(update-seq [x coll] | |
(if (> x (first coll)) |
This file contains 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 next-nums [n] | |
(filter integer? ((juxt (partial + n) (partial * n) (partial / n)) 2))) | |
(defn collect-next [coll step x] | |
(if (coll x) | |
step | |
(let [res (set (mapcat next-nums coll))] | |
(recur res (inc step) x)))) | |
(defn get-steps [initial final] |
This file contains 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 rotate [n coll] | |
(let [[f s] (split-at (mod n (count coll)) coll)] | |
(concat s f))) | |
(rotate 2 [1 2 3 4 5]) | |
;; => (3 4 5 1 2) |
OlderNewer