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
type NonEmptyArray<T> = [T, ...T[]]; | |
const names: NonEmptyArray<string> = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']; | |
function main(names: NonEmptyArray<string>, n: number){ | |
let index = n - 1; | |
while (index >= names.length) { | |
index = Math.floor((index - names.length) / 2); | |
} |
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 React from 'react'; | |
import createPersistedState from 'use-persisted-state'; | |
import { storage } from '../utilities/storage'; | |
import { hasElements, head, isDefined } from '@rhim/utils'; | |
const usePersistedEntityId = createPersistedState('some-entity-key', storage); |
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 Response<T> { | |
status: 'success' | 'pending' | 'error'; | |
data: T | null; | |
} | |
/** | |
* A promise tracker that will be updated | |
* when promise resolves or rejects | |
*/ | |
const response: Response<unknown> = { |
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 { FlattenSimpleInterpolation } from 'styled-components'; | |
import { pick } from './objects'; | |
type Stylesheet<K extends string> = Record<K, FlattenSimpleInterpolation>; | |
/** | |
* CSS-in-JS equivalent for `classNames`. | |
* | |
* @example |
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 Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | |
/** | |
* Supplies default props. | |
*/ | |
export function withDefaults<T extends React.ComponentType<any>, U extends Partial<React.ComponentProps<T>>>( | |
Component: T, | |
defaults: U, |
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
/node_modules/ | |
webpack:///webpack | |
^webpack://.*/process\-update\.js$ | |
^webpack://.*/client\.js$ | |
^debugger:// | |
\(webpack\)-hot-middleware | |
webpack/bootstrap | |
/jquery\.min\.js$ | |
/jquery\-migrate\-1\.4\.1\.min\.js$ |
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
// #region Necessary types | |
type NonEmptyArray<T> = [head: T, ...T[]]; | |
type Tuple<T> = [T, T]; | |
declare function head<T>(collection: [T, ...T[]]): T; | |
// #endregion | |
const cloudflareDNS: NonEmptyArray<string> = ["1.1.1.1"]; | |
const googleDNS: Tuple<string> = ["8.8.8.8", "8.8.4.4"] | |
// ✅ These Just Work™️ |
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
type Singleton = string; | |
type Union = string | number; | |
type DistributedKeyOf<T> = | |
T extends any | |
? keyof T | |
: never; | |
type DistributedValueOf<T> = T[DistributedKeyOf<T>]; |
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
type PromisifyMethods<T> = { | |
[K in keyof T]: T[K] extends AnyFunction ? (...parameters: Parameters<T[K]>) => Promise<ReturnType<T[K]>> : T[K]; | |
}; | |
type AsynchronousStorage = PromisifyMethods<Storage>; | |
export function promisify(storage: Storage): AsynchronousStorage { | |
return new Proxy(storage, { | |
get(target, name: string) { | |
if (typeof target[name] === 'function') { |
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
const isPalindrome = (phrase: string): boolean => { | |
const original = phrase.toLowerCase().replace(/[^A-Za-z0-9]/g, ''); | |
const reversed = original.split('').reverse().join(''); | |
return original === reversed | |
} | |
console.log( | |
isPalindrome("A man, a plan, a canal – Panama!") | |
) |
NewerOlder