Skip to content

Instantly share code, notes, and snippets.

View SugarDarius's full-sized avatar
🚀
Building new products

Aurélien Dupays Dexemple SugarDarius

🚀
Building new products
View GitHub Profile
@SugarDarius
SugarDarius / independent-dropdown.jsx
Last active June 3, 2019 13:51
Independent Dropdown React Component
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import map from 'lodash/map';
export default class IndependentDropdown extends Component {
constructor(props) {
super(props);
this.onClickOutside = this.onClickOutside.bind(this);
@SugarDarius
SugarDarius / index.jsx
Created January 31, 2018 13:52
Independent Dropdown Index
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import IndependentDropdown from './independent-dropdown.jsx';
export default class App extends Component {
constructor(props) {
super(props);
@SugarDarius
SugarDarius / async-action.ts
Last active September 10, 2020 03:35
An async promise middleware for Redux written in TypeScript
/*
* Async action
* author: Aurélien Dupays Dexemple
*/
import { AxiosStatic, AxiosResponse } from 'axios';
import { SyncAction } from './sync-action';
export interface AsyncAction<R extends string = '', S extends string = '', F extends string = '', P extends { [ key: string ]: any } = {}> extends SyncAction<'@@async/action', P> {
@SugarDarius
SugarDarius / browsers.ts
Last active November 5, 2018 09:23
A React component to detect browsers and update UI
/*
* Detect browser - Browsers
* author: Aurélien Dupays Dexemple
*/
export type BrowserName = 'Chrome' |
'Firefox' |
'Safari' |
'Internet Explorer' |
@SugarDarius
SugarDarius / promise-chain.ts
Last active March 16, 2020 10:43
Promise Chain base on Axios which merge promises into on single response
/*
* Promise chain
* author: Aurélien Dupays Dexemple
*/
import { AxiosStatic, AxiosPromise, AxiosResponse } from 'axios';
export const PromiseChain = (axios: AxiosStatic, promises: AxiosPromise[]): Promise<AxiosResponse<any>> => (
axios.all(promises).then((responses: AxiosResponse[]): AxiosResponse<any> => (
@SugarDarius
SugarDarius / map-recursive.ts
Last active October 20, 2022 07:26
TypeScript recursive map
/*
* mapRecursive
* author: Aurélien Dupays Dexemple
*/
export const isUndefined = (obj: any): obj is undefined => typeof obj === 'undefined';
export function mapRecursive<TInput, TOutput>(fn: (e: TInput, index?: number) => TOutput, [first, ...rest]: TInput[], index: number = 0): TOutput[] {
return isUndefined(first) ? [] : [fn(first, index), ...mapRecursive(fn, rest, ++index)];
};
@SugarDarius
SugarDarius / profile.ps1
Last active March 28, 2020 03:45
Customized PowerShell Prompt (Windows Terminal and classic PowerShell app)
# use Install-Module -Name Emojis
Import-Module -Name Emojis;
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).isInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function prompt {
$realLASTEXITCODE = $LASTEXITCODE;
@SugarDarius
SugarDarius / sync-react-reducer-with-session-storage.tsx
Last active June 2, 2020 11:55
Sync React Reducer with session storage
import * as React from 'react';
import { useReducerSyncSessionStorage } from '../hooks';
export const aStateAction = '@@my-reducer/A_STATE_ACTION';
export type Action<A, P = {}> = {
type: A;
payload?: P;
}