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 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 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 member-of-2.scm
(define (member-of-2? a lst1 lst2)
(if (or (null? lst1) (null? lst2)) #f
(or
(and (eq? a (car lst1))
(or (eq? a (car lst2))
(member-of-2? a (list a) (cdr lst2))))
(member-of-2? a (cdr lst1) lst2))))
View greed.clj
;; Ultimo commit con propuestas brillantes de http://twitter.com/_ogf_
(defn score-single [ps]
(case ps 1 100 5 50 0))
(defn score-triple [ps]
(case ps 1 1000 (* ps 100)))
(defn scores-by-freq [[ps freq]]
[(* (quot freq 3)
(score-triple ps))
View jneira-4clojure-solution53.clj
;; jneira's solution to http://4clojure.com/problem/53
(fn sub [c]
(let [gt (comp last sort)
res (gt
(reduce
(fn [[x y] n]
(if (> n (last y))
[x (conj y n)]
[(gt [x y])
View jneira-4clojure-solution59.clj
;; jneira's solution to http://4clojure.com/problem/59
(fn [& fs] (fn [& args] (for [f fs] (apply f args))))
View jneira-4clojure-solution63.clj
;; jneira's solution to http://4clojure.com/problem/63
(fn [f c] (reduce (fn [m n] (merge-with into m {(f n) [n]})) {} c))