Skip to content

Instantly share code, notes, and snippets.

@kriyative
kriyative / myapp.clj
Created January 20, 2011 19:43
server side Clojure for setting up routes etc.
;;; -*- Mode: Clojure -*-
;; This is clojurejs code which is translated to javascript and runs in the browser
(defn login-submit! []
(.text ($ ".error") "")
(.text ($ "#login-message") "submitting ..."))
(defn dialog-close [] (.dialog ($ this) :close))
@kriyative
kriyative / tail-f.el
Created May 31, 2011 02:51
Emacs Lisp function `tail-f`
(defun tail-f (file)
"Create a COMINT mode buffer running the `tail -f` command on
specified FILE. If FILE is a ssh/scp style remote file spec,
e.g.,
user@remote.host.com:/path/to/file.txt
then a ssh connection is opened to remote.host.com, and `tail -f`
is invoked on the remote server."
(interactive "fFile: ")
@kriyative
kriyative / org-mode-agenda-hack.el
Created July 6, 2011 18:14
Displaying a daily Org-mode agenda reminder in Emacs 1
(defvar daily-agenda-timer (parse-relative-time "9:00 am"))
;; (decode-time daily-agenda-timer)
(defun show-daily-agenda ()
(unless (time-less-p (current-time) daily-agenda-timer)
(setq daily-agenda-timer (time-add daily-agenda-timer
(seconds-to-time 86400)))
(org-agenda-list)))
(add-hook 'display-time-hook 'show-daily-agenda)
@kriyative
kriyative / parse-relative-time.el
Created July 6, 2011 18:21
Displaying a daily Org-mode agenda reminder in Emacs 2
(defun parse-relative-time (time-str)
(destructuring-bind (sec min hour day month year dow dst zone)
(parse-time-string time-str)
(destructuring-bind (sec1 min1 hour1 day1 month1 year1 dow1 dst1 zone1)
(decode-time)
(encode-time (or sec sec1)
(or min min1)
(or hour hour1)
(or day day1)
(or month month1)
@kriyative
kriyative / destructuring-bind-1.lisp
Created July 6, 2011 18:23
A lightweight `bind' macro 1
(destructuring-bind (x y)
point
(destructuring-bind (x1 y1 w h)
frame
(let ((x2 (+ x1 w))
(y2 (+ y1 h)))
(and (>= x x1) (<= x x2) (>= y y1) (<= y y2)))))
@kriyative
kriyative / bind-1.lisp
Created July 6, 2011 18:24
A lightweight `bind' macro 2
(bind (((x y) point)
((x1 y1 w h) frame)
(x2 (+ x1 w))
(y2 (+ y1 h)))
(and (>= x x1) (<= x x2) (>= y y1) (<= y y2)))
@kriyative
kriyative / bind-2.lisp
Created July 6, 2011 18:25
A lightweight `bind' macro 3
(defmacro bind (clauses &body body)
"This macro combines the behaviour of the forms `let*', `destructuring-bind',
and `multiple-value-bind', permitting the following style of binding form:
(bind (((:values m n) (values 10 20))
((a b &key (c 10)) '(1 2))
(x 5))
(+ x a b c m n))
=> 48
@kriyative
kriyative / clj-thrush.lisp
Created March 13, 2012 18:40
Clojure `thrush` operator macro in Common Lisp
(defmacro -> (x &rest args)
"A Common-Lisp implementation of the Clojure `thrush` operator."
(destructuring-bind (form &rest more)
args
(cond
(more `(-> (-> ,x ,form) ,@more))
((and (consp form)
(or (eq (car form) 'lambda)
(eq (car form) 'function)))
`(funcall ,form ,x))
@kriyative
kriyative / defmacro2.clj
Created March 17, 2012 08:48
An alternate `defmacro2` definition with compile time semantics
(in-ns 'user)
;; An alternate `defmacro2` definition based on the example from
;; "Macros are Hard" presentation by @david_mcneil. This
;; implementation defines a macro called `name` and a function
;; equivalent called `name+` which still evaluates at compile time as
;; opposed to execution time
(defmacro defmacro2 [name args & body]
`(do
(defmacro ~name ~args ~@body)
@kriyative
kriyative / defmacro2.clj
Created March 17, 2012 08:50
An alternate `defmacro2` definition with compile time semantics
(in-ns 'user)
;; An alternate `defmacro2` definition based on the example from
;; "Macros are Hard" presentation by @david_mcneil. This
;; implementation defines a macro called `name` and a function
;; equivalent called `name+` which still evaluates at compile time as
;; opposed to execution time
(defmacro defmacro2 [name args & body]
`(do
(defmacro ~name ~args ~@body)