Skip to content

Instantly share code, notes, and snippets.

View jneira's full-sized avatar
:octocat:

Javier Neira jneira

:octocat:
View GitHub Profile
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.Trans (lift)
import Control.Parallel (par, pseq)
import Data.Text.Lazy (pack)
import System.Random (StdGen, newStdGen, random)
import Web.Scotty (get, scotty, text)
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) {
(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#))))
;;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]
(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]
(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
(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))))
@jneira
jneira / greed.clj
Created January 5, 2011 20:00 — forked from xaviuzz/greed.rb
;; 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))
;; 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])
;; jneira's solution to http://4clojure.com/problem/59
(fn [& fs] (fn [& args] (for [f fs] (apply f args))))