Skip to content

Instantly share code, notes, and snippets.

View rdsr's full-sized avatar

Ratandeep Ratti rdsr

  • LinkedIn!
  • Sunnyvale, CA
View GitHub Profile
(defn create-project
[]
(sql/create-table
:project
[:id :int "PRIMARY KEY" "NOT NULL"]
[:name "varchar(30)" "NOT NULL"]
[:description :text "NOT NULL"]))
(defn contextual-eval [ctx expr] ;; from Joy of clojure
(eval
`(let ~(vec (mapcat #(list % `('~ctx '~%)) (keys ctx)))
~expr)))
(defn contextual-eval ;; alternative
[ctx expr]
(eval
`(let ~(vec (apply concat ctx))
(defn clean-up [m]
(reduce f {} m))
(defn f
[m [key value]]
(cond
(vector? value) (apply conj m (map clean-up value))
(map? value) (conj m value)
:else (assoc m key value)))
(defun my-save-buffer (&optional args)
"removing trailing whitespaces and tabs while saving buffer"
(interactive "p")
(untabify (point-min) (point-max))
(whitespace-cleanup)
(save-buffer args))
(global-set-key "\C-x\C-s" 'my-save-buffer)
;;toggle full-screen
(defun toggle-fullscreen ()
(interactive)
(set-frame-parameter
nil
'fullscreen
(if (frame-parameter nil 'fullscreen)
nil
'fullboth)))
(->> colls
(reduce #(for [x %1 y %2] [x y]))
(map flatten)))
(defn amicable? [a]
(if (@amicable-nos a) true
(let [b (d a)
db (d b)]
(if (and (not= a b) (= a db))
(do (swap! amicable-nos assoc b true) true)
false))))
(def number->wrd-cnt
{1 (count "one")
2 (count "two")
3 (count "three")
4 (count "four")
5 (count "five")
6 (count "six")
7 (count "seven")
8 (count "eight")
9 (count "nine")
(use '[clojure.contrib.duck-streams :only (reader read-lines)])
(def letter->index
{\A 1
\B 2
\C 3
\D 4
\E 5
\F 6
\G 7
(define (segments->painter segment-list)
(lambda (frame)
(for-each
(lambda (segment)
(draw-line
((frame-coord-map frame) (start-segment segment))
((frame-coord-map frame) (end-segment segment))))
segment-list)))