Skip to content

Instantly share code, notes, and snippets.


Javier Neira jneira

View GitHub Profile
View RandomWalk.hs
{-# 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)
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,
(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
[compojure.http routes servlet helpers]
[clojure.contrib def str-utils duck-streams])
[clojure.contrib.logging :as log])
[ 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 [ File]
[java.util HashMap]
[ ApiProxy ApiProxy$Environment]
View member-of-2.scm
(define (member-of-2? a lst1 lst2)
(if (or (null? lst1) (null? lst2)) #f
(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
(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
(fn sub [c]
(let [gt (comp last sort)
res (gt
(fn [[x y] n]
(if (> n (last y))
[x (conj y n)]
[(gt [x y])
View jneira-4clojure-solution59.clj
;; jneira's solution to
(fn [& fs] (fn [& args] (for [f fs] (apply f args))))