Skip to content

Instantly share code, notes, and snippets.

View jaredwilli's full-sized avatar
🏄‍♂️

Jared Williams jaredwilli

🏄‍♂️
View GitHub Profile
@oliverbenns
oliverbenns / visible.js
Created November 20, 2017 08:31
Hide/Show HOC
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 April 14, 2024 05:40
axios mocking via interceptors
import axios from 'axios'
let mockingEnabled = false
const mocks = {}
export function addMock(url, data) {
mocks[url] = data
}
@JamieMason
JamieMason / vs-code.sh
Last active May 5, 2022 07:35
Install favourite VS Code Extensions
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 September 19, 2020 20:41
ES6 Partial Application in 3 Lines

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 September 28, 2017 12:51
How to test a React component that sets its state in componentDidMount with fetch, and how to mock it, in Jest
// 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 September 14, 2017 22:13
Adapting HoC to RenderProps
////////////////////////////////////////////////////////////////////////////////
// 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 November 9, 2017 12:08
Git monsters
# 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'|'
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 }
@sirgallifrey
sirgallifrey / fetchData.js
Created August 5, 2017 02:10
is loged In HOC
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 July 26, 2017 13:56 — forked from jbub/squash-commits.sh
git squash last two commits into one
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