Skip to content

Instantly share code, notes, and snippets.

🏄

Jared Williams jaredwilli

🏄
Block or report user

Report or block jaredwilli

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View visible.js
import React from 'react';
const visible = isVisible => Component => {
class VisibleComponent extends React.Component {
componentDidMount() {
this.unsubscribe = this.context.store.subscribe(this.handleChange.bind(this));
}
componentWillUnmount() {
this.unsubscribe();
@cowboy
cowboy / mock-axios.js
Last active Jan 20, 2020
axios mocking via interceptors
View mock-axios.js
import axios from 'axios'
let mockingEnabled = false
const mocks = {}
export function addMock(url, data) {
mocks[url] = data
}
@JamieMason
JamieMason / vs-code.sh
Last active Jan 11, 2019
Install favourite VS Code Extensions
View vs-code.sh
code --install-extension akamud.vscode-caniuse && \
code --install-extension andys8.jest-snippets && \
code --install-extension auiworks.amvim && \
code --install-extension bibhasdn.unique-lines && \
code --install-extension christian-kohler.npm-intellisense && \
code --install-extension cssho.vscode-svgviewer && \
code --install-extension dbaeumer.vscode-eslint && \
code --install-extension dzannotti.vscode-babel-coloring && \
code --install-extension eamodio.gitlens && \
code --install-extension eg2.tslint && \
@JamieMason
JamieMason / es6-partial-application.md
Last active May 27, 2019
ES6 Partial Application in 3 Lines
View es6-partial-application.md

ES6 Partial Application in 3 Lines

const pApply = (fn, ...cache) => (...args) => {
  const all = cache.concat(args);
  return all.length >= fn.length ? fn(...all) : pApply(fn, ...all);
};

Example

@alfonsomunozpomer
alfonsomunozpomer / Fetch.test.js
Created Sep 28, 2017
How to test a React component that sets its state in componentDidMount with fetch, and how to mock it, in Jest
View Fetch.test.js
// https://github.com/alfonsomunozpomer/react-fetch-mock
import React from 'react'
import fetchMock from 'fetch-mock'
import Enzyme from 'enzyme'
import {shallow, mount, render} from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
Enzyme.configure({ adapter: new Adapter() })
@mtomcal
mtomcal / HigherOrderComponents.jsx
Created Sep 14, 2017
Adapting HoC to RenderProps
View HigherOrderComponents.jsx
////////////////////////////////////////////////////////////////////////////////
// Exercise:
//
// Make `withMouse` a "higher-order component" that sends the mouse position
// to the component as props.
//
// Hint: use `event.clientX` and `event.clientY`
//
// Got extra time?
//
@codeocelot
codeocelot / git.sh
Last active Nov 9, 2017
Git monsters
View git.sh
# What the fuck just happened to this file?
git reflog -p --since=yesterday -- $file
# I forgot my branch name. What am I working on?
git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)'|column -ts'|'
View field.jsx
import Input from './input';
import Label from './label';
import FormGroup from './form-group';
export default function Field ({children, name, inline, ...props}) {
return (
<FormGroup inline={ inline }>
<Label inline={ inline } htmlFor={ name }>{ label }</Label>
<Input inline={ inline } { ...props } id={ name }>
{ children }
View fetchData.js
import React from 'react';
import Loader from '../components/loader';
export default function fetchData(url, options) {
return (Component) => class fetchComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
finished = false;
data = null;
@landsman
landsman / squash-commits.sh
Created Jul 26, 2017 — forked from jbub/squash-commits.sh
git squash last two commits into one
View squash-commits.sh
git rebase --interactive HEAD~2
# we are going to squash c into b
pick b76d157 b
pick a931ac7 c
# squash c into b
pick b76d157 b
s a931ac7 c
You can’t perform that action at this time.