Skip to content

Instantly share code, notes, and snippets.

@Deraen
Deraen / lazy-assoc-in.clj
Created October 7, 2015 06:30 — forked from ikitommi/repl.md
lazy-assoc-in
(ns test.core
(:import [clojure.lang IDeref]))
(require '[lazymap.core :as lm])
(defn lazy-assoc-in
"Value should be either derefable (delay or future) which will be dereffed when value is needed
or a function which will be called."
[m [k & ks] f]
(if (seq ks)
@Deraen
Deraen / angular-filesize.js
Last active July 5, 2017 15:14 — forked from thomseddon/gist:3511330
Humanize filesize
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
var number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
};
});
(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)
(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))))
(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)]