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 / promise-1.js
Last active August 29, 2015 14:26
proimse-blog
var p = Promise.resolve().then(function() {
console.log('Promise resolve callback'); // Prints Promise resolve callback
}, function() {
console.log('Promise reject callback');
});
@kavitshah8
kavitshah8 / git-amend-1.sh
Last active February 4, 2016 06:41
Git amend use cases
git add .
git commit -m “adding few files”
git log --oneline
touch forgot.js // adds new file to the project
git add . // adds recently added file to the stagging
git commit --amend --no-edit // adds new file to the previous commit without changing the commit message
git log --oneline
@kavitshah8
kavitshah8 / open-1.js
Last active December 16, 2016 20:52
webrtc automated testing
browser
.execute(function (url1, window1) {
window.open(url1, window1, "height=1024,width=768");
}, [URL1, WINDOW1]);
@kavitshah8
kavitshah8 / forEach.js
Last active September 11, 2015 06:27
Most useful Array methods
var arr = ['javascript','css','html'];
function printSkill(element, index) {
console.log(element + ' is the ' + index + ' element in the array');
}
arr.forEach(printSkill);
@kavitshah8
kavitshah8 / localStorage.js
Last active September 8, 2015 04:40
getters and setters for local storage
// setter
localStorage.setItem("employeeName", "Ryan");
localStorage.setItem("employeeId", 121456789);
// getter
var name = localStorage.getItem("employeeName"); // Ryan
var id = localStorage.getItem("employeeId"); // 121456789
@kavitshah8
kavitshah8 / squash-commits.sh
Last active September 10, 2015 01:33
Squash Multiple Commits into One
git commit --soft <Last commit where HEAD should point>
git commit -m 'Many squashed commits'
git push --force origin master
'use strict';
function braces(values) {
var i;
var result = [];
var len = values.length;
for (i = 0; i < len; i++) {
if (isBalanced(values[i])) {
result.push('YES');
@kavitshah8
kavitshah8 / deep-copy.js
Last active October 12, 2015 15:06
Object
function deepCopy(oldObject) {
var temp = JSON.stringify(oldObject);
var newObject = JSON.parse(temp);
return newObject;
}
var employee1 = {
'name': 'Tony',
'age': 27,
@kavitshah8
kavitshah8 / 2-D-array-fix-2.js
Last active March 17, 2020 10:57
Arrays with one Misc
function createAndInitialize2DArray(size) {
// catch a bug & fix me!
var defaultValue = 0;
var twoDimensionalArray = [];
function initOneDArray() {
var row = [];
for (var i = 0; i < size; i++) {
row.push(defaultValue);
}
var cachedNumbers = {};
function calculateFibonacciSum (num) {
if(cachedNumbers[num]) {
return cachedNumbers[num];
}
if(('number' === typeof num) && num <= 0) {
throw new Error ('Fibonnci series starts with 0. Please, enter any interget greater than or equal to 0');
}
else if(('number' === typeof num) && num === 0) {