Skip to content

Instantly share code, notes, and snippets.

View ejackson's full-sized avatar

Edmund Jackson ejackson

  • UnityAI
  • Nashville, TN
View GitHub Profile
~/scratch/clojurescript$ ./script/bootstrap
Fetching Clojure...
Copying clojure-1.3.0/clojure-1.3.0.jar to lib/clojure.jar...
Cleaning up Clojure directory...
Cleaning up Clojure archive...
Fetching Google Closure library...
Cleaning up Google Closure library archive...
Fetching Google Closure compiler...
Cleaning up Google Closure compiler archive...
Building lib/goog.jar...
(defn- ipred [[k v]]
(pred/like k v))
(defn- partial-pred [m]
"Turn a map into a predicate format understood by cql. IE {:a 1 :b 2} --> (pred/and* (pred/=* :a 1) (pred/=* :b 2))"
(apply pred/and* (map ipred m)))
(defprotocol MapFindable
"A protocol for clojureQL searchable things that can be found using a map interface"
(find [this search-map]))
(ns relation.test.relation
(:require [relation.relation :as rel]
[relation.database :as db]
[clojureql.core :as cql])
(:use [clojure.test]))
(defmacro my-macro
[x]
`~(reverse x))
<build>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>test-clojure</id>
@ejackson
ejackson / database.clj
Created August 28, 2011 18:53
Basic Clojure interaction with SQL
(ns bookkeeper.database
(:require [clojure.java.jdbc :as sql]
[clj-time.format :as f]))
(def db {:classname "com.mysql.jdbc.Driver"
:subprotocol "mysql"
:subname "//database-server:3306/database"
:user "user"
:password "password"})
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
(eval-after-load 'clojure-mode
'(progn
(require 'paredit)
(defun clojure-paredit-hook () (paredit-mode +1))
(add-hook 'clojure-mode-hook 'clojure-paredit-hook)
(define-key clojure-mode-map "{" 'paredit-open-brace)
(define-key clojure-mode-map "}" 'paredit-close-brace)))
@ejackson
ejackson / gist:962673
Created May 9, 2011 14:59
RIncanter.project.clj
(defproject com.evocomputing/rincanter
"1.0.0-SNAPSHOT"
:description "Clojure/R integration using rosuda JRIEngine"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[incanter "1.2.3"]]
:native-dependencies [[jriengine "0.8.4"]]
@ejackson
ejackson / nothing.html
Created April 20, 2011 21:15
nothing.html
<h1>Introduction</h1>
This is a brief post about how laziness can be used to construct a step-wise quicksort, or somebody gets excited about laziness.
<P>
Laziness is not something I'd come across before Clojure, and I've been repeatedly bitten by forgetting about it. So it was a real pleasure the other day to see the laziness revealed in some code, and for once not have this as the result of protracted debugging. I was so taken aback that I'm sharing the experience.
<h1>Quicksort</h1>
<h2>The Algo</h2>
We all know the <a href="http://en.wikipedia.org/wiki/Quicksort">algorithm</a>, and <a href="http://bilfp.wikidot.com/why-functional-programming-matters">here's</a> a pretty Clojure implementation:
<pre class="brush:Clojure">
(defn qsort [[pivot & tail]]
@ejackson
ejackson / gist:911386
Created April 9, 2011 13:08
binding over map function
(declare *connection*)
(defn it-works []
(binding [*connection* "hello, world"]
(prn *connection*)))
(defn it-works-now []
(binding [*connection* "hello, world"]
(map
(bound-fn [_] (prn *connection*))