Skip to content

Instantly share code, notes, and snippets.

@prajwalit
prajwalit / drop-items.clj
Created September 1, 2011 06:47
[4clojure #41] Write a function which drops every Nth item from a sequence.
(defn drop-items [coll x]
(loop [coll coll
x x
res []
c 1]
(if (empty? coll)
res
(recur (rest coll)
x
(if (= c x)
@prajwalit
prajwalit / vecs-to-map.clj
Created August 30, 2011 13:30
zipmap implementation.
(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}
@prajwalit
prajwalit / map-to-querystring.clj
Created August 29, 2011 16:44
Convert map to querystring
(defn map->querystring [params]
(str
"?"
(reduce
#(str % "&" %2)
(map
#(str (first %) "=" (second %))
params))))
(map->querystring {"foo" 1 "bar" 2 "baz" "test"})
@prajwalit
prajwalit / get-last.clj
Created August 29, 2011 11:46
Given a sequence return last item.
(defn get-last [vect]
(first (reverse (seq vect))))
(get-last [1 3 2])
(get-last '(1 3 2))
@prajwalit
prajwalit / gist:1042064
Created June 23, 2011 07:04
save-layout before killing emacs
;;; 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)
@prajwalit
prajwalit / PlaceholderCheck,js
Created January 6, 2011 10:21
For checking support for placeholder
// 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("");
}
};