Skip to content

Instantly share code, notes, and snippets.

View t-harison's full-sized avatar
🏆
Positive mindset

Tolotra Raharison t-harison

🏆
Positive mindset
  • Lévis, Québec
View GitHub Profile
/**
* Create delay promise
* @param timeout Timeout delay in MS
* @param value Value to resolve after timeout
*/
export async function delay<T>(timeout: number, value?: T) {
return new Promise((resolve) => {
const timeoutId = setTimeout(() => {
resolve(value);
clearTimeout(timeoutId);
/**
* Create new array
* @param args
*/
export const create = <T>(...args: T[]): T[] => [...args];
/**
* Push item to the list
* @param item
*/
type Func<P = any, R = any> = (...args: P[]) => R;
/**
* Identity function
* Return the given value all the time
* @param value
*/
export function identity<T = any>(value: T): T {
return value;
}
function distinctReducer<T>(key: keyof T, map: Map<any, boolean> = new Map<any, boolean>()) {
return function (acc: T[], item: T) {
if (!map.has(item[key])) {
map.set(item[key], true);
return [...acc, item];
}
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>>;
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";
/**
* Type definition for merge reducer
*/
type MergeReducer<T> = (oldValue: T, newValue: Partial<T>) => T;
/**
* Merge two objects
* @param oldValue Old state
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))
'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('=');
{
"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",