Skip to content

Instantly share code, notes, and snippets.

View sleep.js
export default function sleep(ms = 0) {
 return new Promise(r => setTimeout(r, ms));
}
View game-actions.js
const start = createAction(START_GAME);
const next = createAction(NEXT_LEVEL);
const startGame = payload => start({ next: getRandomId() });
const nextLevel = payload => next({ next: getRandomId() });
startGame(); // { type: ‘START_GAME’, payload: { next: ‘red’ } }
startGame(); // { type: ‘START_GAME’, payload: { next: ‘blue’ } }
startGame(); // { type: ‘START_GAME’, payload: { next: ‘yellow’ } }
View actions.js
const lightenPad = createAction(LIGHTEN_PAD);
const lightenOffPad = createAction(LIGHTEN_OFF_PAD);
lightenPad({ id: 'green' }); // { type: 'LIGHTEN_PAD', payload: { id: 'green' } };
lightenOffPad(); // { type: 'LIGHTEN_OFF_PAD', payload: {} };
function pads(state, action) {
const { type, payload } = action;
switch(type) {
case LIGHTEN_PAD:
View Player.js
import React, { Component } from 'react';
import audios from '../audios';
import { connect } from 'react-redux';
export class Player extends Component {
componentDidUpdate() {
const { active } = this.props;
const player = this.refs[active];
if (!player) {
View state.js
{
 pads: [
{
id: ‘green’,
component: ‘GreenPad’,
active: false
},
// More pads here
 ],
 game: {
View Pad.js
import color from ‘color’; // a simple color helper library
import styled from ‘styled-components’;
const lighten = from => color(from).lighten(0.333).hexString();
const activeCSS = props => `
 background-color: ${lighten(props.color)} !important;
`;
export const Pad = styled.div`
 /* some styles here … */
${(props) => props.active ? activeCSS(props) : ‘’}
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View changelog.sh
git log --first-parent --pretty=format:'%s' \
| grep -v '^update changelog' \
| perl -p -e 's/^((v?[0-9]+\.?)+)$/\n## \1\n/g' \
| perl -p -e 's/^([^#\s].*)$/* \1/g'
View crashReporter.js
const crashReporter = store => next => action => {
try {
return next(action)
} catch (err) {
console.error('Caught an exception!', err)
// capture error somehow here: action, store.getState()
throw err;
}
}
@weslleyaraujo
weslleyaraujo / iffy.js
Last active Feb 18, 2016
add behavior on input's based on values
View iffy.js
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('jquery'));
} else {
root.Iffy = factory(root.$);
}