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 / raf.js
Created April 8, 2019 04:58
requestAnimationFrame
const root = function () {
if (typeof window !== 'undefined') return window
if (typeof self !== 'undefined') return self
if (typeof globalThis !== 'undefined') return globalThis
if (typeof global !== 'undefined') return global
if (typeof this !== 'undefined') return this
}()
export const requestAnimationFrame =
@zerobias
zerobias / leftist.js
Created March 31, 2019 13:47
leftist tree/leftist heap
class Leftist<A> {
left: leftist<A>
right: leftist<A>
value: A
rank: number
constructor(value: A, rank: number, left: leftist<A>, right: leftist<A>) {
this.value = value
this.rank = rank
this.left = left
//@flow
const unify = (() => {
const isValueType = o =>
typeof o === 'boolean'
|| typeof o === 'string'
|| (typeof o === 'number' && !isNaN(o))
const toJson = elem => {
if (Array.isArray(elem)) {
const elems = elem.map(i => toJson(i))
//@flow
import _os from 'os'
export function platform() {
return process.platform
}
export function cpuCount() {
return _os.cpus().length
//@flow
export type Tree = {
/*::+*/ id: ID,
/*::+*/ kind: 'tree',
/*::+*/ refs: Array<Tree>,
/*::+*/ head: Array<StepValue>,
/*::+*/ tail: Array<Tree>,
/*::+*/ config: {
runInBand: boolean,
},
// Generated by BUCKLESCRIPT VERSION 4.0.6, PLEASE EDIT WITH CARE
'use strict';
var $$Map = require("./stdlib/map.js");
var Sys = require("./stdlib/sys.js");
var List = require("./stdlib/list.js");
var $$Array = require("./stdlib/array.js");
var Curry = require("./stdlib/curry.js");
var Caml_oo = require("./stdlib/caml_oo.js");
var Caml_obj = require("./stdlib/caml_obj.js");
@zerobias
zerobias / .d3v4-selectable-force-directed-graph
Last active January 7, 2019 09:57 — forked from pkerpedjiev/.d3v4-selectable-force-directed-graph
D3v4 Selectable, Draggable, Zoomable Force Directed Graph
.
@zerobias
zerobias / api.js
Last active January 7, 2019 10:26
graph dynamic updates
let gr = 0
function classifyNode(node) {
if (isFinite(parseInt(node, 36))) return {type: 'int', node, id: node}
if (node.startsWith('point_')) return {type: 'point', node, id: node.replace('point_', '')}
if (node.startsWith('before_')) return {type: 'before', node, id: node.replace('before_', '')}
if (node.startsWith('after_')) return {type: 'after', node, id: node.replace('after_', '')}
throw new Error(`unknown node ${node}`)
}
window.processGraph = function processGraph(graph) {
const nodes = Object.keys(graph)
{
"id": "4",
"type": "seq",
"group": "step",
"data": [
{
"id": "3",
"type": "single",
"group": "step",
"data": {
@zerobias
zerobias / snake-stress-test.js
Created December 28, 2018 17:33
Snake: effector's stress-test
//@flow
import {
createStore,
createEvent,
combine,
createStoreObject,
type Store,
// } from '../../npm/effector/effector.bundle'
} from '../../npm/effector/effector.es'
global.__SNAKE__ = function snake() {