Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Javier Neira jneira

:octocat:
View GitHub Profile
View gist:208935
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) {
View gist:273432
(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#))))
View flatten-versions.clj
;;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]
View gist:476004
(defn backtracking [solution? explore node]
(if (solution? node) [node]
(mapcat
#(backtracking solution? explore %1)
(explore node))))
View gist:480694
(defn in-range? [vec coords]
(boolean
(reduce #(and
(vector? %1)
(> (count %1) %2)
(%1 %2))
vec coords)))
View trade.clj
(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]
View appengine setup for clojure.clj
(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]
View mygae.clj
(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"))
View local_dev.clj
(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
View alien-nums.clj
(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