Skip to content

Instantly share code, notes, and snippets.

View BarthesSimpson's full-sized avatar

BarthesSimpson

View GitHub Profile
@BarthesSimpson
BarthesSimpson / Form.js
Last active June 24, 2019 04:26
LetterInput with added characters
function Icon({ i, char, reverse = false }) {
const padding = Array.from({ length: i }, (_, i) => (
<span key={i}>&nbsp;</span>
))
return reverse ? [char, ...padding] : [...padding, char]
}
function Happy({ i }) {
return <Icon i={i} char="ᕕ( ᐛ )ᕗ" />
}
@BarthesSimpson
BarthesSimpson / Form.js
Created June 24, 2019 04:12
Memoized LetterInput
const MLetterInput = memo(
LetterInput,
({ value: _old }, { value: _new }) => _old === _new
)
//... Inside the render method of <Form/>
{Object.keys(alphabet).map((l, i) =>
state.itMatters ? (
<MLetterInput
@BarthesSimpson
BarthesSimpson / User.js
Last active June 24, 2019 04:17
Hook for simulating some typing
import { useEffect } from "react"
const TIMER_WINDOW = 20000
const TYPING_DELAY = 20
const MAX_LENGTH = 20
export const useTyping = (setState) =>
useEffect(() => {
const inputs = document.getElementsByClassName("input-letter")
Array.from(inputs).forEach((el, idx) => {
@BarthesSimpson
BarthesSimpson / Form.js
Last active June 24, 2019 04:02
Simple Form
function Form({ state, setState }) {
const toggle = useCallback(() => {
setState(state => ({ ...state, itMatters: !state.itMatters }))
})
const changeLetter = useCallback(l => e =>
setState(state => ({ ...state, [l]: e.target.value }))
)
return (
<form name="f">
<h2>Does unnecessary re-rendering matter? </h2>
@BarthesSimpson
BarthesSimpson / int_to_numeral.py
Created January 27, 2019 21:58
Integers to Numerals
class Solution:
I = 'I'
V = 'V'
X = 'X'
L = 'L'
C = 'C'
D = 'D'
M = 'M'
def intToRoman(self, num):
"""