Skip to content

Instantly share code, notes, and snippets.

View jneira's full-sized avatar
:octocat:

Javier Neira jneira

:octocat:
View GitHub Profile
#!/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
(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]
;; 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
;; 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/58
(fn compon
([f] f)
([f1 & fs]
(fn [& xs]
(let [res (apply
(apply compon fs) xs)]
(f1 res)))))
@mjg123
mjg123 / helloclosure.cljs
Created July 21, 2011 23:48
Same jsonp call as before but with gclosure instead of jQuery
(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
@lynaghk
lynaghk / gist:1141054
Created August 11, 2011 23:21
Clojure sequentials & maps into JavaScript arrays and objects
(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]]
/* 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) {
-- 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.
@timyates
timyates / LazyGenerator.groovy
Created April 20, 2012 14:04
LazyGenerator
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"