Skip to content

Instantly share code, notes, and snippets.

View dangreenisrael's full-sized avatar
👨‍💻
Chasing toddlers and writing code

Dan Green-Leipciger dangreenisrael

👨‍💻
Chasing toddlers and writing code
View GitHub Profile
@dangreenisrael
dangreenisrael / recommended-config.yml
Last active August 13, 2019 13:00
Recommended Chromatic CircleCI config
@dangreenisrael
dangreenisrael / Proptypes.ts
Last active June 17, 2019 16:11
Conditional props
/*
* This forces you to have at least one of : isReadOnly, isDisabled, or onChange
*/
import React from "react";
interface ContainsReadonly {
isReadOnly: boolean;
}
const clearAll = obj => {
const clearMock = member => {
member.mockClear && member.mockClear()
}
Object.keys(obj).forEach(key => clearMock(obj[key]));
}
@dangreenisrael
dangreenisrael / proto-to-ts.txt
Created March 1, 2019 03:12
Protobuf => Typescript
// protobuf
// model.proto
syntax = "proto3";
package model;
message Collection {
optional string id = 1;
optional string name = 2;
optional string description = 3;
@dangreenisrael
dangreenisrael / refactor.jsx
Last active June 19, 2018 13:05
Zi refactor
const Resumitable = props => (
<WaveButton
isDisabled={props.isResubmitting}
isLoading={props.isResubmitting}
type={WaveButtonTypes.SECONDARY}
onClick={props.onClick} >
{props.text}
</WaveButton>
)
const A = () => <h1> Foo </h1>
const B = () => <h1> Bar </h1>
const AorB = props => props.isBusinessOwner ? <A> : <B>;
const Parent = props => (
<div>
Haaaaay!!!
<AorB isBusinessOwner={props.isBusinessOwner}/>
</div>
)
@dangreenisrael
dangreenisrael / getRegexCaptures.js
Last active March 18, 2018 23:05
JavaScript function to get all capture groups for a global regex.
const getRegexCaptures = (regex, string) => {
const getMatches = (cursor, results = []) => {
const exp = regex.exec(string);
if (!exp) {
return results;
}
return getMatches(exp, [...results, exp[1]]);
};
return getMatches();
};