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 fetch from 'cross-fetch'; | |
| import { mocked } from 'ts-jest/utils'; | |
| import { getApiVersion } from './getApiVersion'; | |
| jest.mock('cross-fetch'); | |
| const mockFetch = mocked(fetch); | |
| describe('getApiVersion', () => { | |
| it('request the api version', async () => { |
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 { expect } from 'earljs'; | |
| type Range = [number, number]; | |
| const max = Math.max; | |
| const lastElement = <T>(arr: T[]) => arr[arr.length - 1]; | |
| const overlap = (r1: Range, r2: Range): boolean => { | |
| if (r1[0] > r2[0]) { | |
| return overlap(r2, r1); |
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 { act, renderHook } from '@testing-library/react-hooks'; | |
| import useEditableDataset from '../useEditableDataset'; | |
| function render<T>(input?: T[], onUpdate?: 'prepend' | 'append') { | |
| return renderHook(props => useEditableDataset(props.input, props.onUpdate), { | |
| initialProps: { input, onUpdate }, | |
| }); | |
| } |
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 { expect } from 'earljs'; | |
| import { Node, nodesListToTree, StaticNode } from './nodes-list-to-tree'; | |
| const createStaticNode = (label: string, nLeft: number, nRight: number): StaticNode => ({ | |
| label, | |
| nLeft, | |
| nRight, | |
| }); |
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 EventEmitter from "events"; | |
| import { terminal as term } from "terminal-kit"; | |
| const randInt = (min: number, max: number) => { | |
| return ~~(Math.random() * (max - min) + min); | |
| }; | |
| const choose = <T>(arr: T[] | readonly T[]): T => { | |
| return arr[randInt(0, arr.length)]; | |
| }; |
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 fs from 'fs'; | |
| import glob from 'glob'; | |
| const files = glob(process.argv[2], { sync: true }); | |
| const re = /^(import .* from ')((\.\.\/)+)(.*)$/; | |
| for (const filePath of files) { | |
| const path = filePath.split('/').slice(1, -1); | |
| const file = String(fs.readFileSync(filePath)); |
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 stringifyRequest = (request) => { | |
| const { req, res, _data } = request; | |
| const requestStr = [ | |
| ...req._header.split('\r\n').slice(0, -1), | |
| ...JSON.stringify(_data).split('\n'), | |
| ].map(line => '> ' + line).join('\r\n'); | |
| const responseStr = [ | |
| [res.statusCode, res.statusMessage, res.httpVersion].join(' '), |
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 main = async () => { | |
| }; | |
| (async () => { | |
| try { | |
| await main(); | |
| process.exit(0); | |
| } | |
| catch (e) { |
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
| // @flow | |
| const NETWORK_STORAGE_URL = process.env.NETWORK_STORAGE_URL; | |
| const storage = { | |
| getItem: (key: string): Promise<string> => { | |
| return fetch([NETWORK_STORAGE_URL, key].join('/')) | |
| .then(res => { | |
| if (res.status === 404) |
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
| COUNT=100000 | |
| function timefunc(f) { | |
| const start = Date.now(); | |
| f(); | |
| const end = Date.now(); | |
| return end - start; | |
| } | |
| function array_foreach() { |