This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************** | |
ExportSVGLayers.jsx | |
DESCRIPTION | |
For Adobe Illustrator. | |
This script takes your active document and export one | |
SVG per layer. | |
Best used for exporting many layers with the same artboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Promise.all is good for executing many promises at once | |
Promise.all([ | |
promise1, | |
promise2 | |
]); | |
// Promise.resolve is good for wrapping synchronous code | |
Promise.resolve().then(function () { | |
if (somethingIsNotRight()) { | |
throw new Error("I will be rejected asynchronously!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//if statement | |
(if ( foo ) { | |
bar = "beta"; | |
} | |
// and... | |
if ( foo ) { | |
bar(); | |
}) | |
//alternative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shuffle(array) { | |
var m = array.length, t, i; | |
// While there remain elements to shuffle… | |
while (m) { | |
// Pick a remaining element… | |
i = Math.floor(Math.random() * m--); | |
// And swap it with the current element. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ajax = { | |
load : function() { | |
var xhr; | |
if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest(); | |
else { | |
var versions = ["MSXML2.XmlHttp.5.0", | |
"MSXML2.XmlHttp.4.0", | |
"MSXML2.XmlHttp.3.0", | |
"MSXML2.XmlHttp.2.0", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//my solution using REGEX | |
function toCurrency(price){ | |
return price.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); | |
} | |
//good example | |
function toCurrency(price){ | |
return price.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//my example | |
function descendingOrder(n){ | |
var digits = (""+n).split("").sort(function(a, b){return b-a}); | |
digits = digits.join(""); | |
return Number(digits); | |
} | |
//good examples | |
//1 | |
function descendingOrder(n){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//my solution | |
var paginationText = function(pageNumber, pageSize, totalProducts){ | |
var numOfPages = Math.ceil(totalProducts/pageSize); | |
var initItem = pageNumber*pageSize-(pageSize-1); | |
var endItem; | |
if (pageNumber === numOfPages){ | |
endItem = totalProducts; | |
}else{ | |
endItem = pageSize*pageNumber; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//my solution | |
function f(n){ | |
return n > 0 && n % 1 === 0 ? ((1+n)*n)/2 : false; | |
}; | |
//good examples | |
//1 | |
function f(n){ | |
return (parseInt(n) === n && n > 0) ? n*(n+1)/2 : false; | |
}; |
NewerOlder