Skip to content

Instantly share code, notes, and snippets.

View tolotrasmile's full-sized avatar
🏆
Positive mindset

Tolotra Raharison tolotrasmile

🏆
Positive mindset
View GitHub Profile
function range(start: number, end: number, step = 1) {
return {
[Symbol.iterator]() {
return this
},
next() {
if (start < end) {
start = start + step
return {
value: start,
#!/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.
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
}
{
"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",
'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('=');
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))
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
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;
}, {});
import * as React from 'react';
export const enum TaskStatus {
IDLE = 'IDLE',
PROCESSING = 'PROCESSING',
DONE = 'DONE',
ERROR = 'ERROR',
}
export type Tasks<T> = Array<() => Promise<T>>;