Skip to content

Instantly share code, notes, and snippets.

View example.js
[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
View question about formatting
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
})
}
View gitconfig
[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 Dec 7, 2017
Pipe and Reduce implementation
View PipeandReduce.js
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)
};
View reverse.js
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 Nov 6, 2017
Middleware js Laravel like implementation
View middleware.js
let middlewares = [{
handle(requesst , next)
{
console.log(`Username is: ${request.name}`);
next(request);
}
},
{
handle(request ,next)
{
View memoize
function memoize(func)
{
let cache = {};
return function(x ,y)
{ if(Object.keys(cache).length == 0)
{
cache.res = func(x,y );
cache.x = x;
View promise
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;
View Reduxagain
function todo(state, action)
{
switch(action.type)
{
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
View redux
const createStore = (reducer) =>
{
let state;
let listeners = [];
const getState = () => state;
const dispatch = (action) =>
{
state = reducer(state , action);