Skip to content

Instantly share code, notes, and snippets.

View mvbattan's full-sized avatar

Batu mvbattan

  • Buenos Aires
View GitHub Profile
@mvbattan
mvbattan / PointsPath.js
Created April 7, 2017 15:56
createPoint
export const createPoint = (coordinates, color, size = 8) => {
return {
backgroundColor: color,
left: coordinates.x - 3,
bottom: coordinates.y - 2,
position: 'absolute',
borderRadius: 50,
width: size,
height: size
};
@mvbattan
mvbattan / PointsPath.js
Created April 7, 2017 16:01
createLine
export const createLine = (dist, angle, color, opacity, startingPoint) => {
return {
backgroundColor: color,
height: 4,
width: dist,
bottom: dist * Math.sin(angle) / 2 + startingPoint.y,
left: -dist * (1 - Math.cos(angle)) / 2 + startingPoint.x,
position: 'absolute',
opacity,
transform: [
@mvbattan
mvbattan / pulgassaltarinas.py
Last active November 27, 2017 22:59
Pulgas Saltarinas por backtracking !
#!/usr/bin/python3
import sys
from time import time
from math import sqrt
from random import uniform
UP = 0
RIGHT = 1
DOWN = 2
@mvbattan
mvbattan / actions.js
Created December 11, 2017 15:15
privateActionCreators
import SoccerService from '../services/SoccerService';
export const actions = createTypes([
'GET_MATCHES',
'GET_MATCHES_SUCCESS',
'GET_MATCHES_FAILURE',
'GET_PITCHES',
'GET_PITCHES_SUCCESS',
'GET_PITCHES_FAILURE'
], '@SOCCER');
@mvbattan
mvbattan / reducer.js
Last active December 5, 2018 14:48
Disable complexity
import { actions } from './actions';
const initialState = {
matches: [],
matchesLoading: false,
matchesError: null,
pitches: [],
pitchesLoading: false,
pitchesError: null
};
@mvbattan
mvbattan / reducer.js
Last active June 4, 2018 15:29
Reducer description
const reducerDescription = {
[actions.GET_MATCHES]: (state, action) => ({ ...state, matchesLoading: true }),
[actions.GET_MATCHES_SUCCESS]: (state, action) => ({
...state,
matchesLoading: false,
matchesError: null,
matches: action.payload
}),
[actions.GET_MATCHES_FAILURE]: (state, action) => ({
...state,
@mvbattan
mvbattan / reducer.js
Last active July 19, 2019 19:57
createReducer
function createReducer(initialState, reducerObject) {
return (state = initialState, action) => (
(reducerObject[action.type] && reducerObject[action.type](state, action)) || state;
);
}
export default createReducer(initialState, reducerDescription);
@mvbattan
mvbattan / actions.js
Created December 11, 2017 17:28
Targeted actions
const privateActionCreators = {
getMatchesSuccess: matchList => ({
type: actions.GET_MATCHES_SUCCESS,
payload: matchList,
target: 'matches'
}),
getMatchesError: error => ({
type: actions.GET_MATCHES_ERROR,
payload: error,
target: 'matches'
@mvbattan
mvbattan / reducer.js
Created December 11, 2017 17:31
Handlers with effects
const reducerDescription = {
[actions.MATCHES]: onLoading(),
[actions.MATCHES_SUCCESS]: onSuccess(),
[actions.MATCHES_FAILURE]: onFailure(),
[actions.PITCHES]: onLoading(),
[actions.PITCHES_SUCCESS]: onSuccess(),
[actions.PITCHES_FAILURE]: onFailure()
};
export default createReducer(initialState, reducerDescription);
@mvbattan
mvbattan / utils.js
Last active December 11, 2017 17:49
Effects
export function onLoading(selector = (action, state) => true) {
return (state, action) => ({ ...state, [`${action.target}Loading`]: selector(action, state) });
}
export function onSuccess(selector = (action, state) => action.payload) {
return (state, action) => ({
...state,
[`${action.target}Loading`]: false,
[action.target]: selector(action, state),
[`${action.target}Error`]: null