Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
https://leanpub.com/composingsoftware

Eric Elliott ericelliott

💭
https://leanpub.com/composingsoftware
View GitHub Profile
@ericelliott
ericelliott / with-magic-link.js
Created Mar 30, 2020
withMagicLink HOC example.
View with-magic-link.js
View magic-link-tools.js
@ericelliott
ericelliott / use-local-storage.js
Created Mar 30, 2020
A localStorage drop-in replacement for useState
View use-local-storage.js
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;
View use-promise.js
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 Mar 5, 2020
TypeScript melts my brain.
View typescript-help.ts
// 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 Jan 17, 2020
A React hook for Fortmatic integration.
View use-fortmatic.js
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;
View tdd-scientific-method.md
Scientific Method TDD
Question Requirement
Prediction Expected Output
Experiment Test Assertion
Subject Implementation Code
@ericelliott
ericelliott / promise-monad-proof.js
Created Jun 28, 2017 — forked from briancavalier/promise-monad-proof.js
A proof that Promises/A is a Monad
View promise-monad-proof.js
//-------------------------------------------------------------
//
// 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 Sep 2, 2019
Class inheritance demo 2 (not recommended)
View class-inheritance-demo-2.js
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 }`);
}
@ericelliott
ericelliott / class-inheritance-demo.js
Last active Jan 30, 2017
Class inheritance demo (not recommended)
View class-inheritance-demo.js
class User {
constructor ({ name = 'Anonymous' }) {
this.name = name;
}
login () {
console.log(`${ this.name } logged in.`);
}
};
class Student extends User {
You can’t perform that action at this time.