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 Exercitium.hs
a057531=[e | e<-[0..], (sum $ digits e) == (length $ divisors e)]
where divisors n=n:[i|i <- [1..n `div` 2], n `mod` i==0]
digits 0=[]
digits n=mod n 10: digits (div n 10)
*Exercitium> last $ takeWhile (<2015) a057531
*Exercitium> head $ dropWhile (<=2015) a057531
*Exercitium> length $ takeWhile (<=2015) a057531
View Timeout.purs
foreign import data Timeout :: !
type Milliseconds = Number
type WithTimeout eff = Eff (t :: Timeout | eff)
type ContTimeout eff = ContT Unit (WithTimeout eff)
setTimeoutCont :: forall eff. Milliseconds -> ContTimeout eff Unit
setTimeoutCont = ContT <<< setTimeout
View Spider.purs
-- Purescript tutorial 12.4 Exercise 4
module Spider where
import Files
import Data.Foreign
import Data.Foreign.Index
import Data.Either
import Data.Array
import Data.Traversable
import Data.Foldable
import Control.Monad.Eff
View Free.purs
type WithST h r = Eff (st:: ST h | r)
add :: forall h r. STRef h String -> String -> WithST h r String
add ref str = modifySTRef ref (++ str)
renderST :: Element -> String
renderST = pureST <<< renderElemST
renderElemST :: forall h r. Element -> WithST h r String
renderElemST e = do
public final class Correct<T> implements Result<T> {
private static final long serialVersionUID = 1L;
public final T value;
public Correct(T value) {
this.value = value;
View Bloomberg.hs
{-# LANGUAGE RecordWildCards #-}
module Bloomberg where
import Data.Time
import Text.Format
data Issue = Issue {
title :: String,
price :: Double,
pages :: Int,
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]