Skip to content

Instantly share code, notes, and snippets.

@abp
abp / gist:3219885
Created July 31, 2012 19:43 — forked from swannodette/gist:3217582
sudoku_compact.clj
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [grid x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in grid [x y])))
(defn init [grid [pos value]]
@abp
abp / gist:3213464
Created July 31, 2012 04:01 — forked from swannodette/gist:3213107
sudoku.clj
(defn distincto [s]
(if (seq s)
(all
(distinctfd (first s))
(distincto (next s)))
s#))
(defn all-infd [xs d]
(if (seq xs)
(all
(use '[datomic.api :only [db q] :as d])
(def schema
[{:db/doc "A persons name"
:db/id #db/id[:db.part/db]
:db/ident :name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
(ns barker.client.main
(:require [barker.client.render :as render]
[barker.client.search :as search]
[shoreleave.client.common :as common]
[shoreleave.client.history :as history]
[shoreleave.client.pubsubs.simple :as pbus]
[shoreleave.client.pubsubs.protocols :as pubsub]
[shoreleave.client.worker :as swk]
)
(:use [jayq.core :only [$ attr]])
(ns barker.client.search
(:require [clojure.string :as cstr]
[shoreleave.client.services.geo :as geo]
[shoreleave.client.remote :as remote])
(:use [jayq.core :only [$ inner]]))
(defn query->map [search-query]
(let [[topic location] (map cstr/trim (cstr/split search-query #" near "))
zip (when (re-find #"\d" location) location)] ;if we see an digit, we assume it's some kind of zip
{:raw-query search-query :topic topic :location location :zip zip}))
@abp
abp / two-useful-macros.clj
Created June 30, 2012 05:38 — forked from rplevy/two-useful-macros.clj
with and within
(defmacro with
"do things with the first expression passed,
and produce the result"
[expr & body]
`(let [~'% ~expr] ~@body))
(defmacro within
"do things with the first expression passed (for side effects),
but produce the value of the first expression"
[expr & body]
@abp
abp / automath.clj
Created June 29, 2012 06:18 — forked from fogus/automath.clj
Namespace of functions that are proxies for methods on java.lang.Math for maximum developer convenience.
(ns automath
"Namespace of functions that are proxies for methods on
java.lang.Math for maximum developer convenience."
(:use [clojure.string :only (lower-case)]))
(def ^{:private true
:doc "Set of method names not to generate a proxy function for."}
exclusions #{"min" "max"})
(defn- methods-in
@abp
abp / twip.c
Created June 27, 2012 21:32 — forked from fogus/twip.c
/* The whole point of the twIP stack is to respond to pings. This is
done by reading one IP packet at a time, hoping that it is an IP
ping packet (no check is made!), changing the packet type to a ping
reply packet, updating the ICMP checksum, swapping the IP source
and destination addresses, and sending the packet back. That's
it.
*/
/* This is the packet buffer. I chose the size of the array so that
the maximum packet size that twIP would support would be the same
@abp
abp / clojure-match.clj
Created June 16, 2012 21:37 — forked from ckirkendall/clojure-match.clj
Language Compare F#, Ocaml, Scala, Clojure and Haskell
(use '[clojure.core.match :only [match]])
(defn evaluate [env exp]
(match [exp]
[(['Number a] :seq)] a
[(['Add x y] :seq)] (+ (evaluate env x) (evaluate env y))
[(['Multiply x y] :seq)] (* (evaluate env x) (evaluate env y))
[(['Variable i] :seq)] (env i)))
(def environment {"a" 3, "b" 4, "c" 5})
@abp
abp / lens.clj
Created May 30, 2012 11:25 — forked from fogus/lens.clj
(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]))