Skip to content

Instantly share code, notes, and snippets.

View tommmyy's full-sized avatar
🏠
Working from home

Tomáš Konrády tommmyy

🏠
Working from home
View GitHub Profile
// One must love Dan:
// https://github.com/reduxjs/react-redux/issues/1252#issuecomment-488160930
// bindActionCreators are not good for your codebase!?
const useInfo = journey => {
const dispatch = useDispatch();
return {
goToStep: useCallback((...args) => dispatch(goToStep(...args)), [dispatch]),
goToNextStep: useCallback((...args) => dispatch(goToNextStep(...args)), [dispatch]),
@tommmyy
tommmyy / combineValidate.js
Last active July 8, 2019 11:52
How to create reusable field validations with @validarium?
// Did you know that in @validarium you can combine not only validation schemes
// (as is used in `validate` fn), but even the particular validations?
import { validate, createValidation, combineValidate } from '@validarium/core';
// 1. For the example I am using one of the validation from @validarium/validations:
import { hasNoSpecialSymbols } from '@validarium/validations';
import { test } from 'ramda';
import m from './messages';
@tommmyy
tommmyy / extending-component.jsx
Created May 28, 2019 10:40
Extending component
// BEFORE:
const CommentTextArea = ({ maxCharacters, name, validate, ...otherProps }) => (
<TextareaField
name={name}
rows={4}
label={<Message {...messages.comment} />}
maxCharacters={maxCharacters}
{...otherProps}
/>
);
const Example = ({ onClick }) => {
const memoizedHandleClick = useCallback(
(event) => onClick(event),
[] // ugly magic of hooks
);
return <Button onClick={memoizedHandleClick}>Click</Button>;
}
@tommmyy
tommmyy / javascript-for-vim-refactoring.js
Created November 5, 2018 19:19 — forked from iamnewton/javascript-for-vim-refactoring.js
Moving faster with Vim (5-minute lightning talk presentation). I wasn't inspired to learn effective command of Vim until I saw some people flying around faster than I thought was possible. The goal of this presentation is to call out how slow "normal" text editing is, and how many keystrokes can be reduced by using increasingly more terse Vim co…
$(function() {
// good opportunity to combine into a single statement
// qq w cw <esc> A, <esc> 0 j q
var a = 10;
var b = 20;
var c = 30;
var d = 40;
var e = 50;
// opportunity to simplify syntax
import React, { useMemo } from 'react';
const Section = ({ heading, children }) => {
const headingChild = useMemo(() => <h1>{heading}</h1>, [heading]);
return (
<section>
{headingChild}
{children}
</section>
@tommmyy
tommmyy / ramdaDebounce.js
Last active October 19, 2023 15:14
Debounce function using Ramda.js
import { curry, apply } from 'ramda';
/**
* Debounce
*
* @param {Boolean} immediate If true run `fn` at the start of the timeout
* @param timeMs {Number} Debounce timeout
* @param fn {Function} Function to debounce
*
* @return {Number} timeout
@tommmyy
tommmyy / countEvenDigits.js
Last active July 22, 2017 22:15
Count even digits in a number.
import { modulo, o, not, curry, compose, length, filter, split, map } from 'ramda';
// Number -> Number
const isOdd = o(Boolean, modulo(2));
// Number -> Boolean
const isEven = o(not, isOdd);
// (a -> Boolean) -> [a] -> Number
const countIf = curry(compose(length, filter));