Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Set your status

Dmitry zerobias

💭
Set your status
View GitHub Profile
@zerobias
zerobias / toposort.ts
Created Mar 21, 2021
Topological sorting
View toposort.ts
export function toposort(
rawGraph: Record<string, string[]>,
ignore?: Set<string>
) {
const graph = {} as Record<string, string[]>
for (const id in rawGraph) {
graph[id] = [...new Set(rawGraph[id])]
}
const result = [] as string[]
const visited = {} as Record<string, boolean>
@zerobias
zerobias / server.js
Created Feb 16, 2021
server sent events with effector
View server.js
const express = require('express')
const {createStore, createEvent, sample} = require('effector')
const clientConnected = createEvent()
const statusRequested = createEvent()
const updateReceived = createEvent()
const clientClosed = createEvent()
const pushUpdate = createEvent()
const clients$ = createStore([])
.on(clientConnected, (list, client) => [...list, client])
@zerobias
zerobias / safe-padding.css
Last active Mar 9, 2020
Safe body paddings with env() and max() support
View safe-padding.css
/* 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 / bar.f12f7610.js
Created Feb 26, 2020
parcel 2 dynamic import
View bar.f12f7610.js
parcelRequire.registerBundle('e1095da0325446888ed16378b7e22c16', function() {
var e =
'undefined' != typeof globalThis
? globalThis
: 'undefined' != typeof self
? self
: 'undefined' != typeof window
? window
: 'undefined' != typeof global
? global
@zerobias
zerobias / hear-dom.js
Created Feb 15, 2020
Hear DOM changes with WebAudio API
View hear-dom.js
/*
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) {
@zerobias
zerobias / decompress.js
Created Dec 27, 2019
decompress effector repl sources
View decompress.js
const keyStrUriSafe =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$'
const baseReverseDic = {}
const charAt = (str, i) => str.charAt(i)
for (let i = 0; i < keyStrUriSafe.length; i++) {
baseReverseDic[charAt(keyStrUriSafe, i)] = i
}
console.log(decompress(localStorage.getItem('code-compressed')))
@zerobias
zerobias / lsdb.ts
Created Nov 27, 2019
Reactive database with localStorage and effector
View lsdb.ts
import {
createEvent,
createStore,
createEffect,
combine,
forward,
Effect,
Store,
Event,
step
@zerobias
zerobias / h.ts
Last active Apr 18, 2022
Declarative stack-based DOM api
View h.ts
import {
createStore,
createEvent,
is,
clearNode,
forward,
sample,
Store,
Event,
launch
@zerobias
zerobias / proposal_tasks.md
Last active Jul 18, 2019
effector proposal: tasks
View proposal_tasks.md

Tasks

try it

Current effect behavior

const fx = createEffect({
  handler(params) {
    console.log(params)
  },
View markdown_ast.json
{
"type": "root",
"children": [
{
"type": "thematicBreak",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0