Skip to content

Instantly share code, notes, and snippets.

[cartActions.INCREMENT_CART_ITEM_QTY]({ commit, state }, cartItemId) {
let clonedCartItems = {...state.cartItems}
clonedCartItems[cartItemId].qty++
let actualCartItems = []
for (let key in clonedCartItems) {
let currentCartItem = clonedCartItems[key]
actualCartItems.push({
id: currentCartItem.id,
product_id: currentCartItem.product_id,
qty: currentCartItem.qty
static registerCallBack(personName, personPhone) {
return axios.post(`${BASE_URL}/api/client/v2/callback_messages`, {
name: personName,
phone: personPhone
}).then(resp => resp.data)
.catch(err => {
throw err
})
}
[alias]
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
[core]
editor = vim
@anotherxx
anotherxx / PipeandReduce.js
Created December 7, 2017 17:29
Pipe and Reduce implementation
let statement = "wELCOME | lower | capitalize";
let another = "welcome | upper";
let handlers = {
lower : (val) => val.toLowerCase(),
upper: (val) => val.toUpperCase(),
capitalize: (val) => val.slice(0,1).toUpperCase() + val.slice(1)
};
let arr1 = [1,2,3,4,5];
let arr2 = [1,2,3,4,5,6,7,8,9,10];
function reverse(arr)
{
var len = arr.length;
var middle = Math.floor(len / 2);
var start = 0;
var end = len - 1;
@anotherxx
anotherxx / middleware.js
Last active November 6, 2017 23:08
Middleware js Laravel like implementation
let middlewares = [{
handle(requesst , next)
{
console.log(`Username is: ${request.name}`);
next(request);
}
},
{
handle(request ,next)
{
function memoize(func)
{
let cache = {};
return function(x ,y)
{ if(Object.keys(cache).length == 0)
{
cache.res = func(x,y );
cache.x = x;
httpGetUser('http://localhost:3000/users')
.then(response =>
{
console.log('First resolve callback');
console.log('~~~~~~~~~~');
var user = JSON.parse(response);
user = user.find((user) => user.name == 'Nerhbest');
return user.name;
function todo(state, action)
{
switch(action.type)
{
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
const createStore = (reducer) =>
{
let state;
let listeners = [];
const getState = () => state;
const dispatch = (action) =>
{
state = reducer(state , action);