Skip to content

Instantly share code, notes, and snippets.

@ekozhura
ekozhura / Audio.re
Last active August 6, 2018 20:28
WebAudio Reason bindings (playground)
module AudioNode = {
type audio_node;
};
module AudioParam = {
type audio_param;
[@bs.send] external setValue: audio_param => float => float => unit = "setValueAtTime";
};
module AudioSourceNode = {
@ekozhura
ekozhura / parser.ml
Last active March 10, 2019 19:48
Parser Combinators
open Printf
type ('a, 'b) result =
| Success of 'a * 'b
| Failure of string
type 'a parser = Parser of (string -> ('a, string) result)
let run_parser p i = match p with
| Parser fn -> fn i;;
@ekozhura
ekozhura / using-rxjs-instead-of-flux-with-react.md
Created December 11, 2017 06:15 — forked from justinwoo/using-rxjs-instead-of-flux-with-react.md
Using RxJS instead of Flux with React to organize data flow

Reposted from Qiita

For almost a year now, I've been using this "flux" architecture to organize my React applications and to work on other people's projects, and its popularity has grown quite a lot, to the point where it shows up on job listings for React and a lot of people get confused about what it is.

Why I'm tired of using and teaching flux

There are a billion explainations on the internet, so I'll skip explaining the parts. Instead, let's cut to the chase -- the main parts I hate about flux are the Dispatcher and the Store's own updating mechanism.

If you use a setup similar to the examples in facebook/flux, and you use flux.Dispatcher, you probably have this kind of flow:

{-# 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
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
@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);
@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 / 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 / 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;