Skip to content

Instantly share code, notes, and snippets.

View bendlas's full-sized avatar

Herwig Hochleitner bendlas

  • Austria
View GitHub Profile
@bendlas
bendlas / ast.clj
Created January 13, 2012 20:25
An intermedient version of a new frontend for CQL
(ns ast
(:use [clojure.core.match :only [match]] )
(:require [clojureql.predicates :as pred]))
(comment These protocols are from a former iteration. They capture the intention pretty well
and might be reintroduced, as soon the format is stable.
(defprotocol SqlCompilable
(render [this] "Sequence of strings that represent the prepared statement")
(param-count [this] "Number of positional parameters in expression or relation")
(label [this] "Canonical label of expression or relation"))
(defn jit-memoize [query-fn]
(let [cache-agent (agent {})]
(letfn
[(add-listener [queries parameter callback]
(if-let [listeners (queries parameter)]
(assoc queries parameter
(cons callback listeners))
(add-query queries parameter callback)))
(add-query [queries parameter callback]
(future (send cache-agent
@bendlas
bendlas / select.clj
Last active December 13, 2015 16:48
This is a draft of the current production state of my clojurescript enlive port. From the other end, I'm factoring enlive, so that its engine can work on any tree. That should enable a lot of shared code between a clj and a cljs version.
;; The macros
;; most macros here alias names from select.cljs
;; they will get used in regular calls
(ns lib.select
(:require
[clojure.string :as str]))
;; selector syntax
(defn intersection [preds]
@bendlas
bendlas / predicate.clj
Created February 13, 2013 07:00
This file is not part of the cljs port as of yet, but a tidbit from my enlive cleanup effort It shows how to implement CSS3 operations in terms of zippers, in that form it should be trivial to adapt to the DOM it's basically the predicates library from enlive, but lifted to a zipper level, so that it can work generically
(ns workbench.enlive.predicate
(:require
[clojure.zip :as z]
[workbench.enlive.engine
:refer [compile-step]]
[workbench.enlive.select
:refer [zip-select]]))
;; ## Builtin predicates
;;
(let [m {0 :z 1 :o 2 :t 3 :th}]
(run* [q]
(fresh [r]
(fd/in r (fd/interval 1 2))
(featurec m {r q}))))
From 85fd5c4f3c20c1a557c2da7d06b0c1b41e9533f9 Mon Sep 17 00:00:00 2001
From: Herwig Hochleitner <hhochleitner@gmail.com>
Date: Mon, 11 Mar 2013 03:57:43 +0100
Subject: [PATCH] Throw exception instead of trying to throw string in
defmulti compiler macro
---
src/clj/cljs/core.clj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(def path-cache (atom {}))
(defn load-cached [path]
(if-let [ret (get @path-cache path)]
ret
(let [ret (cell nil)]
(swap! path-cache assoc path ret)
(XhrIo/send path
(fn [e]
(case (.. e -target getStatus)
@bendlas
bendlas / curry.clj
Created April 15, 2013 17:26
A macro that allows to define a function with one arity, that gets curried. You can call the curried function with any number of arguments at a time.
(ns util.curry)
(defn feed-curry [f arg args]
(if (pos? (count args))
(recur (f arg) (first args) (rest args))
(f arg)))
(defn- curried-fn-body [name args body]
{:pre [(pos? (count args))]}
(let [arg (first args)
@bendlas
bendlas / current_master.js
Last active December 17, 2015 19:59
Generated code for PersistentArrayMap with advanced optimizations on branch specify vs current master
function $cljs$core$PersistentArrayMap$$($meta$$20$$, $cnt$$9$$, $arr$$73$$, $__hash$$11$$) {
this.$meta$ = $meta$$20$$;
this.$cnt$ = $cnt$$9$$;
this.$arr$ = $arr$$73$$;
this.$__hash$ = $__hash$$11$$;
this.$cljs$lang$protocol_mask$partition1$$ = 4;
this.$cljs$lang$protocol_mask$partition0$$ = 16123663
}
$JSCompiler_prototypeAlias$$ = $cljs$core$PersistentArrayMap$$.prototype;
$JSCompiler_prototypeAlias$$.$cljs$core$IEditableCollection$_as_transient$arity$1$ = function $$JSCompiler_prototypeAlias$$$$cljs$core$IEditableCollection$_as_transient$arity$1$$() {
(ns dev
(:require
cemerick.austin cemerick.austin.repls webnf.server
[net.cgrand.enlive-html :refer [deftemplate content set-attr]]
[net.cgrand.moustache :refer [app]]
[ring.util.response :refer [not-found]]
[ring.middleware.file :refer [wrap-file]]))
(def repl-env)