Skip to content

Instantly share code, notes, and snippets.

View kavitshah8's full-sized avatar

Kavit Shah kavitshah8

  • Adobe
  • Bay Area, CA
View GitHub Profile
@kavitshah8
kavitshah8 / map.js
Last active March 18, 2017 20:09
Closures
'use strict';
function mul(x) {
return x * x;
}
function mulWVariance(variance, x) {
return x * x + variance;
}
@kavitshah8
kavitshah8 / chain-1.js
Last active May 24, 2018 05:59
Functional Programming in Javascript
'use strict';
function chain() {
var newReleases = [{
"id": 70111470,
"title": "Die Hard",
"rating": 4.0
}, {
"id": 654356453,
"title": "Bad Boys",
@kavitshah8
kavitshah8 / arrow.js
Created February 22, 2016 18:40
arrow functions
function ViewSomething() {
this.a = 42
this.click = function() => {
alert(this.a) // undefined
}
this.click1 = () => {
alert(this.a) // 42
@kavitshah8
kavitshah8 / uuid.js
Created February 28, 2016 07:58
Node
// npm i node-uuid
var uuid = require('node-uuid');
// Generate a v1 (time-based) id
uuid.v1();
// Generate a v4 (random) id
uuid.v4();
// Mutated Version
const combineReducers = reducers => {
return (state = {}, action) => {
return Object.keys(reducers).reduce((nextState, key) => {
nextState[key] = reducers[key](state[key], action)
return nextState
}, {})
}
};
var parts = ['shoulders', 'knees'];
var parts2 = ['head', 'and', 'toes'];
// ES 5
var lyrics = parts2.slice(0, 1).concat(parts).concat(parts2.slice(1, 3));
console.log(lyrics); // ["head", "shoulders", "knees", "and", "toes"]
// ES 6
var lyrics = [parts2[0], ...parts, parts2[1], parts2[2]];
console.log(lyrics); // ["head", "shoulders", "knees", "and", "toes"]
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
this.lastName = ko.observable("Bertington");
this.capitalizeLastName = function() {
var currentVal = this.lastName(); // Read the current value
this.lastName(currentVal.toUpperCase()); // Write back a modified value
};
}
// Activates knockout.js
@kavitshah8
kavitshah8 / curry-3.js
Last active July 20, 2016 15:10
Currying
function realSum(a, b) {
return a + b;
};
console.log(realSum(5, 3)); // 8
var sum5 = curryIt(realSum, 5);
console.log(sum5(4)); // 9
@kavitshah8
kavitshah8 / timeConvertor.js
Last active October 26, 2016 04:18
Hacker
function timeConvertor(time) {
var PM = time.match('PM') ? true : false
time = time.split(':')
var min = time[1]
if (PM) {
var hour = 12 + parseInt(time[0],10)
var sec = time[2].replace('PM', '')
@kavitshah8
kavitshah8 / mutiple-entry-points.js
Last active October 28, 2018 17:02
Webpack Configs
var config = {
entry: {
app: addEntryPoint('./src/Router.jsx'),
vendor: ['lodash', 'react', 'react-router', 'react-dom', 'rc-slider']
},
output: {
path: options.devServer ? path.join( __dirname, 'public', 'js') : 'public',
filename: '[name]-[chunkhash].js',
publicPath: '',