Skip to content

Instantly share code, notes, and snippets.

View mvbattan's full-sized avatar

Batu mvbattan

  • Buenos Aires
View GitHub Profile
@mvbattan
mvbattan / AnotherService.js
Created November 28, 2018 21:25
dService
import { wrapService, withPostSuccess } from 'redux-recompose';
import responseBody from './response';
// Declare your api calls
const getCards = async () => new Promise(resolve => setTimeout(() => resolve(responseBody), 1000));
// Declare your customizations, used by fetchMiddleware
getCards.successSelector = response => response.cards;
getCards.injections = [
@mvbattan
mvbattan / index.js
Last active November 28, 2018 21:18
A component using dServices
import React, { Component } from 'react';
import { connect } from 'react-redux';
import SoccerService from '../Services/SoccerService.js';
class MatchList extends Component {
componentDidMount() {
this.props.dispatch(SoccerService.getMatches());
}
@mvbattan
mvbattan / SoccerService.js
Created November 28, 2018 21:06
Dispatcheable Service
import { wrapService } from 'redux-recompose';
import api from '../config/api';
const service = {
getMatches: () => api.get('/matches'),
getPitches: ({ id }) => api.get('/pitches', { id }),
};
export default wrapService(service, 'soccer');
import api from '../config/api';
export default {
getMatches: () => api.get('/matches'),
getPitches: ({ id }) => api.get('/pitches', { id }),
};
@mvbattan
mvbattan / actions.js
Created November 28, 2018 20:53
External actions usage
import { createActions, createExternalActions } from 'redux-recompose';
// Our action names, as always. These will be handled by our reducer.
export const actions = createActions(['LOCAL_ACTION'], '@@SOCCER');
// External actions names being handled by the invisible reducer. We should specify
// what slice of the state is related with this reducer, say, state.soccer
// No need to handle them at our reducer.
const $ = createExternalActions('soccer');
@mvbattan
mvbattan / commonReducer.js
Created November 28, 2018 20:42
Common reducer
import createReducer from '../../creators/createReducer';
import onLoading from '../../effects/onLoading';
import onSuccess from '../../effects/onSuccess';
import onFailure from '../../effects/onFailure';
// TODO: Let the user specify selectors
const reducerDescription = {
LOADING: onLoading(),
SUCCESS: onSuccess(),
FAILURE: onFailure()
@mvbattan
mvbattan / store.js
Created November 28, 2018 20:38
Configuring CR
import { combineReducers as CR } from 'redux';
import { wrapCombineReducers } from 'redux-recompose';
const combineReducers = wrapCombineReducers(CR);
const rootReducer = combineReducers({
// Add here your reducers like always.
});
@mvbattan
mvbattan / actions.js
Created November 28, 2018 20:31
using fetchMiddleware
import SoccerService from '../services/SoccerService';
export const actions = createTypes(completeTypes['GET_MATCHES','GET_PITCHES'], '@SOCCER');
const actionCreators = {
getMatches: () => ({
type: actions.GET_MATCHES,
target: 'matches',
service: SoccerService.getMatches
}),
@mvbattan
mvbattan / actions.js
Last active November 29, 2018 13:44
createThunkAction with named params
import SoccerService from '../services/SoccerService';
export const actions = createTypes(completeTypes['GET_MATCHES','GET_PITCHES'], '@SOCCER');
const actionCreators = {
getMatches: () => createThunkAction({
type: actions.GET_MATCHES,
target: 'matches',
service: SoccerService.getMatches
}),
@mvbattan
mvbattan / generator.py
Created September 7, 2018 05:15
Ejercicio 3 - Generator
# Taken from https://stackoverflow.com/a/44308018
from scipy.stats import norm, truncnorm
import matplotlib.pyplot as plt
from numpy import array
from math import pi, cos
SAMPLE_SIZE = 200
def get_truncated_normal(mean=0, sd=1, low=0, upp=10):
return truncnorm(