This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const placeHolderElemAttr = { | |
| position: 'absolute', | |
| top: '-99999px', | |
| left: '-99999px', | |
| width: '100px', | |
| height: '100px', | |
| overflow: 'scroll' | |
| }; | |
| interface CalcScrollbarSize { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function ({ types: t }) { | |
| let hasUserTokenImport = false; | |
| let defaultImportIdentifier = ''; | |
| return { | |
| visitor: { | |
| Program: { | |
| enter(path) { | |
| const children = path.node.body; | |
| const userTokenImportIndex = children.findIndex(item => { | |
| if (item.type !== 'ImportDeclaration') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class GraphNode { | |
| public neighbors: Set<GraphNode> | |
| public color: string | |
| constructor(public label) { | |
| this.label = label; | |
| this.neighbors = new Set(); | |
| this.color = null; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mergeArrays(leftArray, rightArray) { | |
| const result = []; | |
| let leftIndex = 0; | |
| let rightIndex = 0; | |
| const leftLen = leftArray.length; | |
| const rightLen = rightArray.length; | |
| while(result.length < leftLen + rightLen) { | |
| if (leftIndex < leftLen && (rightIndex === rightLen || leftArray[leftIndex] < rightArray[rightIndex])) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DumpMap { | |
| hashTable: Array<Array<[string, any]>> | |
| constructor() { | |
| this.hashTable = [] | |
| } | |
| get(x: string) { | |
| const index = hash(x) | |
| const backets = this.hashTable[index] | |
| if (!backets) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { fromEvent, of, EMPTY } from 'rxjs'; | |
| import { switchMap } from 'rxjs/operators'; | |
| import { isEmpty } from 'lodash'; | |
| function bindKeyboardShortcuts(eventName: string, keybinding: string) { | |
| const keys = keybinding.split('.').map(key => key.toLowerCase()); | |
| const allModifierKeys = ['ctrl', 'shift', 'alt', 'cmd', 'meta']; // meta === cmd | |
| const modifierKeys = keys.filter(key => allModifierKeys.indexOf(key) !== -1); | |
| return fromEvent(document, eventName).pipe( | |
| switchMap((e: KeyboardEvent) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { iif, of, Subject } from 'rxjs'; | |
| import { switchMap, delay, finalize } from 'rxjs/operators'; | |
| import { ajax } from 'rxjs/ajax'; | |
| const loadingSubject = new Subject<boolean>(); | |
| const loading$ = loadingSubject.pipe( | |
| switchMap(flag => { | |
| return iif( | |
| () => flag, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * console order is: | |
| * main call stack start | |
| * main callback stack end | |
| * Promise | |
| * mutate | |
| * setTimeout | |
| * | |
| * @see https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/ | |
| * callback of Promise, MutationObserver(as microtasks) has higher privilege then setTimeout callback |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const worker = new Worker('worker.js') | |
| // handle data from worker | |
| worker.addEventListener('message', (e) => { | |
| console.log('worker send data back:', e.data) | |
| }, false); | |
| // handle error | |
| worker.addEventListener('error', (err) => { | |
| console.log(`Error: Line ${err.lineno} in ${err.filename} : ${e.message}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Graph { | |
| public adjList = new Map<any, any[]>(); | |
| public numberOfVertexs: number = 0; | |
| public addVertex(vertex) { | |
| this.adjList.set(vertex, []); | |
| this.numberOfVertexs ++; | |
| } | |
| public addEdge(vertex1, vertex2) { |
NewerOlder