Skip to content

Instantly share code, notes, and snippets.

Avatar

Will will-wow

View GitHub Profile
@will-wow
will-wow / applicative_functors_cool.md
Last active Jun 12, 2017
Applicative Functors - Other Cool Stuff
View applicative_functors_cool.md

Applicative Functors Part II

const

const x is a function that returns x for all inputs.

const :: a -> b -> a
const x _ = x

const 1 2 = 1
const 1 3 = 1
@will-wow
will-wow / .tmux-osx.conf
Created Jul 25, 2017
Copying and Pasting with tmux 2.4+
View .tmux-osx.conf
# Unbind from non-macOS setup
unbind-key -T copy-mode-vi 'y'
# Copy now goes to macOS clipboard
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
@will-wow
will-wow / average-triangle-1.js
Last active Dec 20, 2017
Easy pipeline debugging with curried console.log
View average-triangle-1.js
import * as R from 'ramda';
const multiplySides = R.reduce(R.multiply, 1);
const divideByTwo = R.divide(2);
const averageTriangle = R.pipe(
R.map(multiplySides),
R.map(divideByTwo),
R.mean
);
@will-wow
will-wow / user-component1.jsx
Last active Aug 9, 2018
Using Elixir-Style Modules in JavaScript
View user-component1.jsx
import React from ‘react’;
import {userType, fullName} from ./user’;
const UserComponent = user => (
<div>Name: {fullName(user)}</div>
);
UserComponent.propTypes = {
user: userType
};
@will-wow
will-wow / react.code-snippets
Created May 21, 2019
VSCode Snippets for a React/Redux/Jest/Enzyme Project
View react.code-snippets
{
"jest-component": {
"prefix": "jestcomponent",
"body": [
"import React from 'react';",
"import { shallow } from 'enzyme';",
"import $1 from '../$1';",
"",
"describe('$1', () => {",
" let props;",
@will-wow
will-wow / authors-active-author-test.js
Last active Jul 23, 2019
Sample code for a blog post about shallow-testing hooks
View authors-active-author-test.js
describe("given selected author", () => {
beforeEach(() => {
// Expect one more render loop of useEffect
mockUseEffect();
mockUseEffect();
// Trigger the select action
wrapper
.find("Author")
.first()
@will-wow
will-wow / big-grid-memo.js
Created Jul 23, 2019
Sample code for a blog post about Optimizing Performance in React 18.6
View big-grid-memo.js
import React from "react";
const BigGrid = ({ number }) => {
...
};
export default React.memo(BigGrid);
View 01-countdown-react.jsx
import React, { useState } from "react"
const CountDown = () => {
const [count, setCount] = useState(0)
const remaining = 10 - count
const increment = () => {
if (remaining > 0) {
setCount(count + 1)
@will-wow
will-wow / reactive.ts
Created Jan 26, 2020
RxJS functions with React Hooks
View reactive.ts
/* eslint-disable react-hooks/exhaustive-deps */
import React from "react";
export const useCombineLatest = <T extends any[], U>(
values: T,
f: (...values: T) => U
): U => {
return React.useMemo(() => f(...values), [f, ...values]);
};
View AppWithBoundingBoxes.ts
export const App: FunctionComponent = () => {
const [videoRef, status] = useWebcam();
{
/* Hooks... */
}
return (
<PredictionWrapper status="none">
{/* ... */}