Skip to content

Instantly share code, notes, and snippets.

@dakrone
dakrone / project.clj
Created February 16, 2012 18:01
lein-multi functionality with lein ver.2 profiles
∴ lein2 all test
Performing task 'test' with profile(s): 'dev,1.2'
Testing clj-http.test.client
Testing clj-http.test.cookies
Testing clj-http.test.core
Ran 47 tests containing 175 assertions.
@swannodette
swannodette / spectral_norm.cljs
Last active October 3, 2015 00:37
spectral_norm_alioth.js
function A(i,j) {
return 1/((i+j)*(i+j+1)/2+i+1);
}
function Au(u,v) {
for (var i=0; i<u.length; ++i) {
var t = 0;
for (var j=0; j<u.length; ++j)
t += A(i,j) * u[j];
v[i] = t;
@jamii
jamii / gist:2400297
Created April 16, 2012 17:50
(Slightly less) crude (monotonic) datalog interpreter
(ns mist.logic.datalog
(:use clojure.core.logic
[clojure.set :only [union, difference]])
(:require clojure.walk))
(defn- all-o [goal args]
(conde
[(emptyo args)]
[(fresh [arg rest]
(conso arg rest args)
@alandipert
alandipert / rubyuse.rb
Created May 4, 2012 23:44
A different way to organize Ruby code
class Ns
def initialize
use.each do |pkg, method_names|
method_names.each do |name|
self.class.send(:define_method, name) do |*args|
pkg.method(name).call(*args)
end
end
end
end
@swannodette
swannodette / gist:2719676
Created May 17, 2012 15:35
unify_datums.clj
(ns datomic-play.core
(:use [datomic.api :only [db q] :as d])
(:require [clojure.core.logic :as l]
[clojure.pprint :as pp]))
(def uri "datomic:dev://localhost:4334/hello")
(defprotocol IUnifyWithDatum
(unify-with-datum [u v s]))
@lambda-fairy
lambda-fairy / Fold.hs
Created May 27, 2012 07:44
Data.List.Fold - fold lists in constant space
-- | Lock-step folding.
--
-- This module presents an elegant way of executing multiple left folds
-- on one list using constant memory. For example, the mean can be
-- expressed as:
--
-- @
-- average = foldLeft $ (/) <$> sumF <*> lengthF
-- @
(def users [{:name "Brian" :age 22} {:name "Ben" :age 19}])
;; Takes a "path", returns a function that takes an "object" and
;; returns a "costate"
(defn lens [p]
(fn [o]
{:get (get-in o p)
:set #(assoc-in o p %1)}))
(def myAgeLens (lens [0 :age]))
@frenchy64
frenchy64 / fbound.clj
Created August 10, 2012 13:52
F-bounded Polymorphism in Typed Clojure
; y has upper bound x, z has upper bound (Seqable y)
typed.core=> (ann foo (All [x [y :< x] [z :< (Seqable y)]]
[x y z -> Any]))
[typed.core/foo (All [x [y :< x] [z :< (clojure.lang.Seqable y)]] (Fn [x y z -> Any]))]
typed.core=> (declare foo)
#'typed.core/foo
;cf = check-form
typed.core=> (cf (foo 2 2 [2]))
Any
@hugoduncan
hugoduncan / gist:4138017
Created November 24, 2012 01:49
lb being called on :clojure.core.logic/not-found
No implementation of method: :lb of protocol: #'clojure.core.logic/IInterval found for class: clojure.lang.Keyword
java.lang.IllegalArgumentException
Restarts:
0: [CONTINUE] Pass exception to program
1: [ABORT] Abort request.
2: [IGNORE] Do not enter debugger for this exception type
3: [IGNORE-MSG] Do not enter debugger for this exception message
4: [IGNORE-CATCH] Do not enter debugger for exceptions with catch location clojure.lang.LazySeq.*
5: [IGNORE-LOC] Do not enter debugger for exceptions with throw location clojure.core.*
@cgrand
cgrand / foami.clj
Last active October 25, 2015 18:32
(ns foami.core
"FOreign Asynchronous Mechanism Interop"
(:require [clojure.core.async :as async]))
(def ^:private abandon (doto (async/chan) async/close!))
(def ^:private pending-writes (async/chan))
(defn put!
"Tries to put a val into chan, returns either: true if put succeeded, false if chan is