Skip to content

Instantly share code, notes, and snippets.

View cocodrino's full-sized avatar
🏠
Working from home

carlos L cocodrino

🏠
Working from home
  • Venezuela
View GitHub Profile
@tracker1
tracker1 / MyComponent.jsx
Last active July 8, 2019 12:48
Simple pattern for loading async data with react, redux and redux-thunk middleware
import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as Actions from './action';
const mapStateToProps = ({ loaded, loading, error, data }) = ({ loaded, loading, error, data });
const mapDispatchToProps = dispatch => ({ action: bindActionCreators(Actions, dispatch) });
export class MyComponent extends Component {
load = _ => this.props.action.load(this.props.id);
@Jonplussed
Jonplussed / monadic_builtins.rs
Last active August 29, 2015 14:06
Add applicative `fmap` and monadic `bind` to Rust's builtin enums
trait MonadicOpt<T> {
fn fmap<U>(self, f: |T| -> U) -> Option<U>;
fn bind<U>(self, f: |T| -> Option<U>) -> Option<U>;
}
impl<T> MonadicOpt<T> for Option<T> {
fn fmap<U>(self, f: |T| -> U) -> Option<U> {
match self {
Some(x) => Some(f(x)),
_ => None,
@RoboTeddy
RoboTeddy / keyboard.coffee
Last active August 29, 2015 14:03
Bacon.js keyboard
Bacon = require 'Bacon'
_ = require 'underscore'
$ = require 'jquery'
# Reference: http://unixpapa.com/js/key.html
# IE = IE keycodes (webkit, IE)
# MZ = Mozilla keycodes (gecko)
# Opera = Opera keycodes (opera)
# US locale specific. About as well as can be done without browser detection.