Skip to content

Instantly share code, notes, and snippets.

@web2ls
Last active February 21, 2018 07:35
Show Gist options
  • Select an option

  • Save web2ls/9f5441140a91abb85060705acf79fbb2 to your computer and use it in GitHub Desktop.

Select an option

Save web2ls/9f5441140a91abb85060705acf79fbb2 to your computer and use it in GitHub Desktop.
Usefull notes
//Save previously received compute result in function(for increase perfomance)
function isPrime(value) {
if (!isPrime.answers) {
isPrime.answers = {};
}
if (isPrime.asnwers[value] !== undefined) {
return isPrime.answers[value];
}
var prime = value !== 0 && value !== 1;
for (var i = 2; i < value; i++) {
if (value % i === 0) {
prime = false;
break;
}
}
return isPrime.answers[value] = prime;
}
//Store function in cache object only if it is unique function
var store = {
nextId: 1,
cache: {},
add: function(fn) {
if (!fn.id) {
fn.id = nexId++;
this.cache[fn.id] = fn;
return true;
}
}
}
//Set n-digits after comma for float number without rounding
(f - 0.005).toFixed(n)
1) Get all keys in object and works with them
const keys = Objects.keys(myObject);
keys.forEach(function(key) {
console.log(`${key}: ${myObject[key}`)
});
2) Convert value to another notation
const a = 'ff'; //value in hexidecimal
const b = parseInt(a, 10); //convert it into decimal
3) Deploy dist folder from master branch to github pages
-Remove dist folder from local .gitignore file
-git add dist && git commit -m "Add dist subtree"
-git subtree push --prefix dist origin gh-pages
Also need check base tag in index.html file in dist folder. By default it has value = '/', but for correct work it must be equal '/repository_name/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment