This file contains 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 range(start: number, end: number, step = 1) { | |
return { | |
[Symbol.iterator]() { | |
return this | |
}, | |
next() { | |
if (start < end) { | |
start = start + step | |
return { | |
value: start, |
This file contains 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
#!/usr/bin/env bash | |
# ~/.macos — https://mths.be/macos | |
# Modified by Kent C. Dodds | |
# Run without downloading: | |
# Close any open System Preferences panes, to prevent them from overriding | |
# settings we’re about to change | |
osascript -e 'tell application "System Preferences" to quit' |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
interface User { | |
id: number | |
name: string | |
} | |
type Repository<T> = { | |
// `TKey in string & keyof T`: Enumerate all keys of the given object as string | |
// `findBy${Capitalize<TKey>}`: infer all keys by a template string | |
[TKey in string & keyof T as `findBy${Capitalize<TKey>}`]: (args: T[TKey]) => T[] // May be a promise | |
} |
This file contains 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
{ | |
"workbench.iconTheme": "material-icon-theme", | |
"workbench.colorTheme": "Palenight Theme", | |
"editor.fontFamily": "'Source Code Pro', 'Dank Mono','Cascadia Code', 'Source Code Pro', 'Fira Code', Consolas, 'Courier New', monospace", | |
"editor.tabSize": 2, | |
"editor.renderWhitespace": "boundary", | |
"window.zoomLevel": 1, | |
"editor.fontSize": 12, | |
"editor.formatOnType": true, | |
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe", |
This file contains 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
'use strict'; | |
const fs = require('fs'); | |
/** | |
* Reducer for each line | |
* @param {Object} conf Return value | |
* @param {string} line env config line | |
*/ | |
const reducer = (conf, line) => { | |
const [key, value] = line.split('='); |
This file contains 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 * as React from 'react'; | |
import { mount } from 'enzyme'; | |
export function createCompoundComponent<T, U = any>(Parent: React.FC<T>, ...components: (React.FC<U> | string)[]) { | |
return function Compound(props: React.PropsWithChildren<T>) { | |
const { children, ...newProps } = props; | |
let newChildren = React.Children | |
.toArray(children) | |
.filter(({ type }: any) => components.some(component => type === component)) |
This file contains 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 * as React from "react"; | |
/** | |
* Type definition for merge reducer | |
*/ | |
type MergeReducer<T> = (oldValue: T, newValue: Partial<T>) => T; | |
/** | |
* Merge two objects | |
* @param oldValue Old state |
This file contains 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
interface Result<T> { | |
[key: string]: T[]; | |
} | |
function groupBy<T>(array: T[], key: keyof T): Result<T> { | |
return array.reduce((acc: Result<T>, current: T) => { | |
const currentKey = (current[key] as unknown) as string; | |
acc[currentKey] = [...(acc[currentKey] || []), current]; | |
return acc; | |
}, {}); |
This file contains 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 * as React from 'react'; | |
export const enum TaskStatus { | |
IDLE = 'IDLE', | |
PROCESSING = 'PROCESSING', | |
DONE = 'DONE', | |
ERROR = 'ERROR', | |
} | |
export type Tasks<T> = Array<() => Promise<T>>; |