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
#!/bin/sh | |
# change paths according to your repl setup | |
USER_HOME="/Users/antonio.garrote" | |
CLJR_HOME="/Users/antonio.garrote/.cljr" | |
CLASSPATH=src:test:. | |
if [ ! -n "$JVM_OPTS" ]; then | |
JVM_OPTS="-Xmx1G" | |
fi |
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
;; amalloy's solution to http://4clojure.com/problem/53 | |
(let [less (partial apply <)] | |
(fn [coll] | |
(if-let [pairs | |
(seq (->> coll | |
(partition 2 1) | |
(partition-by less) | |
(filter (comp less first))))] | |
(apply cons |
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/58 | |
(fn compon | |
([f] f) | |
([f1 & fs] | |
(fn [& xs] | |
(let [res (apply | |
(apply compon fs) xs)] | |
(f1 res))))) |
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 helloclosure | |
(:require [goog.net.Jsonp :as jsonp])) | |
(defn show [msg] | |
(let [data-as-json ((js* "JSON.stringify") msg nil 4)] | |
((js* "alert") data-as-json))) | |
(defn doajax [] | |
(.send (goog.net.Jsonp. (goog.Uri. "http://api.stackoverflow.com/1.1/users/268619") "jsonp") | |
nil |
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
(defn jsArr | |
"Recursively converts a sequential object into a JavaScript array" | |
[seq] | |
(.array (vec (map #(if (sequential? %) (jsArr %) %) | |
seq)))) | |
(defn jsObj | |
"Convert a clojure map into a JavaScript object" | |
[obj] | |
(.strobj (into {} (map (fn [[k v]] |
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
/* Son objetivos fundamentales: | |
* - Minimizar las funciones ECMAScript utilizadas | |
* - Optimizar en espacio, evitando la creación de arrays transitorios | |
* | |
* Suponemos que no se utilizará esta función con arrays creados | |
* en frames externos, con lo cual instanceof Array es seguro | |
*/ | |
function aplaneitor(soa,acu) { | |
if (soa instanceof Array) { |
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
-- A simple definition without using any fancy functions. | |
haskell>let ifMaybe pred value = if pred value then Just value else Nothing | |
haskell>:t ifMaybe | |
ifMaybe :: (a -> Bool) -> a -> Maybe a | |
haskell>ifMaybe (const True) 2 | |
Just 2 | |
haskell>ifMaybe (const False) 2 | |
Nothing | |
-- Using functions from standard library. |
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
LazyGenerator.from 1..10 where { it < 3 } transform { it * idx++ } using idx:0 each { | |
println "Transformed Range $it" | |
} | |
LazyGenerator.from x:1..5, y:2..5 where { ( x + y ) % ( x + 2 ) == 0 } eachWithIndex { match, idx -> | |
println "$idx) $match" | |
} | |
LazyGenerator.from 1..10 each { | |
println "Range: $it" |
OlderNewer