Skip to content

Instantly share code, notes, and snippets.

View bendlas's full-sized avatar

Herwig Hochleitner bendlas

View GitHub Profile
@bendlas
bendlas / gist:763393
Created January 3, 2011 11:57
First stab at a WITH RECURSIVE construct for ClojureQL
;; http://www.postgresql.org/docs/9.0/static/queries-with.html
(defmacro with-recursive [rectable cols [start-relation union step-relation] body-relation]
;; store info in meta data, since compile doesn't dispatch on relation type
`(let [start# ~start-relation
~rectable (project (table ~(keyword (name rectable)))
~cols)
body# ~body-relation
step# ~step-relation
(ns gist
(:require [clojureql.core :as cql]))
(def schema-tables
(cql/select
(cql/table *db* :information_schema.tables)
(cql/where (= :table_schema "public"))))
(def table-columns
(cql/project
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
// defined in asma.s
unsigned char *asma(unsigned char *s);
unsigned char *asma_ref(unsigned char *s)
{
@bendlas
bendlas / emacs-merge-into
Created October 18, 2011 03:46
A wrapper to use ediff-merge-files as a system merge tool
#!/bin/zsh
if [ ${#argv} -eq 3 ]; then
emacs -Q -nw --eval "(ediff-merge-files \"$2\" \"$3\" nil \"$1\")"
exit $?
(defn fast-expt [b n]
(loop [acc 1
b b
n n]
(cond
(= n 0) acc
(even? n) (recur acc (* b b) (/ n 2))
:else (recur (* acc b) b (dec n)))))
(defn mult [a b]
@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 / on_data_readers.md
Last active October 1, 2015 05:39
On source code configuration in the clojure family of languages

statement of issue

The current requirement for defining a data_readers.clj at the source-path root makes creating libraries, that define reader-tags, cumbersome:

  • Users need to paste the library reader-tags into their data_readers.clj
  • Maintainers won't want to use reader tags in the library's own source, because users might forget to paste them
  • Shipping a data_readers.clj (like datomic does) bears the risk of libraries randomly clobbering each other (see lein-collisions)

Also other interactions arount reader tags could be improved:

@bendlas
bendlas / bendlas.clj
Created May 9, 2015 20:06
An experiment with collection updates
(ns user.bendlas
(:require [criterium.core :as crit]))
;; # Overview
;; ## Two new core operations
;; ### pretial -- partial for the first param
;; This is the main proposition: introduce an operation that lets one
Verifying that +bendlas is my blockchain ID. https://onename.com/bendlas