Skip to content

Instantly share code, notes, and snippets.

View tomfaulhaber's full-sized avatar

Tom Faulhaber tomfaulhaber

View GitHub Profile
<h1>Sparkly Corn Soup</h1>
<p>Recipe #1:</p>
<p>Here's the recipe:</p>
<ul>
<li>First you put something sparkly</li>
<li>Then, you put some corn</li>
<li>Then, you put some cinnamon</li>
(def #^{:doc "Ignore stack traces from these patterns"}ignore-files
[".*\\.java" "swank-clojure\\.clj" "boot\\.clj" "unit_test\\.clj"])
(defn filter-stacktrace
"Filters a stacktrace removing file patterns defined in ignore-files."
[t]
(let [es (to-list (. t getStackTrace))
top (take-while #(not (.contains (.getClassName %) "unit_test$run_test__")) es)
cljs (filter (comp not nil? (memfn getFileName)) top)
(ns wrap-base
(:use [clojure.contrib.pprint :only (cl-format pprint)]))
(def *print-base* 10)
;;; borrowed frm cl-format
(defn- integral?
"returns true if a number is actually an integer (that is, has no fractional part)"
[x]
(cond
@tomfaulhaber
tomfaulhaber / arity.clj
Created January 10, 2010 06:25
A chunk of clojure code that allows you to extend a function def with new argument lists
(ns arity)
(defn make-proxy-args [n] (map #(gensym (str "a" (char (+ 48 %)) "-")) (range n)))
(defn make-proxy-decl [old-f-sym n]
(let [proxy-args (make-proxy-args n)]
`([~@proxy-args]
(apply ~old-f-sym ~(apply vector proxy-args)))))
@tomfaulhaber
tomfaulhaber / yank-visible.el
Created August 11, 2010 20:06
An emacs lisp function to yank visible text from an outline mode buffer so you can paste it somewhere else. Based on org-export-visible.
(defun outline-copy-visible (keepp)
"Create a copy of the visible part of the current buffer and add
it to the kill ring so it can be copied into other buffers or programs.
The copy is created in a temporary buffer and removed after use.
As a special case, if you have a prefix arg KEEPP, the temporary
buffer will not be removed but presented to you so that you can
continue to use it.
This function is derived from org-export-visible."
(interactive "P")
(let* ((file buffer-file-name)
tom@monet:~/src/clj/dashboard$ lein deps
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.pom from central
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.pom from clojure
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.pom from clojure-snapshots
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.pom from clojars
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.pom from central
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.jar from central
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.jar from clojure
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.jar from clojure-snapshots
Downloading: org/apache/xmlrpc/xmlrc/3.1.3/xmlrc-3.1.3.jar from clojars
@tomfaulhaber
tomfaulhaber / gist:955623
Created May 4, 2011 17:29
Multi-line, multi-lambdas in coffeescript?
# I want to be able to spread multiple lambda args across multiple lines, but
# I'm unclear on the syntax
# The following gives me
# "Error: In XXX/dashboard.coffee, Parse error on line 125: Unexpected ','"
# whether I put it on one line or multiple lines.
$("ul.topnav > li").hover(
( -> $(this).find("span").addClass "subhover"),
( -> $(this).find("span").removeClass "subhover"))
@tomfaulhaber
tomfaulhaber / gist:1338547
Created November 4, 2011 02:44
Paredit setup
(autoload 'paredit-mode "paredit" "Parenthesis editing minor mode" t)
(eval-after-load "clojure-mode"
'(progn
(defun clojure-paredit-hook () (paredit-mode +1))
(add-hook 'clojure-mode-hook 'clojure-paredit-hook)
(defun clojure-indent-hook ()
(define-clojure-indent (clone-for 1) (at 1)))
(add-hook 'clojure-mode-hook 'clojure-indent-hook)
@tomfaulhaber
tomfaulhaber / gist:1572651
Created January 6, 2012 22:13
Slamhound crashing on autodoc
tom@renoir:~/src/clj/autodoc-release$ lein slamhound src/autodoc/build_html.clj
Warning: *debug* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherw\
ise. Please either indicate ^:dynamic *debug* or change the name.
Warning: *swank-source-path* not declared dynamic and thus is not dynamically rebindable, but its name sug\
gests otherwise. Please either indicate ^:dynamic *swank-source-path* or change the name.
Warning: *swank-source-path* not declared dynamic and thus is not dynamically rebindable, but its name sug\
gests otherwise. Please either indicate ^:dynamic *swank-source-path* or change the name.
Warning: *swank-compile-path* not declared dynamic and thus is not dynamically rebindable, but its name su\
ggests otherwise. Please either indicate ^:dynamic *swank-compile-path* or change the name.
Warning: *swank-compile-path* not declared dynamic a
@tomfaulhaber
tomfaulhaber / gist:1906914
Created February 25, 2012 06:28
Simple pprint on a deftype
user> (deftype Foo [a b c])
user.Foo
user> (def f (Foo. "The quick brown fox jumped over the" "lazy dog" "Friends, Romans, and Countrymen, lend me your ears")) │····
#'user/f
user> (def e (Foo. 1 2 3))
#'user/e
user> (defn augmented-dispatch [f]
(if (instance? Foo f)
(cl-format true
"~<{~;~<a ~_~w~:>, ~_~<b ~_~w~:>, ~_~<c ~_~w~:>~;}~:>"