Skip to content

Instantly share code, notes, and snippets.

View jclaggett's full-sized avatar

Jonathan Claggett jclaggett

View GitHub Profile
(defmacro lazy
"Returns a lazy sequence of calls to (f). Arguments are evaluated once as needed.
(lazy f a b c d) --> (a, (f a b), (f (f a b) c), (f (f (f a b) c) d))"
([f x]
`(lazy-seq
(list ~x)) )
([f x form & more]
`(lazy-seq
(let [x# ~x]
(cons x#
; Experiment with 'foo' blocks as an alternative to -> and ->>.
(defmacro foo
([] '%)
([form & more]
`(let [~'% ~form] (foo ~@more))) )
(def foo-ex1
(foo
1
(+ 1 %)
(defmacro topic
([t] nil)
([t form] form)
([t form & more]
`(let [~t ~form] (topic ~t ~@more))) )
(def topic-ex1
(topic % 1
(+ 1 %)
(/ % 2) ) )
#!/bin/bash -e
new_status()
{
gajim-remote change_status "$@"
}
lock_screen()
{
gnome-screensaver-command --lock
(defmacro let2
"Alternate let block that doesn't have a body, just bindings. The last binding is returned."
([] nil)
([& bindings]
`(let [~@bindings] ~(first (take-last 2 bindings))) ) )
(defn conjoin [& preds]
(fn [& args]
(let2
% (apply juxt preds)
% (map % args)
% (flatten %)
% (every? identity %))))
(defn disjoin [& preds]
(fn [& args]
@jclaggett
jclaggett / context.sh
Created April 14, 2011 20:24
context switcher tool
#!/bin/bash -e
status_icon_000="/usr/share/icons/Humanity/apps/48/stock_delete-bookmark.svg"
status_icon_100="/usr/share/icons/Humanity/apps/48/stock_bookmark.svg"
function context_loop() {
declare time_task
while time_task=$(context_switch_dialog $*)
do
set $time_task # reference using positional args
(defn sparkline [values]
(let [low (apply min values)
high (apply max values)
bars "▁▂▃▄▅▆▇█"
step (/ (- high low) (dec (count bars)))
scale #(nth bars (int (/ (- % low) step)))]
(apply str (map scale values))))
@jclaggett
jclaggett / deftype+.clj
Created March 10, 2014 13:32
:delegate option for deftype
(ns deftype+
"Augmented deftype sporting a new :delegate option.")
;; code to get the methods of interfaces and protocols
(defmulti get-methods
"Return a map of all method names to their arity."
class)
(defmethod get-methods clojure.lang.PersistentArrayMap
[protocol]
(ns squarespec
(:require [clojure.spec :as s]
[clojure.spec.gen :as sgen]
[clojure.spec.test :as stest]))
;; Implementation
(defn square
"Define a square path given an origin and length."
[[x1 y1 :as origin] length]
(let [x2 (+ x1 length)