Skip to content

Instantly share code, notes, and snippets.

View bendlas's full-sized avatar

Herwig Hochleitner bendlas

View GitHub Profile
(ns timer
(:import [java.util Timer TimerTask]))
(def the-timer (Timer.))
(defn timer
"Schedules a callback for delayed execution.
Returns a function, that accepts a parameter:
:bump to restart the timer, returning true only if timer was active, hence was extended by that call
:cancel to abort the timer, returning true only if timer was active, hence was canceled b.t.c."
import java.io.*;
class ExceptionAdapter extends RuntimeException {
private final String stackTrace;
public Exception originalException;
public ExceptionAdapter(Exception e) {
super(e.toString());
originalException = e;
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
stackTrace = sw.toString();
;; First fetch CVS version of slime, git version of clojure, swank-clojure, clojure-contrib and clojure-mode
;; Create ~/bin/clojure script which starts clojure repl and adds clojure-contrib src dir and swank-clojure src dir to classpath. I used clj-env helper from clojure-contrib
(pushnew '("\.clj$" . clojure-mode) auto-mode-alist)
(require 'clojure-mode)
;;;; Slime configuration stuff
(setf slime-lisp-implementations
'((ecl("~/bin/ecl" "--heap-size" "1024000000") :coding-system utf-8-unix)
@bendlas
bendlas / gist:726251
Created December 2, 2010 22:47
test case for clojureql
(use 'clojureql.core)
(def users (project (table server/*db* :user_view)
[:user_id
:lname :fname]))
(def groups (aggregate
(join (table server/*db* :groups)
(table :user_groups)
:group_id)
@bendlas
bendlas / gist:728427
Created December 4, 2010 19:47
Case for wrapped exception issue
(ns wrap.fail)
(defn failing []
(throw (IndexOutOfBoundsException. "Failed")))
(defn wrappy []
(try
(failing)
(catch Throwable e
(throw (IllegalArgumentException. "Wrapped Fail" e)))))
@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]