Skip to content

Instantly share code, notes, and snippets.

View zerobias's full-sized avatar
💭
Set your status

Dmitry zerobias

💭
Set your status
View GitHub Profile
@zerobias
zerobias / fs-extra.js
Last active April 12, 2025 23:15
Flow typings delaration for fs-extra
declare module 'fs-extra' {
import type {
createReadStream as createReadStreamType,
createWriteStream as createWriteStreamType,
} from 'fs'
declare export var createReadStream: $PropertyType<
$Exports<'fs'>,
'createReadStream',
>
@zerobias
zerobias / Dynamic spawn in effector.md
Last active June 19, 2024 13:02
Dynamic spawn in effector

Привет! Хочу описать ситуацию с моделями и динамическим спавном: хочется сделать это в ближайшее время. Мы в комитете эффектора рассмотрели ряд апи, все по своему интересны, но в целом не были учтены три главные проблемы, хочу их озвучить для вас, может вам придет что-то на ум)

Спавн моделей будет работать примерно как вызов fork для каждого инстанса. Тело фабрики при этом вызывается один раз, то есть юниты не пересоздаются, все как мы привыкли. Разница в том, что статические фабрики можно спавнить радикально эффективнее, разница как с первой версией fork с линейной сложностью и текущей которую в принципе малореально увидеть на мониторинге приложения.

Итак, проблемы которые нужно решить проектируя апи:

Первая проблема

Как пробрасывать аргументы в фабрику, которая вызывается один раз?

Нужно так или иначе сделать все аргументы сторами и возникает вопрос как сделать это удобнее всего?

@zerobias
zerobias / safe-padding.css
Last active May 29, 2024 05:51
Safe body paddings with env() and max() support
/* size variables */
:root {
--md: 8px;
--md-2: calc(var(--md) * 2);
--md-3: calc(var(--md) * 3);
--md-4: calc(var(--md) * 4);
}
/* safe area defaults */
@zerobias
zerobias / db.ts
Created September 29, 2023 17:07
Indexed DB with effector
import {createEvent, Event} from 'effector'
type DOMEvent = globalThis.Event
type Deferrable<Done, Fail> = {
addEventListener(event: 'success', handler: (val: Done) => any): any
addEventListener(event: 'error', handler: (err: Fail) => any): any
}
type ObjectDB = {
@zerobias
zerobias / htmlToForestPlugin.js
Last active August 21, 2023 19:26
HTML to forest rollup plugin
import {parseFragment} from 'parse5'
import generate from '@babel/generator'
import {parse} from '@babel/parser'
import t from '@babel/types'
import traverse from '@babel/traverse'
import template from '@babel/template'
function addFactoryImport(path, defs) {
const programPath = path.find(path => path.isProgram())
@zerobias
zerobias / nicknames.md
Last active June 16, 2022 07:44
nicknames
16.06.2022
Дима Zerobias
01.03.2022
⛴➡️🍆
@zerobias
zerobias / h.ts
Last active April 18, 2022 08:23
Declarative stack-based DOM api
import {
createStore,
createEvent,
is,
clearNode,
forward,
sample,
Store,
Event,
launch
@zerobias
zerobias / BinarySearchTree.js
Created August 11, 2018 10:10
Binary Search Tree
/**
* A binary search tree implementation in JavaScript. This implementation
* does not allow duplicate values to be inserted into the tree, ensuring
* that there is just one instance of each value.
* @class BinarySearchTree
* @constructor
*/
class BinarySearchTree {
constructor() {
/**
@zerobias
zerobias / Graph.js
Created August 27, 2018 06:09 — forked from netgusto/Graph.js
Graph Data Structure, adjacency list implementation + Traversals (DFS, BFS)
module.exports = class Graph {
constructor(V, E, directed = false) {
this.vertices = V;
this.edges = {};
E.map(e => {
const a = e[0]; const b = e[1]; const w = e[2] === undefined ? 1 : e[2];
this.addEdge(a, b, w);
@zerobias
zerobias / hear-dom.js
Created February 15, 2020 22:05
Hear DOM changes with WebAudio API
/*
Copy this into the console of any web page that is interactive and doesn't
do hard reloads. You will hear your DOM changes as different pitches of
audio.
I have found this interesting for debugging, but also fun to hear web pages
render like UIs do in movies.
*/
const audioCtx = new (window.AudioContext || window.webkitAudioContext)()
const observer = new MutationObserver(function(mutationsList) {