This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inject = function(iterable, initial, func) { | |
var cur = initial | |
for(var i = 0;i < iterable.length;i++) { | |
cur = func(cur, iterable[i]) | |
} | |
return cur | |
} | |
var map = function(arr, func) { | |
return inject(arr, [], function(memo, val) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro extend-fn [name args & body] | |
`(let [old-fn# (var-get (var ~name)) | |
new-fn# (fn [& p#] | |
(let [~args p#] | |
(do ~@body))) | |
wrapper# (fn [& params#] | |
(if (= ~(count args) (count params#)) | |
(apply new-fn# params#) | |
(apply old-fn# params#)))] | |
(alter-var-root (var ~name) (constantly wrapper#)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;from clojure.contrib.seq-utils | |
;;'flatten' written by Rich Hickey, | |
;;see http://groups.google.com/group/clojure/msg/385098fabfcaad9b | |
(defn flatten [x] | |
(filter (complement sequential?) | |
(rest (tree-seq sequential? seq x)))) | |
;aprox. translate from paul graham's on lisp to clojure | |
(defn flatten-ol [x] | |
(letfn [(rec [x acc] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn backtracking [solution? explore node] | |
(if (solution? node) [node] | |
(mapcat | |
#(backtracking solution? explore %1) | |
(explore node)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn in-range? [vec coords] | |
(boolean | |
(reduce #(and | |
(vector? %1) | |
(> (count %1) %2) | |
(%1 %2)) | |
vec coords))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol TradeTax | |
(trade-tax [trade logic])) | |
(defprotocol Commission | |
(commission [trade logic])) | |
(defrecord Trade [ref-no account instrument principal tax-fees | |
unit-price quantity]) | |
(defn calculate-tax [{:keys [principal]} logic] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.freiheit.clojure.appengine.appengine-local | |
(:use | |
[compojure.http routes servlet helpers] | |
clojure.contrib.test-is | |
compojure.server.jetty | |
[clojure.contrib def str-utils duck-streams]) | |
(:require | |
[clojure.contrib.logging :as log]) | |
(:import | |
[com.google.appengine.api.labs.taskqueue.dev LocalTaskQueue] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns mygae.core | |
(:gen-class :extends javax.servlet.http.HttpServlet) | |
(:use compojure.core | |
ring.util.servlet | |
ring.adapter.jetty) | |
(:require [compojure.route :as route])) | |
(defroutes example | |
(GET "/" [] "<h1>Hello World Wide Web</h1>") | |
(route/not-found "Page not found")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns local-dev | |
"Tools for local development. | |
Enables the use of the App Engine APIs on the REPL and in a local Jetty instance." | |
(:use ring.adapter.jetty | |
[ring.middleware file file-info]) | |
(:import [java.io File] | |
[java.util HashMap] | |
[com.google.apphosting.api ApiProxy ApiProxy$Environment] | |
[com.google.appengine.tools.development | |
ApiProxyLocalFactory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns alien-nums | |
(:require (clojure.contrib [combinatorics :as comb :only cartesian-product] | |
[seq-utils :as seq-utils :only indexed]))) | |
(defn leading-zero? [lang num] | |
(= (first num) (first lang))) | |
(defn generate-nums [lang] | |
(when-let [lst (map list lang)] | |
(let [fcp #(map flatten |
OlderNewer