Skip to content

Instantly share code, notes, and snippets.

Avatar

Danakt danakt

View GitHub Profile
View pepkek.js
([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]][(![]+[])[+[]]+(!![]+[])[+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+((+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!
@danakt
danakt / getElementByTagName.ts
Created Jun 27, 2019
Returns type of HTML element by tag name
View getElementByTagName.ts
/**
* Returns type of HTML element by tag name
* @example
* type ElementType = GetElementByTagname<'div'> // HTMLDivElement
*/
type GetElementByTagName<
Tagname extends keyof React.ReactHTML
> = React.ReactHTML[Tagname] extends React.DetailedHTMLFactory<infer A, infer E> ? E : null;
@danakt
danakt / useDebouncedCallback.ts
Created Mar 19, 2019
React hook for creating debounced callback
View useDebouncedCallback.ts
export const useDebouncedCallback = <T extends (...args: any) => void>(
callback: T,
time: number,
deps: React.DependencyList
) => {
const timerRef = React.useRef<number>(-1);
const memoizedCallback = React.useCallback<T>(
((...args: any): void => {
clearTimeout(timerRef.current);
@danakt
danakt / containerCreator.tsx
Last active Feb 11, 2019
Creates react container with render props pattern
View containerCreator.tsx
const createContainer = function<Props = {}, Data = {}, Actions = {}>(callback: (props: Props) => [Data, Actions]) {
return (props: Props & { children: (data: Data, actions: Actions) => React.ReactNode }) => (
<React.Fragment>{props.children(...callback(props))}</React.Fragment>
);
};
@danakt
danakt / usePrev.ts
Created Dec 3, 2018
React hook to use previous data
View usePrev.ts
/**
* React hook to use previous data
*/
const usePrevious = function<T>(value: T): undefined | T {
const ref = React.useRef<T | undefined>(undefined);
React.useEffect(() => {
ref.current = value;
});
@danakt
danakt / pureComponent.ts
Created Oct 31, 2018
Pure Component HOC
View pureComponent.ts
/**
* Wraps any React component (even functional) to PureComponent class
*/
export const pureComponent = function<P>(Component: React.ComponentType<P>) {
return class extends React.PureComponent<P> {
static displayName = `pureComponent(${Component.displayName || Component.name})`;
render() {
return <Component {...this.props} />;
}
@danakt
danakt / enhanceJSXAttributes.d.ts
Last active Aug 30, 2018
Expanding attributes of JSX element
View enhanceJSXAttributes.d.ts
/// <reference path="../node_modules/@types/react/index.d.ts" />
/**
* Enhancer of JSX attributes
*/
type EnhanceAttributes<
Tagname extends keyof React.ReactHTML,
NewAttributes extends {},
T = React.ReactHTML[Tagname]
> = T extends React.DetailedHTMLFactory<infer A, infer E>
@danakt
danakt / validateInputForNumber.js
Last active Feb 27, 2018
Validate text input for numer
View validateInputForNumber.js
/**
* Checks text input for valid integer/float
* @param {string} value The input value
* @returns {boolean} Result of the validate
*
* @example
* validateInputForNumber('123') // true
* validateInputForNumber('123.123') // true
* validateInputForNumber('123.') // (!) still true
*
@danakt
danakt / iterableNumber.js
Last active Oct 25, 2017
Make number iterable
View iterableNumber.js
Number.prototype[Symbol.iterator] = function* () {
if (isNaN(this) || !isFinite(this)) {
throw new ReferenceError('Non-iterable number')
}
const abs = Math.abs(this)
const isNegative = this < 0
for (let i = 0; i < abs; i++) {
yield isNegative ? -i : i
@danakt
danakt / char-without-char.js
Last active Jun 21, 2017
Getting chars without using alphanumeric chars
View char-without-char.js
var words = {
'true': !![]+[],
'false': ![]+[],
'Infinity': !![]/[]+[],
'undefined': [][[]]+[],
'NaN': []/[]+[],
'[object Object]': []+{}
};
var numbersSpec = {