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 / 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()
@granmoe
granmoe / form-validation-and-utils.jsx
Last active September 23, 2020 03:59
Simple react form validation plus a few tiny utilities, via a higher order component
import React from 'react'
export default options => {
return WrappedComponent => class FormValidation extends React.Component {
constructor () {
super()
this.validate = options.validate
this.state = options.fields.reduce((result, field) => {
result.fields.push(field)
@granmoe
granmoe / __responsive styled components
Last active January 6, 2021 02:22
Programmatically create responsive styled components with react and styled-components
// this file is just here to change the name of the gist
import React from 'react'
import styled from 'styled-components'
const makeResponsiveComponent = (rulesets, tagName = 'div') =>
styled(tagName)`${buildStyles(rulesets)}`
const buildStyles = rulesets =>
rulesets.reduce(
(cssString, { constraint, width, rules }) =>
@granmoe
granmoe / React Join Children
Last active December 7, 2022 14:50
Ever wanted to join react children like you join an array?
This file is only here to provide the title of the gist