Skip to content

Instantly share code, notes, and snippets.

View rafaelmaeuer's full-sized avatar

Rafael M. rafaelmaeuer

View GitHub Profile
@rafaelmaeuer
rafaelmaeuer / 0_reuse_code.js
Created December 11, 2016 19:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
Object.keys(myArray).length
var indexOfStevie = myArray.findIndex(i => i.hello === "stevie");
PersonModel.find({ favouriteFoods: { "$in" : ["sushi"]} }, ...);
@rafaelmaeuer
rafaelmaeuer / array-map.js
Last active October 9, 2017 13:14
From an array of objects, extract value of a property as array (JavaScript) - From https://stackoverflow.com/questions/19590865/from-an-array-of-objects-extract-value-of-a-property-as-array
var result = objArray.map(function(a) {return a.foo;});
(function myLoop (i) {
setTimeout(function () {
alert('hello'); // your code here
if (--i) myLoop(i); // decrement i and call myLoop again if i > 0
}, 3000)
})(10); // pass the number of iterations as an argument
var myfunc = PTest();
myfunc.then(function () {
console.log("Promise Resolved");
}).catch(function () {
console.log("Promise Rejected");
});
var random_boolean = Math.random() >= 0.5;
var translator = new T2W("EN_US");
// one thousand two hundred thirty-four
translator.toWords(1234)