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 deDupeArrByPropReduceSort(objectArray, prop) { | |
//copy the parameter array as we don't want to mutate that object | |
const sorted = Object.assign([], objectArray); | |
// Now we sort the new array by the prop value | |
sorted.sort(function(a, b){ | |
if (a[prop] > b[prop]) { | |
return -1; | |
} else { | |
return 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
// Prop is the prop you want to check in the array for a unique value | |
// objectArray is the original array of objects | |
function deDupeArrByPropReduce(objectArray, prop) { | |
return objectArray.reduce(function (acc, obj, ind, arr) { | |
// acc is the accumulator. On line 14 we pass an emtpy array as the inital value | |
if (acc.findIndex(obj1 => { | |
// We check if the accumulator has an object with the same value as the iterated obj. | |
return obj1[prop] === obj[prop]; | |
}) == -1) { | |
// if the findIndex function returns -1 we add the object to the accumulator |
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
const people = [ | |
{ name: 'Alice', age: 21 }, | |
{ name: 'Max', age: 20 }, | |
{ name: 'Jane', age: 20 }, | |
{ name: 'Jesse', age: 22 }, | |
{ name: 'Mike', age: 24 }, | |
{ name: 'Jen', age: 21 }, | |
{ name: 'Jesse', age: 22 }, | |
{ name: 'Jen', age: 21 }, | |
{ name: 'Mike', age: 25 }, |
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
// should support most browsers with a fallback for no gradient support | |
@mixin gradient($from, $to) { | |
background: $from; /* Old browsers */ | |
background: -moz-linear-gradient(top, $from 0%, $to 100%); /* FF3.6+ */ | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,$from), color-stop(100%,$to)); /* Chrome,Safari4+ */ | |
background: -webkit-linear-gradient(top, $from 0%,$to 100%); /* Chrome10+,Safari5.1+ */ | |
background: -o-linear-gradient(top, $from 0%,$to 100%); /* Opera 11.10+ */ | |
background: -ms-linear-gradient(top, $from 0%,$to 100%); /* IE10+ */ | |
background: linear-gradient(to bottom, $from 0%,$to 100%); /* W3C */ |
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
// After some debugging, got this working. Didn't see it documented anywhere so thought I would put this up to help any others | |
// First install the grunt-postcss and autoprefixer-core npm repositiories | |
// Looks like this: npm install grunt-postcss autoprefixer-core | |
var autoprefixer = require('autoprefixer-core'); | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), |
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
// lastUpdate param should be a date object or a number representing milliseconds since 1970 | |
// interval param should be seconds | |
// Interval is the elapsed time you are checking | |
// Returns true if the interval time has elapsed | |
// Returns false if the interval has not elapsed | |
function update(lastUpdate, interval) { | |
var curTime = new Date().getTime(); | |
lastUpdate = (typeof lastUpdate.getTime == "function")? lastUpdate.getTime(): lastUpdate; | |
interval *= 1000; |
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
// Often you want to dump a large amount of models into a collection at one time. | |
// This take models from one collection and adds thems to another | |
// This assumes you have two collections already initialized with models. | |
// If you had one collection that had change events wired to render a view you might use this. | |
collectionAttachedToView.add(collectionToAdd.models); | |
//This would work, however, it will fire an add event everytime one of the models is added. | |
// This will slow your app down ad it will try to render over and over again as many times as the models you are adding | |
// To avoid this, use the silent option |
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
// One Digit returns string | |
function pad (n) { | |
return ("0" + n.toString()).slice(-2); | |
} | |
//Two digit returns string | |
function pad (n) { | |
return ("00" + n.toString()).slice(-3); | |
} |