Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Rhodes jasonrhodes

View GitHub Profile
View math.md

Student Fit Problem

T is the number of total students
n is the number of teachers/classes
c is the number of students per class

c = T / n

for every value of n, I want to also compute r, or "the number of students you can add to T to get c to rise to the next whole number"

View TrackVisit.js
import { trackUiMetric } from '../wherever'
export function TrackVisit({ app, path, delay = 0 }) {
if (!delay) {
trackUiMetric(app, `visit__${path}`) // something like visit__transactions_list_page
}
useEffect(() => {
if (!delay) {
return;
}
@jasonrhodes
jasonrhodes / yarn.lock
Created May 29, 2019
Mulltiple copies of package in yarn.lock ... why?
View yarn.lock
react@^16.2.0, react@^16.6.0, react@^16.8.0:
version "16.8.2"
resolved "https://registry.yarnpkg.com/react/-/react-16.8.2.tgz#83064596feaa98d9c2857c4deae1848b542c9c0c"
integrity sha512-aB2ctx9uQ9vo09HVknqv3DGRpI7OIGJhCx3Bt0QqoRluEjHSaObJl+nG12GDdYH6sTgE7YiPJ6ZUyMx9kICdXw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.2"
View exclusive-or.ts
type Neverize<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
type ExclusiveOr<T, U> = (T | U) extends object
? (Neverize<T, U> & U) | (Neverize<U, T> & T)
: T | U;
interface S {
value: string;
string: string;
}
@jasonrhodes
jasonrhodes / debug-diff.js
Last active Nov 30, 2018
Compares two objects and gives you detailed diff results about added, removed, changed, and ref-only changes
View debug-diff.js
/**
* flattens an object into a single dimension with dot-separated key paths
*
* e.g.
* const test = { a: 'hello', b: { xx: 'cool', yy: 'yeah' }, c: [1, 2] }
* flatten(test) => { 'a': 'hello', 'b.xx': 'cool', 'b.yy': 'yeah', 'c.0': 1, 'c.1': 2 }
*/
function flatten(o, path = []) {
return Object.entries(o).reduce((result, [key, value]) => {
const localPath = [...path, key];
@jasonrhodes
jasonrhodes / kibana-build-flow.md
Last active Nov 26, 2018
Schoolhouse Rock: How a Kibana becomes a build (specifically client-side webpack)
View kibana-build-flow.md
@jasonrhodes
jasonrhodes / why.js
Created Nov 2, 2018
implicit function naming quirk?
View why.js
// file1a.js
const CoolName = () => 'cool'
export { CoolName }
// file2a.js
import { CoolName } from './file1a'
console.log(CoolName.name) // -> "CoolName"
/**
View git-clean-stale-branches
#!/bin/sh
#
# Suggested name for this script: git-clean-stale-branches
#
# This script will help to remove "stale" branches from a remote
# repository (by default the "origin" repository). Stale branches
# are any branches that does not exist in the local repository.
#
# This script should be run in the local repository. It will print
# out a git command to remove all branches from the remote repository
View redux-async-hell.js
// these examples use thunks but the problem applies to most other redux async strategies
// action creator 1: get user
const getUser = async (id) => (dispatch) => {
dispatch({ type: 'GET_USER_PENDING', payload: id })
try {
const result = await doAsyncThing(id)
return dispatch({ type: 'GET_USER_SUCCESS', payload: result })
} catch (error) {
return dispatch({ type: 'GET_USER_FAILED', payload: error })
@jasonrhodes
jasonrhodes / render-props.jsx
Last active May 17, 2018
React HOCs and "Render Props" ... Note: If we're going to call it the "render prop" pattern, can we stop using props.children as the function?
View render-props.jsx
// higher order component creator
const withFun = (Component) => (props) => <Component {...props} fun='Injected Secret Value' />
// using the higher order component (with this pattern, you have to create a component, THEN wrap it in the HOC creator function)
const _MyComponent = (props) => <div><h1>{props.fun}</h1></div>
const MyComponent = withFun(_MyComponent)
// "render prop" using children
You can’t perform that action at this time.