Skip to content

Instantly share code, notes, and snippets.

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

Jared Williams jaredwilli

🏄‍♂️
View GitHub Profile
@codeocelot
codeocelot / MuiThemeProvider.js
Created October 15, 2016 22:52
Material UI's MuiThemeProvider Component
import {Component, PropTypes} from 'react';
import getMuiTheme from './getMuiTheme';
class MuiThemeProvider extends Component {
static propTypes = {
children: PropTypes.element,
muiTheme: PropTypes.object,
};
@codeocelot
codeocelot / react-redux-provider.js
Created October 15, 2016 22:43
React Router Provider
export default class Provider extends Component {
getChildContext() {
return { store: this.store }
}
constructor(props, context) {
super(props, context)
this.store = props.store
}
@codeocelot
codeocelot / simple-react-context.js
Last active November 9, 2017 12:11
Simple React Context Example
class App extends React.Component{
render = () => <div className="app">{this.props.children}</div>
}
class Greeting extends React.Component{
render = () => <p style={this.context.style}>Hello world!</p>
}
Greeting.contextTypes = {
color: React.PropTypes.string,
backgroundColor: React.PropTypes.string
}
@sebmarkbage
sebmarkbage / asyncToReact.js
Last active March 31, 2023 15:57
Convert Async Function to React Component
function asyncToReact(fn) {
class PromiseComponent extends React.Component {
state = { waiting: true, result: null };
componentDidMount() {
fn(...this.props.args).then(result => this.setState({ waiting: false, result }));
}
componentDidUpdate() {
fn(...this.props.args).then(result => this.setState({ waiting: false, result }));
}
shouldComponentUpdate(newProps) {
@tallykatt
tallykatt / debug.js
Created July 25, 2016 01:16 — forked from dftaiwo/debug.js
JS Console Logging For Production & Debug Builds
var debugMode=false;
//.....
function logMessage() {
if(!debugMode) return;
console.log(Array.prototype.slice.call(arguments) );
}
@framp
framp / fizzbuzz.js
Last active October 31, 2017 11:59
Mattia Asti Challenge 2016
const assert = require('assert')
const identity = a => a
const add = a => b => b + a
const call = a => b => b(a)
const multiple = a => b => b%a === 0
const get = a => b => b[a]
const desc = (a, b) => b-a
const makeArray = (start, end) =>
@paulirish
paulirish / index.html
Last active March 7, 2019 00:55
array augmenting: push read vs concat (http://jsbench.github.io/#e412522baff1e164b3dd1c679f2f0845) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>array augmenting: push read vs concat</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
// where `db` is a `Firebase` ref
export function checkIfUserExists(authData) {
return db
.child('users')
.child(authData.uid)
.once('value')
.then(dataSnapshot => {
return Promise.resolve({
authData,
@markerikson
markerikson / redux-thunk-examples.js
Last active June 28, 2024 05:30
Redux-Thunk examples
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(
response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}),
error => dispatch({type : "REQUEST_FAILED", error : error})
);
@framp
framp / uniqueByFunction.js
Created May 3, 2016 13:58
unique by function
const users = [{userId:"34"},{userId: "10"}, {userId: "1"}, {userId: "1"}]
const sameUserId = (a, i) => (b, j) => a.userId === b.userId && j>i
users.filter((value, index, array) => array.findIndex(sameUserId(value, index)) < 0)