Skip to content

Instantly share code, notes, and snippets.

View MarcusHurney's full-sized avatar

Marcus Hurney MarcusHurney

View GitHub Profile
function log(firstName, ...rest) {
console.log(firstName);
console.log(rest);
}
log('Marcus', 'Cheese', 'Fruit', 'Blowski', 'Wine');
// Marcus
@MarcusHurney
MarcusHurney / self.js
Created February 9, 2017 03:41
how to use self
var person = {
name: 'Marcus',
sayName: function() {
var self = this;
function changeName() {
self.name = 'Anonymous';
console.log(self.name);
}
@MarcusHurney
MarcusHurney / usingLet.js
Created February 3, 2017 16:48
Allows you to store a local variable in a for loop
function usingLet() {
//i is *not* visible out here
var myArray = [];
for( let i = 0; i < 5; i++ ) {
myArray.push(
function() {
console.log(i);
}
);
}
@MarcusHurney
MarcusHurney / functionFactory.js
Created February 2, 2017 07:21
Makes use of closures to create a function factory
function makeGreeting(language) {
if (language === 'en') {
return function(name, lastname) {
console.log('Hello ' + name + ' ' + lastname);
}
}
if(language === 'es') {
function isPrime(number) {
// If your browser doesn't support the method Number.isInteger of ECMAScript 6,
// you can implement your own pretty easily
if (typeof number !== 'number' || !Number.isInteger(number)) {
// Alternatively you can throw an error.
return false;
}
if (number < 2) {
return false;
function buildFunction() {
var arr = [];
for (var i = 0; i < 3; i++) {
arr.push(
(function(j) {
return function() {
console.log(j);
}
var myArray = [1,3,2,2,10,9,9,8,7,13,6,4];
var mysteryFunction = function(array) {
var hashHadChange;
for (var i = 0; i < array.length - 1; i++) {
hashHadChange = false;
for (var x = 0; x < array.length - 1; x++) {
if (array[x] > array[x+1]) {
var temp = array[x];
array[x] = array[x+1];
async.each(myContacts, function(contact, messageToSend, callback) {
const message = {
from: "+18442849820",
to: `+1${contact.number}`,
text: messageToSend,
callbackUrl: 'https://happie-match.herokuapp.com/messageCallback'
};
// the paramter called candidatesArray is an array of objects that look about like this:
// var candidate = { name: 'Marcus Hurney', phone: '7064834776', email: '[email protected], etc: etc };
// candidatesArray usually contains thousands of objects
const sendJobs = (candidatesArray, typeOfReq) => {
return new Promise((resolve, reject) => {
// array for tracking which jobs have been sent via sms
const sendBandWidthSMS = (number, messageToSend) => {
const message = {
from: "+18442849820", // <-- This must be a Bandwidth number on your account
to: `+1${number}`,
text: messageToSend,
callbackUrl: 'https://happie-match.herokuapp.com/messageCallback'
};
client.Message.send(message)
.then(function(message) {