Skip to content

Instantly share code, notes, and snippets.

View granmoe's full-sized avatar
🔔
Maximizing the frame rate, resolution, and screen size of my mind 😑

Matt Granmoe granmoe

🔔
Maximizing the frame rate, resolution, and screen size of my mind 😑
View GitHub Profile
@granmoe
granmoe / gitconfig
Last active May 16, 2018 18:19
temp-vscode-settings
[alias]
s = status
d = diff
c = checkout
co = commit
ps = push
l = log
p = pull
b = branch
[user]
@granmoe
granmoe / example.js
Last active November 10, 2018 21:21
A weird way of testing react hooks. It's interesting that it's possible, but you should do this instead: https://gist.github.com/granmoe/1316210dd63fc09bb012acfbcd0e28a8
// I like how this approach lets me test my hook as if it's a pure function,
// but something about this feels weird 🤔 🤫
test('use-validation', () => {
let counter = 0
render(
<Test>
{fields => {
const fooFuncs = {
onChange: fields.foo.onChange,
@granmoe
granmoe / hook-test.js
Created November 10, 2018 21:12
A way to test React hooks
import React from 'react'
import { render, fireEvent } from 'react-testing-library'
import useValidation from '..'
describe('use-validation', () => {
const Test = ({ mockFunc, handleSubmit }) => {
const { fields } = useValidation({
fields: {
foo: '',
bar: '',
@granmoe
granmoe / int-to-roman-numeral.js
Created February 6, 2019 02:11
Convert an integer of 9,999 or less to a roman numeral with JS (just a terrible JS interview question that got stuck in my head)
const convertToRomanNumerals = int => {
const romanNumerals = ['I', 'V', 'X', 'L', 'C', 'D', 'M']
const createRomanNumeralRange = (I, V, X) => [
'',
I,
`${I}${I}`,
`${I}${I}${I}`,
`${I}${V}`,
V,
`${V}${I}`,
/**
* Given an array of Person objects, returns the root PersonTreeNode (the CEO).
* @param {Person[]} employees - An array of Person objects representing all the employees of the company.
* @returns {PersonTreeNode} The CEO of the organization.
*/
function generateTree(employees) {
let ceo = null
const visitedById = new Map()
const visitedByManagerId = new Map()