Skip to content

Instantly share code, notes, and snippets.

View mcabreradev's full-sized avatar
🎯
Focusing

Miguelángel Cabrera mcabreradev

🎯
Focusing
View GitHub Profile
@mcabreradev
mcabreradev / actions.js
Created October 20, 2018 03:18
React Redux cheatsheet
import { FETCH_DATA } from './types';
export const fetchRestaurants = () => async (dispatch, getState) => {
try {
const response = await axios.get("/service");
const data = response.data.data;
dispatch({
type: FETCH_DATA,
// Initialize an empty array of length n. Use Array.prototype.reduce() to add values into the array, using the sum of the last two values, except for the first two.
const fibonacci = n =>
[...Array(n)].reduce(
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[]
)
const _$ = $;
setInterval(function(){
_$("#mm_cc > div > header > div.profile-header__vote.js-profile-header-buttons > div.profile-header__vote-item.profile-header__vote-item--yes.js-tutorial-first-yes > div > span").click()
}, 2000);
///////
setInterval(function(){
let items = [
{name:"A", value:2},
{name:"B", value:3},
{name:"A", value:4},
];
let result = [];
items.map((item, index) => {
@mcabreradev
mcabreradev / fruits.js
Last active September 22, 2017 07:48
Demo Promesas
const fruits = ['apple', 'peach', 'lime', 'watermelon']; // Array de frutas
function getFruit(fruit) {
return new Promise((resolve, reject) => { // Se crea la promesa con los 2 parámetros
// Se busca en el array si existe la fruta
if (fruits.find(item => item === fruit)) {
resolve(`${fruit} was found!`); // Se resuelve la promesa
} else {
reject(Error('no fruit was found!')); // Se rechaza la promesa
@mcabreradev
mcabreradev / cloudSettings
Last active August 19, 2020 22:34
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-06-25T21:31:00.119Z","extensionVersion":"v3.4.3"}
@mcabreradev
mcabreradev / filter.es6.js
Last active October 18, 2018 16:32
Angular filter to vanilla javascript
export const filter = (array, expression, comparator, anyPropertyKey) => {
if (isArrayLike(array)) {
if (array == null) {
return array;
} else {
throw minErr('filter')('notarray', 'Expected array but received: {0}', array);
}
}
@mcabreradev
mcabreradev / Input.vue
Last active June 2, 2017 17:16
Table.vue
<template>
<div>
<input v-if="field.type === 'text'"
class="form-control"
type="text"
v-bind:id="field.id"
v-model.trim="data[field.name]"
v-bind:name="field.name"
v-bind:placeholder="field.title"
v-bind:required="field.required">
@mcabreradev
mcabreradev / ng-image-onload.js
Created May 6, 2017 03:36 — forked from kmaida/ng-image-onload.js
AngularJS image onload directive
app.module['myApp'].directive('imageOnload', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('load', function() {
// call the function that was passed
scope.$apply(attrs.imageOnload);
// usage: <img ng-src="src" image-onload="imgLoadedCallback()" />
});
@mcabreradev
mcabreradev / angularjs_directive_attribute_explanation.md
Created February 23, 2017 17:41 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>