Skip to content

Instantly share code, notes, and snippets.

@devn
devn / cannot recur across try.clj
Created November 21, 2011 05:24
Cannot recur across try
(defn property*
"The property* driver handles the work when testing a property. It
expects:
* a descriptive message for failure reporting
* a list of locals (also for reporting)
* a generator which takes the scaled size and returns the input
for the property
* the property test in form of a function of the generated
input."
{:added "2.0"}
@devn
devn / org-remember-templates.el
Created November 29, 2011 16:41
org-remember-templates.el
(setq org-remember-templates
(quote
(("todo" ?t "* TODO %?\n %u\n %a" "~/Dropbox/org/gtd.org" bottom nil)
("note" ?n "* %?\n :NOTE:\n %u\n %a" "~/Dropbox/org/gtd.org" bottom nil)
("journal" ?j "* %U %?" "~/Dropbox/org/journal.org" 'top nil))))
Originally:
https://gist.github.com/7565976a89d5da1511ce
Hi Donald (and Martin),
Thanks for pinging me; it's nice to know Typesafe is keeping tabs on this, and I
appreciate the tone. This is a Yegge-long response, but given that you and
Martin are the two people best-situated to do anything about this, I'd rather
err on the side of giving you too much to think about. I realize I'm being very
critical of something in which you've invested a great deal (both financially
@devn
devn / fm.clj
Created December 9, 2011 04:46 — forked from harold/fm.clj
(definst fm [carrier 440 divisor 2.0 depth 1.0]
(let [modulator (/ carrier divisor)
mod-env (env-gen (lin-env 1 0 1))
amp-env (env-gen (lin-env 0 1 1))]
(* amp-env
(sin-osc (+ carrier
(* mod-env (* carrier depth) (sin-osc modulator)))))))
; Some of these are more or less interesting
(fm)
@devn
devn / jquerytest.cljs
Created December 16, 2011 06:01 — forked from ryancrum/jquerytest.cljs
How to use jQuery from ClojureScript
(ns jquerytest.core)
(def jquery (js* "$"))
(jquery
(fn []
(-> (jquery "div.meat")
(.html "This is a test.")
(.append "<div>Look here!</div>"))))
@devn
devn / gist:1624324
Created January 17, 2012 03:11
clojure and slime tweaks
;; Hide slime version mismatches
(setq slime-protocol-version 'ignore)
;; More syntax coloring
(defun tweak-clojure-syntax (mode)
(mapcar (lambda (x) (font-lock-add-keywords mode x))
'((("#?['`]*(\\|)" . 'clojure-parens))
(("#?\\^?{\\|}" . 'clojure-braces))
(("\\[\\|\\]" . 'clojure-brackets))
((":\\w+" . 'clojure-keyword))
@devn
devn / lithp.rb
Created January 26, 2012 04:07 — forked from fogus/lithp.rb
class Lisp
def initialize
@env = {
:label => lambda { |(name,val), _| @env[name] = val },
:quote => lambda { |sexpr, _| sexpr[0] },
:car => lambda { |(list), _| list[0] },
:cdr => lambda { |(list), _| list.drop 1 },
:cons => lambda { |(e,cell), _| [e] + cell },
:eq => lambda { |(l,r), _| l == r },
:if => lambda { |(cond, thn, els), ctx| eval(cond, ctx) ? eval(thn, ctx) : eval(els, ctx) },
@devn
devn / numbers-to-english.clj
Created January 27, 2012 22:31
numbers to english in clojure
(ns quiz.core
(:require [clojure.pprint :as pp]))
(defn to-english [n]
(pp/cl-format nil "~@(~@[~R~]~^ ~A.~)" n))
(to-english 99999999999999999)
;=> "Ninety-nine quadrillion, nine hundred ninety-nine trillion, nine hundred ninety-nine billion, nine hundred ninety-nine million, nine hundred ninety-nine thousand, nine hundred ninety-nine"
(map to-english (range 0 101))
@devn
devn / foo.rb
Created February 10, 2012 21:49 — forked from manveru/foo.rb
class Hash
def true_of?(key, &block)
TrueOf.new(self, key).instance_eval(&block)
end
end
class TrueOf
attr_reader :key, :value
def initialize(hash, key, &block)
@devn
devn / gist:1849788
Created February 17, 2012 02:00
Your Very Own Object System
Point = -> (x, y) {
methods =
Hash[:x, -> { x },
:y, -> { Math.sqrt(x*x + y*y) },
:shift!, ->(xinc, yinc)
{ x += xinc
y += yinc }]
->(message, *args) { methods[message].(*args)
}
}