Skip to content

Instantly share code, notes, and snippets.

@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:

@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 / 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 / notes.md
Last active September 18, 2018 13:15
Notes on FRA implementation

Notes on FRA implementation (functional reactive animation)

Inspired by Fran (by Conal Elliott) and "The Haskell School of Expression" (by Paul Hudak).

Github: https://github.com/ekozhura/fra (work in progress).

Transform type

Let's define a type Transform:

type lazylist('a) =
| Cons('a, unit => lazylist('a));
let rec lseq = n => Cons(n, () => lseq(n + 1));
let lhd = (Cons(n, _)) => n;
let ltl = (Cons(_, tf)) => tf();
let rec ltake = (Cons(h, tf), n) =>
switch (n) {
/**
* This code was used as a part of PoC, done for my talk at ReactKyiv meetup:
* https://animationsslides.brutallo.now.sh/#/
*
*
* Emoji animations were inspired by this article:
* https://matthewrayfield.com/articles/animating-urls-with-javascript-and-emojis/
*/
/**
@ekozhura
ekozhura / ffmpeg.md
Created October 12, 2019 11:12 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@ekozhura
ekozhura / latency.markdown
Created November 10, 2019 21:01 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@ekozhura
ekozhura / machine.js
Last active November 22, 2019 16:01
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@ekozhura
ekozhura / sketch.ino
Created September 21, 2020 09:18
Arduino + 7-Segment Red LED + HCF4015B
#define DATA_PIN 3 // data
#define CLOCK_PIN 4 // clock
#define RESET_PIN 5 // reset
#define SEVEN_SEGMENTS_LENGTH 17
static byte seven_segments_codes[SEVEN_SEGMENTS_LENGTH] = {
B10001000, // 0
B11101011, // 1
B01001100, // 2
B01001001, // 3