Skip to content

Instantly share code, notes, and snippets.

View ryanhamley's full-sized avatar

Ryan Hamley ryanhamley

View GitHub Profile
@ryanhamley
ryanhamley / getDigitAt.js
Last active August 29, 2015 14:18
Number prototype method to return a digit at a specified position or a slice between two specified positions
/**
* [getDigitAt method for numbers that will return either the digit at a specified position or the section of the number between two positions]
* @param {[number]} position1 [either the position to search for or the starting position of the slice]
* @param {[number]} position2 [*optional*, if supplied, this creates a slice and acts as the end position]
* @return {[number]} [either the digit at the specified position or the slice between the specified positions]
*/
Number.prototype.getDigitAt = function (position1, position2) {
//convert the number to a string to allow array-like access
var num = this.valueOf().toString();
@ryanhamley
ryanhamley / checkForDuplicateObjects.js
Created April 9, 2015 16:59
Recursive function for Angular.js to determine if an array of objects contains duplicates
/**
* [checkForDuplicateObjects recursively checks an array of objects for duplicate values using angular.equals() to deeply compare objects.]
* @param {[array]} _array [the array of objects to be checked]
* @return {[boolean]} true or falsey [the function will return true if duplicates are found]
*/
function checkForDuplicateObjects(_array) {
if (_array.length > 1) {
var first = _array[0];
for (var i = 1; i < _array.length; i++) {
@ryanhamley
ryanhamley / customResourceAction.js
Created April 8, 2015 15:40
An example of adding custom functionality to an Angular $resource in order to create an action which accepts variables and a callback.
Event.getDateRange = function (start, end, cb){
var params = {
q: {
filters: [
{
name: 'occurrences',
op: 'any',
val: {
'name': 'date',
'op': 'gte',