Skip to content

Instantly share code, notes, and snippets.

@ekozhura
ekozhura / machine.js
Created October 30, 2020 10:36
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@ekozhura
ekozhura / fastapi_websocket_redis_pubsub.py
Created October 15, 2020 21:52 — forked from timhughes/fastapi_websocket_redis_pubsub.py
FastAPI Websocket Bidirectional Redis PubSub
"""
Usage:
Make sure that redis is running on localhost (or adjust the url)
Install uvicorn or some other asgi server https://asgi.readthedocs.io/en/latest/implementations.html
pip install -u uvicorn
Install dependencies
@ekozhura
ekozhura / machine.js
Created October 6, 2020 09:49
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
@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 / 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 / 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:

/**
* 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/
*/
/**
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) {
@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: