Skip to content

Instantly share code, notes, and snippets.

View andycarrell's full-sized avatar

Andy Carrell andycarrell

View GitHub Profile
const composeDecorators = (first, ...decorators) =>
decorators.reduce(
(accumulatedDecorators, nextDecorator) => storyFn =>
accumulatedDecorators(() => nextDecorator(storyFn)),
first,
);
// please don't
const ds = (i, ...r) => r.reduce((a, d) => f => a(() => d(f)), i);
password: Yup.string()
.required("Password is required")
.min(8, "Password must be at least 8 characters long")
.matches(/\d/, "Password must contain a number")
.matches(
/[\W_]/,
"Password must contain a non-alphanumberic character",
),
// new RegExp(`^((?!${name}).)*$`);
const useInputValue = initialValue => {
const [value, setX] = React.useState(initialValue);
const prop = p => o => o[p];
const setValue = Ramda.compose(
setX,
prop("value"),
prop("target"),
);
import { useCallback, useState } from "react";
export default function useMutation(mutate) {
const [isLoading, setIsLoading] = useState(false);
const [data, setData] = useState(null);
const [error, setError] = useState(null);
const runMutation = useCallback(
(...args) => {
setIsLoading(true);
class SetInterval extends React.Component {
componentDidMount() {
this.setNewInterval();
}
componentDidUpdate(prevProps) {
if (this.props.delay !== prevProps.delay) {
clearInterval(this.interval);
this.setNewInterval();
}
# bash
eval $(/opt/homebrew/bin/brew shellenv)
alias bashrefresh=". ~/.bash_profile"
alias bashopen="open ~/.bash_profile"
# fnm
eval "$(fnm env)"
# mac
alias big-sur="xcode-select --install"
// could you do something like this:
const actionsToTake = actions.filter(({ type }) => type.endsWith('_FAILURE'));
yield actionsToTake.map(action => takeEvery(action.type, genericSaga));
alias dkr-die="docker ps -a -q | xargs docker stop | xargs docker rm"
const cached = fn => {
const c = Object.create(null);
return a => {
if (a in c) return c[a];
const value = fn(a);
c[a] = value;
return value;
};
const AppContextConsumer = ({ children }) => (
<PermissionContext.Consumer>
{permissions => (
<ThemeContext.Consumer>
{theme => children({ permissions, theme })}
</ThemeContext.Consumer>
)}
</PermissionContext.Consumer>
);