Skip to content

Instantly share code, notes, and snippets.


Javier Neira jneira

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,
(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]
#(backtracking solution? explore %1)
(explore node))))
View gist:480694
(defn in-range? [vec coords]
(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
[compojure.http routes servlet helpers]
[clojure.contrib def str-utils duck-streams])
[clojure.contrib.logging :as log])
[ LocalTaskQueue]
View mygae.clj
(ns mygae.core
(:gen-class :extends javax.servlet.http.HttpServlet)
(:use compojure.core
(: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 [ File]
[java.util HashMap]
[ ApiProxy ApiProxy$Environment]
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