Skip to content

Instantly share code, notes, and snippets.

Avatar

Herwig Hochleitner bendlas

  • Austria
View GitHub Profile
View timer.clj
(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."
View Fix for checked esceptions
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();
View Swank_clojure_setup_for_hardcore_Emacs_users.el
;; 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 Dec 2, 2010
test case for clojureql
View gist:726251
(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 Dec 4, 2010
Case for wrapped exception issue
View gist:728427
(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 Jan 3, 2011
First stab at a WITH RECURSIVE construct for ClojureQL
View gist:763393
;; 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
View gist:772953
(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
View testbed.c
#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 Oct 18, 2011
A wrapper to use ediff-merge-files as a system merge tool
View emacs-merge-into
#!/bin/zsh
if [ ${#argv} -eq 3 ]; then
emacs -Q -nw --eval "(ediff-merge-files \"$2\" \"$3\" nil \"$1\")"
exit $?
View sicp.clj
(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]