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
export const defaultCache = store => {
return {
invalidate: hash =>
new Promise(resolve => {
delete store[hash];
resolve(hash);
}),
invalidateAll: () =>
new Promise(resolve => {
store = {};
@zerobias
zerobias / .block
Created August 27, 2018 08:02
Nitrogen Cycle
license: mit
@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 / effector persistent store.js
Created August 26, 2018 17:38
effector persistent store
//@flow
import {
createStore,
createEffect,
type Store,
} from 'effector'
export function persistentStore(defaults: string, key: string) {
const readEff = createEffect(`read ${key}`)
@zerobias
zerobias / SemiMutable.js
Last active August 16, 2018 02:39
Semi-mutable Set and Map, immutable wrappers over native mutable js Maps and Sets
//@flow
export class SemiMap<Key, Val> {
/*::
;+_: Map<Key, Val>
;+@@iterator: () => Iterator<[Key, Val]>
mutable: boolean
*/
constructor(parent: Map<Key, Val> = new Map()) {
this._ = parent
@zerobias
zerobias / a way to fast flow checks.md
Last active August 12, 2018 20:18
Flow lazy (aka "blazing fast") server with force recheck shortcuts

Flow lazy (aka "blazing fast") server with force recheck shortcuts

Usage

Run ./flowtype to start server in lazy mode and ./check Foo to add ./src/Foo.js to flow watchlist

One line install

echo '#!/usr/bin/env bash\nnpx flow server --lazy-mode fs --strip-root\n' > ./flowtype && echo '#!/usr/bin/env bash\necho "focus check src/$1.js"\nnpx flow force-recheck --focus ./src/$1.js\n' > ./check && chmod +x ./flowtype && chmod +x ./check
@zerobias
zerobias / DoubleLinkedList.js
Created August 11, 2018 10:16
Double linked list
/**
* A linked list implementation in JavaScript.
*/
class DoublyLinkedList {
constructor() {
/**
* Pointer to first item in the list.
* @property _head
* @type Object
* @private
@zerobias
zerobias / LinkedList.js
Created August 11, 2018 10:13
linked list
/**
* A linked list implementation in JavaScript.
* @class LinkedList
* @constructor
*/
class LinkedList {
constructor() {
/**
* The number of items in the list.
* @property _length
@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 / binary search.js
Created August 11, 2018 10:00
binary search
/**
* Uses a binary search algorithm to locate a value in the specified array.
* @param {Array} items The array containing the item.
* @param {variant} value The value to search for.
* @return {int} The zero-based index of the value in the array or -1 if not found.
*/
function binarySearch(items, value){
var startIndex = 0,
stopIndex = items.length - 1,