This file contains 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
{-# 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) |
This file contains 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 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 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 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 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 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
(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)))) |
This file contains 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
;; 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)) |
This file contains 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
;; 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]) |
This file contains 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
;; jneira's solution to http://4clojure.com/problem/59 | |
(fn [& fs] (fn [& args] (for [f fs] (apply f args)))) |
OlderNewer