Skip to content

Instantly share code, notes, and snippets.

View ericelliott's full-sized avatar
💭
https://leanpub.com/composingsoftware

Eric Elliott ericelliott

💭
https://leanpub.com/composingsoftware
View GitHub Profile
import { compose } from 'lodash/fp';
import withFeatures from './with-features';
import withEnv from './with-env';
import withLoader from './with-loader';
import withCoupon from './with-coupon';
import withLayout from './with-layout';
import withAuth from './with-auth';
import { withRouter } from 'next/router';
import withMagicLink from '../features/ethereum-authentication/with-magic-link';
@ericelliott
ericelliott / with-magic-link.js
Created March 30, 2020 23:51
withMagicLink HOC example.
@ericelliott
ericelliott / magic-link-tools.js
Created March 30, 2020 23:37
Magic link tools
@ericelliott
ericelliott / use-local-storage.js
Created March 30, 2020 23:34
A localStorage drop-in replacement for useState
import { useState } from 'react';
const configureLocalStorage = key => initialValue => {
const [state, setState] = useState(() => {
try {
const value = localStorage.getItem(key);
return value ? JSON.parse(value) : initialValue;
} catch (e) {
console.log(e);
return initialValue;
@ericelliott
ericelliott / use-promise.js
Created March 30, 2020 23:32
usePromise hook
import { useRef } from 'react';
const usePromise = () => {
const ref = [];
const container = useRef(ref);
ref[0] = new Promise((resolve, reject) => {
ref[1] = resolve;
ref[2] = reject;
});
@ericelliott
ericelliott / typescript-help.ts
Created March 5, 2020 23:45
TypeScript melts my brain.
// Trying to replicate this easy-as-pie Haskell type:
// fmap:: (a -> b) -> f a -> f b
// And failing miserably.
// OK, verbose, but I think we're on the right track...
// First, we define functor.
interface Functor<T> {
map<U> (f: (x: T) => U): Functor<U>
}
@ericelliott
ericelliott / use-fortmatic.js
Created January 17, 2020 01:30
A React hook for Fortmatic integration.
import { useState, useEffect, useRef } from 'react';
import Web3 from 'web3';
import Fortmatic from 'fortmatic';
const usePromise = () => {
const ref = [];
const container = useRef(ref);
ref[0] = new Promise((resolve, reject) => {
ref[1] = resolve;
Scientific Method TDD
Question Requirement
Prediction Expected Output
Experiment Test Assertion
Subject Implementation Code
@ericelliott
ericelliott / promise-monad-proof.js
Created June 28, 2017 02:57 — forked from briancavalier/promise-monad-proof.js
A proof that Promises/A is a Monad
//-------------------------------------------------------------
//
// Hypothesis:
//
// Promises/A is a Monad
//
// To be a Monad, it must provide at least:
// - A unit (aka return or mreturn) operation that creates a corresponding
// monadic value from a non-monadic value.
// - A bind operation that applies a function to a monadic value
@ericelliott
ericelliott / class-inheritance-demo-2.js
Last active September 2, 2019 02:23
Class inheritance demo 2 (not recommended)
class Teacher extends User {
constructor (options) {
super(options);
this.lessons = [];
}
createLesson (lesson) {
const { name } = lesson;
this.lessons.push(lesson);
console.log(`${ this.name } created lesson: ${ name }`);
}