Skip to content

Instantly share code, notes, and snippets.

import * as React from "react";
interface WordBreakProps {
value: string;
on?: string | string[] | RegExp;
}
/**
* Insert <wbr/> element into long text string according to matching rules
*
@zachfedor
zachfedor / useAsync.ts
Created June 10, 2022 16:49
React Async Hook
/**
* Hook to create safe useReducer dispatch function
*
* This only runs a dispatch if the component is still mounted, otherwise it
* returns undefined to prevent memory leaks from async functions, for example.
*/
const useSafeDispatch = <T>(dispatch: React.Dispatch<T>) => {
// The component is not rendered yet when hook is first called in the component logic
const isMounted = React.useRef(false);
@zachfedor
zachfedor / setup.sh
Last active September 22, 2020 14:29
CSET MacBook Setup
# Install Xcode Command Line Tools
xcode-select --install
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew update
# Test it out
brew cask install google-chrome
brew cask install firefox
@zachfedor
zachfedor / walter-calculator.js
Created August 1, 2017 12:59
A tiny module to calculate how many Walters you can afford.
const WALTER_PRICE = 0.53;
const TARE_PRICE = 0.08;
function round(f) {
return Math.round(f*Math.pow(10,2))/Math.pow(10,2);
}
function getNumWalters(money) {
var ret = [0, 0];
ret[0]=Math.floor(money/WALTER_PRICE);
@zachfedor
zachfedor / buggy.html
Created July 13, 2017 18:26
Demo to show mutations of nested objects logged to Chrome's Developer Console
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>buggy html</title>
<script>
const object = { nested: { state: 'before' } };
// create a nested object
getCountries() {
fetch('/api/endpoint/countries').then((data) => {
this.setState({ countries: data });
})
}
getCities(country) {
fetch(`/api/endpoint/countries/${country}/cities`).then((data) => {
this.setState({ cities: data });
@zachfedor
zachfedor / option-one.js
Created March 9, 2017 16:09
react component import convention
// ./App.js
import React from 'react';
import ComponentOne from './componentGroup/ComponentOne';
import ComponentTwo from './componentGroup/ComponentTwo';
class App extends React.Component {
render() {
return (
<div>
<ComponentOne />
@zachfedor
zachfedor / readme.md
Created March 1, 2017 21:18
Testing Readme
@zachfedor
zachfedor / nestedConcat.js
Created December 12, 2016 15:15
Concat Arbitrarily Nested Arrays
/*
* Will flatten an array of arbitrarily nested arrays of any type into a flat array
*
* @param {array} array containing any type
* @return {array} flattened array
*/
const nestedConcat = (array) => {
// flatten the first layer of arrays
const results = [].concat.apply([], array);

Keybase proof

I hereby claim:

  • I am zachfedor on github.
  • I am zachfedor (https://keybase.io/zachfedor) on keybase.
  • I have a public key ASCq8YRoLVUQ1U-bdQnxVVitiFYzqolEDwIBwAQHFOoDigo

To claim this, I am signing this object: