Skip to content

Instantly share code, notes, and snippets.

View aboekhoff's full-sized avatar

Andrew Boekhoff aboekhoff

  • DemandingBear
  • San Francisco
View GitHub Profile
;;;; *very* quick and dirty support for javascript destructuring on
;;;; native javascript arrays and objects
(add-inline-form
get [[_ a b c]]
(str "((" a "[" b "]" ")||" c ")"))
(add-inline-form
nth [[_ a b]]
(str a "[" b "]"))
(add-inline-form
var jury;
jury || (jury = {});
if(!jury.destro)jury.destro = {};
(function() {
jury.destro.foo = function(b, a) {
if(arguments.length !== 2)throw"required arity is 2";var h, c;
c = b["that-thingy"] || "bar";
var d;
d = b["this-thingy"] || "foo";
var e;
@aboekhoff
aboekhoff / gist:274828
Created January 12, 2010 02:41
dynamic session middleware
(ns #^{:doc "A handful of utilities for handling sessions"}
somnium.financier.app.control.session
(:refer-clojure :exclude (assoc! dissoc! get)))
;;;; declaring session var here for global-ish access to session
(def *session* {})
(def *flash* {})
(defn with-dynamic-session
;;;; point-free SHA1 hash
(import java.security.MessageDigest)
(defmacro >>
"(>> 1 2 3 4 5) => (2 3 4 5 1)"
[x & xs]
`(~@xs ~x))
(defn sha1 [#^String s]
(-> (doto (MessageDigest/getInstance "SHA1")
(defmacro defn-src
[& body]
`(alter-meta!
(defn ~@body)
assoc :defn-src (quote ~(cons 'defn body))))
(let [cursor (fetch-eager :where {... whatever ...})
res (transient [])]
(while (.hasNext cursor)
(conj! res (-> cursor .next .toClojure)))
(persistent! res))
;;
(deftype ConsType [_first _more] [ISeq] :as this
ISeq
(first ([] _first))
(next ([] (when (first _more) _more))
(seq ([] this))
(cons ([x] (ConsType. x this)))
(add-to-list 'swank-clojure-classpath (expand-file-name "classes/" path))
(add-to-list 'swank-clojure-classpath (expand-file-name "src/" path))
(add-to-list 'swank-clojure-classpath (expand-file-name "test/" path))
;; in swank-clojure.el
;; add resources to swank-clojure-project classpath
(add-to-list 'swank-clojure-classpath (expand-file-name "resources/" path))
(defmacro and-let
[bindings & body]
(if (seq bindings)
(let [[a b & cs] bindings]
`(when-let [~a ~b] (and-let ~cs ~@body)))
`(do ~@body))
lang.EmptyCons = {
first: function() {return null;},
rest: function() {return lang.EmptyCons;},
seq: function() {return null;},
toString: function() {return "()";}
}
lang.Cons = function(_first, _rest) {
if (!_rest) { _rest = lang.EmptyCons; }
this._first = _first;