Skip to content

Instantly share code, notes, and snippets.

(defn mrg [[x & xrest :as X] [y & yrest :as Y] R]
(if (and X Y)
(if (<= x y)
(recur xrest Y (conj R x))
(recur X yrest (conj R y)))
(concat R X Y)))
(defn mrgsrt [X]
(if (> (count X) 1)
(let [[left right] (split-at (/ (count X) 2) X)]
(defn outrun-2 [pyramid]
(->> pyramid
(reduce
(fn [previous line]
(mapv (fn [this i]
(let [left (get previous (dec i) 0)
right (get previous i 0)]
(+ this (max left right))))
line
(range))))
(ns reaktor-outrun.core
(:require [nio.core :as nio]
[clojure.java.io :as io]
[hiphip.int :as hh])
(:gen-class :main true))
(set! *warn-on-reflection* true)
(set! *unchecked-math* true)
;; http://reaktor.fi/blog/fast-track-osa-kolme-koodaa-out-run-lempikielellasi/
@Deraen
Deraen / viikko43.hs
Last active August 29, 2015 14:08
Some Haskell excercises
#!/usr/bin/env runhaskell
import System.IO
import Control.Monad
import qualified Data.Text as T
splitLines :: String -> [String]
splitLines s = map T.unpack $ T.splitOn (T.pack ",") $ T.pack s
readNumbers :: [String] -> [Int]
readNumbers = map (\x -> read x :: Int)
(defn debounce
"Creates a channel which will change put a new value to the output channel
after timeout has passed. Each value change resets the timeout. If value
changes more frequently only the latest value is put out.
When input channel closes, the output channel is closed."
[in ms]
(let [out (chan)]
(go-loop [last-val nil]
(let [val (if (nil? last-val) (<! in) last-val)
@Deraen
Deraen / Vagrantfile
Created December 14, 2014 00:05
Testing boot
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$script = <<SCRIPT
apt-get install -y git maven openjdk-7-jdk
(
cd /usr/local/bin
wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein -O lein
chmod +x lein
)
@Deraen
Deraen / README.md
Created December 14, 2014 11:52
Necessitate.js, POC JS modules

Feb 2014, not used, not maintained

Necessitate.js

Does RequireJS seem to complicated? You don't like that Browserify requires compilation while developing?

This is a library to implement simple modules.

  • Function params used to define dependencies
@Deraen
Deraen / NOTES.md
Last active August 29, 2015 14:12
Clojure Schema/Validation Libs

Notes

  • Most libraries do only validation. Schema does also coercion.

Pros:

  • Schemas are represented using collections and maps etc.
  • It's easy to modify existing schemas using general fns:
@Deraen
Deraen / build.boot.clj
Last active August 29, 2015 14:12
Cljsjs
(set-env!
:resource-paths #{"resources"}
:dependencies '[[adzerk/bootlaces "0.1.8" :scope "test"]])
(require '[adzerk.bootlaces :refer :all])
(def +version+ "2.6.0-0")
(bootlaces! +version+)
(task-options!
[clj-pdf "1.11.21" :exclusions [org.apache.xmlgraphics/batik-gvt]]
[org.apache.xmlgraphics/batik-gvt "1.7" :exclusions [org.apache.xmlgraphics/batik-bridge]]
[org.apache.xmlgraphics/batik-bridge "1.7" :exclusions [org.apache.xmlgraphics/batik-gvt org.apache.xmlgraphics/batik-script org.apache.xmlgraphics/batik-anim]]
[org.apache.xmlgraphics/batik-script "1.7" :exclusions [org.apache.xmlgraphics/batik-bridge]]
[org.apache.xmlgraphics/batik-anim "1.7" :exclusions [org.apache.xmlgraphics/batik-svg-dom]]
[org.apache.xmlgraphics/batik-svg-dom "1.7" :exclusions [org.apache.xmlgraphics/batik-svg-dom]]