Skip to content

Instantly share code, notes, and snippets.

#(= (seq %1) (reverse %1))
(fn [key map] (and (contains? map key) (= nil (key map))))
@melklein
melklein / rainbow-strokes.clj
Created July 10, 2016 16:28
draw lines following the mouse in rainbow colours; base stroke thickness on mouse speed
(ns mouse-interactivity.core
(:require [quil.core :refer :all]))
(def max-stroke-weight 40)
(defn setup []
(background 255)
(color-mode :hsb)
(smooth))
@melklein
melklein / gaussian-distribution-with-matrix-translate.clj
Last active July 10, 2016 14:34
visualisation of gaussian distribution in quil (from The Nature of Code - Daniel Shiffman)
(ns fun-mode-sketch
(:require [quil.core :as q]
[quil.middleware :as m]))
(def win-width 400)
(def win-height 200)
(def sd 60) ;standard deviation
(def center-x (/ win-width 2))
(def center-y (/ win-height 2))
(ns fun-mode-sketch
(:require [quil.core :as q]
[quil.middleware :as m]))
(def win-width 400)
(def win-height 200)
(def bar-width 1)
(def bar-height 10)
(def bar-count (/ win-width bar-width))
(def grow-bar (partial + bar-height))
(fn [my-seq]
((fn [rest-seq result]
(if (= 0 (count rest-seq))
result
(recur (butlast rest-seq) (conj result (last rest-seq)))))
my-seq []))
@melklein
melklein / fib-mundane.clj
Created June 27, 2016 20:58
clojure recursion with 'mundane' recursion and fibonacci numbers
(defn fib-seq [x result]
(if (= x 0)
(reverse result)
(let [next-fib (reduce + (take 2 result))]
(fib-seq (dec x) (conj result next-fib)))))
(defn fib [mx]
(fib-seq (- mx 2) '(1 1)))
@melklein
melklein / fib-loop.clj
Created June 27, 2016 20:54
clojure recursion with loop and fibonacci numbers
(fn [mx]
(loop [x (- mx 2) result '(1 1)]
(if (> x 0)
(recur (dec x)
(conj result
(reduce + (take 2 result))))
(reverse result)))))
@melklein
melklein / 4clojure#134.clj
Created June 27, 2016 20:48
clojure stuff
(fn [key map] (and (contains? map key) (= nil (key map))))
@melklein
melklein / fib-anon.clj
Last active June 27, 2016 20:54
recursion in clojure with fibonacci numbers
(defn fib-anon [mx]
((fn [x result]
(if (= x 0)
(reverse result)
((let [next-fib (reduce + (take 2 result))]
recur (dec x) next-fib))))
(- mx 2) '(1 1)))
@melklein
melklein / vim_solutions.md
Last active July 6, 2016 10:39
useful vim commands
  • increase number under cursor: ctrl+a
  • decrease number under cursor: ctrl+x
  • replace one word with another: select first word, e.g. vi"; select second word vi" and paste p
  • search from within vim, don't jump to first match: vimgrep /render_show/gj **/*.rb

Resize splits

  • resize horizontal split: ctrl+w - / ctrl+w +
  • resize horizontal split to maximum: ctrl+w _
  • make horizontal and vertical splits equally big: ctrl+w =
  • resize vertical split: ctrl+w < / ctrl+w >