Skip to content

Instantly share code, notes, and snippets.

@ekozhura
ekozhura / hansa.clj
Last active August 29, 2015 14:01
#overtone #supercollider #clojure
(defsynth hansa []
(let [sig (* (lf-noise0 (x-line:kr 100 1000 0.5))
(env-gen:ar (env-perc 0.001 0.05 1 -4) :action FREE :gate (impulse:ar (/ 1 0.04))))
delayed (comb-c:ar sig 1 (* 0.005 (+ (* (sin-osc 20 0) 0.5 ) 1)) 1)
env (env-gen:ar (env-perc 0.4 1.5 0.6 -4) :action FREE)
sig (free-verb (+ sig delayed) (x-line:kr 0.01 0.6 1) 0.1 0.1)]
(out [0 1] (* sig env))))
(hansa)
(defn sum-dur-ext
[ls]
(letfn [(rec-sum [tl, ls]
(cond (empty? tl) ls
(empty? ls) (rec-sum (rest tl) (conj ls (first tl)))
:else (rec-sum (rest tl)
(conj ls (+ (first ls) (first tl))))))]
(reverse (rec-sum ls '()))))
@ekozhura
ekozhura / flat.clj
Last active August 29, 2015 14:06
transform nested lists into flat list: (1 3 (4 66 33 67) 23 16) => (1 3 4 66 33 67 23 16)
(defn flat-lists
[ls]
(letfn [(rec-flat [rec-list ls]
(cond (empty? rec-list) ls
(seq? (first rec-list)) (rec-flat (rest rec-list)
(rec-flat (first rec-list) ls))
(not (seq? (first rec-list))) (rec-flat (rest rec-list)
(cons (first rec-list) ls))))]
(cond (seq? ls) (reverse (rec-flat ls '()))
:else (list ls))))
@ekozhura
ekozhura / gist:375b14f217fd46950371
Created April 19, 2015 18:49
mixing two breaks with LinLin UGen
(
{
var source1, source2, buf1, buf2, tempo, rate = 44100, beatDur;
tempo = 170 / 60;
beatDur = (44100 / tempo).ceil;
buf1 = Buffer.read(s, "sounds/break_1_170.wav", startFrame: beatDur * 0);
buf2 = Buffer.read(s, "sounds/break_2_170.wav", startFrame: beatDur * 0);
source1 = PlayBuf.ar(2, buf1, BufRateScale.kr(buf1), startPos: beatDur * 0.5, rate: 1, trigger: Impulse.kr(tempo/16));
source2 = PlayBuf.ar(1, buf2, BufRateScale.kr(buf2), rate: 0.75, trigger: Impulse.kr(tempo/4)) * 0.5;
@ekozhura
ekozhura / init.hs
Last active September 15, 2015 21:05
Introduction to Functional Programming
initTake xs = take (length xs - 1) xs
initRev = reverse . tail . reverse
initRec = reverse . initAux []
where
initAux acc (x:[]) = acc
initAux acc xs = initAux (head xs : acc) (tail xs)
initRec2 (x:[]) = []
@ekozhura
ekozhura / routine.sc
Created November 7, 2015 12:43
Stream.collect implementation not only creates a new FuncStream, it mutates an original stream.
(
var a, b;
a = Routine.new({
inf.do{ |idx = 1|
idx.yield;
}
});
b = a.collect({|item| item * 2;});
b.nextN(10).postln; // -> [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 ]
@ekozhura
ekozhura / chain.js
Created December 25, 2015 13:31
fetch fork chain
github.fetch().fork()
.then(@chicoxyzzy)
.then(@blia)
.then(@ekozhura)
.then(@RReverser)
.then(@terrysahaidak)
.then(@ALF-er);
module Codewars.Kata.FancyReplace where
import Data.Functor
import Data.List
getNumber :: Integer -> Either Integer String
getNumber n | n `mod` 15 == 0 = Right "BOTH"
| n `mod` 3 == 0 = Right "THREE"
| n `mod` 5 == 0 = Right "FIVE"
| otherwise = Left n
{-# LANGUAGE ConstraintKinds, DataKinds, DeriveDataTypeable,
GADTs, TypeFamilies, TypeOperators, UndecidableInstances #-}
module Codewars.Kata.HelloWorld where
import Control.Arrow(first, second)
import Data.Char(toLower)
import Data.Typeable
import GHC.Exts(Constraint)
type family All (c :: * -> Constraint) (ts :: [*]) :: Constraint