Skip to content

Instantly share code, notes, and snippets.

View Ifmr24's full-sized avatar
😄

Fabian Mesias Ifmr24

😄
  • Santiago
  • 08:33 (UTC -04:00)
View GitHub Profile
@Ifmr24
Ifmr24 / allSettled.js
Created March 26, 2022 00:17
allSettled example
const items = Array.from({length: 10})
const handler = async () => {
const promises = await items.map((item) => {
const bool = Boolean(Math.random() < 0.5)
if (bool) {
return Promise.resolve('True')
}else {
return Promise.reject('False')
}
@Ifmr24
Ifmr24 / peru.json
Created January 23, 2021 02:08
peru provincias
[
{ "name": "Abancay", "code": "PE-APU" },
{ "name": "Acobamba", "code": "PE-HUV" },
{ "name": "Acomayo", "code": "PE-CUS" },
{ "name": "Aija", "code": "PE-ANC" },
{ "name": "Alto Amazonas", "code": "PE-LOR" },
{ "name": "Ambo", "code": "PE-HUC" },
{ "name": "Andahuaylas", "code": "PE-APU" },
{ "name": "Angaraes", "code": "PE-HUV" },
{ "name": "Anta", "code": "PE-CUS" },
@Ifmr24
Ifmr24 / style.css
Created September 8, 2020 23:00
aspect ratio css
.post {
width:320px;
position: relative;
background-color: #dbdbdb;
}
.post::after {
display: block;
content: "";
/* 1:1 */
@Ifmr24
Ifmr24 / payment-component.js
Last active August 19, 2020 23:24
payment
window.PaymentComponent = zoid.create({
tag: "payment-component",
url: "http://d2sftg1mzf8i5a.cloudfront.net/payments/form.html",
dimensions: {
width: "800px",
height: "600px",
},
props: {
onClick: {
type: "function",
@Ifmr24
Ifmr24 / formstate.js
Created May 17, 2020 04:23
JS Patron Observador
class FormState {
constructor(){
this.fields = {};
this.subscribers = [];
}
subscribe(callback) {
this.subscribers.push(callback)
}
class Timer {
constructor() {
this.time = 0;
this.interval = -1;
}
start() {
if (this.interval === -1) {
this.interval = setInterval(() => {
this.time++;
@Ifmr24
Ifmr24 / skus.js
Created December 3, 2019 17:04
verificar que existan skus
function verificar() {
const arr1_skus = arr1.rate.items.map(arr => arr.sku);
const skus = ['1', '2', '3', '4', '5'];
let checks = 0;
arr1_skus.map(sku => skus.includes(sku) && (checks = checks + 1));
return checks === arr1_skus.length ? true : false;
}
@Ifmr24
Ifmr24 / cart.js
Created October 29, 2019 20:00
LocalStorage Shopping Cart
const addToCartInLocalStorage = product => {
if (!localStorage.getItem("cart")) {
localStorage.setItem("cart", JSON.stringify([]));
}
let cartProducts = JSON.parse(localStorage.getItem("cart"));
cartProducts.push(product);
localStorage.setItem("cart", JSON.stringify(cartProducts));
};
@Ifmr24
Ifmr24 / ComoUsarReducer.js
Created October 11, 2019 04:11
React context api, reducers, hooks
import React, { useReducer } from "react";
import * as TheReducer from "./Context/context";
function ComoUsarReducer() {
const [state, dispatch] = useReducer(
TheReducer.default,
TheReducer.initialState
);
@Ifmr24
Ifmr24 / GraphQLClientSetup.js
Last active October 9, 2019 17:24
Conectarse a la api graphql de shopify y una query simple
import { ApolloClient } from "apollo-client";
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import { setContext } from "apollo-link-context";
const middlewareLink = setContext(() => ({
headers: {
"X-Shopify-Storefront-Access-Token": "{Token del storefront}"
}
}));