Skip to content

Instantly share code, notes, and snippets.

💭
Optimistic

Gabriel Dibble gdibble

💭
Optimistic
Block or report user

Report or block gdibble

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gdibble
gdibble / findDateRanges.js
Created Oct 4, 2019
findDateRanges: Find and group date-ranges in an Array of dates
View findDateRanges.js
/**
* @function findDateRanges
* @description Find and group date-ranges in an Array of dates
*
* @param {Array} sourceCollection - containing ISODateStrings in any order
* @param {?Array} destinationCollection - defaults to []
*
* @returns {Array} - ^destinationCollection passed or new Array
*
* @example findDateRanges([
@gdibble
gdibble / intersectionObj.js
Created May 12, 2017
Lodash mixin to find similar property values in an array of objects
View intersectionObj.js
/**
* intersectionObj
* Pass an array of objects to find the similar objects
* You may also pass a single prop as a string, or an array of props to ignore
* Returns an array of the items which intersected
*
* Usage example:
* var arr = [ { id:1, b:2, c:3 }, { id:2, b:3, c:4 }, { id:3, b:2, c:3 } ];
* _.intersectionObj(arr, 'id');
* » [ { id:1, b:2, c:3 }, { id:3, b:2, c:3 } ]
View clone.js
function clone(thing, opts) {
var newObject = {};
if (thing instanceof Array) {
return thing.map(function (i) { return clone(i, opts); });
} else if (thing instanceof Date) {
return new Date(thing);
} else if (thing instanceof RegExp) {
return new RegExp(thing);
} else if (thing instanceof Function) {
return opts && opts.newFns ? new Function('return ' + thing.toString())() : thing;
@gdibble
gdibble / grab.styl
Last active May 12, 2017 — forked from BenKalsky/grab.scss
Grabbing Cursor SCSS Mixin
View grab.styl
.grab-cursor
cursor: url('http://www.google.com/intl/en_ALL/mapfiles/openhand.cur'), all-scroll
cursor: url('data:image/vnd.microsoft.icon;base64,AAACAAEAICACAAcABQAwAQAAFgAAACgAAAAgAAAAQAAAAAEAAQAAAAAAAAEAAAAAAAAAAAAAAgAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD8AAAA/AAAAfwAAAP+AAAH/gAAB/8AAA//AAAd/wAAGf+AAAH9gAADbYAAA2yAAAZsAAAGbAAAAGAAAAAAAAA//////////////////////////////////////////////////////////////////////////////////////gH///4B///8Af//+AD///AA///wAH//4AB//8AAf//AAD//5AA///gAP//4AD//8AF///AB///5A////5///8='), all-scroll
cursor: -webkit-grab
cursor: -moz-grab
cursor: -o-grab
cursor: -ms-grab
cursor: grab
.grabbing-cursor
View detection.js
/* Detection: http://gist.github.com/df3fd4016e632344336f3227a6f159e6
* While userAgent sniffing is not ideal, arguably it is best in most cases
* throw in some proper feature detection & this will give you vast UI/UX control
*/
var userAgent = navigator.userAgent || navigator.vendor || window.opera || navigator.platform;
this.isMobile = (function (browserUserAgent) { return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(browserUserAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|n
@gdibble
gdibble / reIndexOf.js
Last active May 20, 2016
Regular Expresion indexOf for Arrays
View reIndexOf.js
/**
* Regular Expresion IndexOf for Arrays
* This little addition to the Array prototype will iterate over array
* and return the index of the first element which matches the provided
* regular expresion. Note: This will not match on objects.
* @param {RegEx} rx The regular expression to test with. E.g. /-ba/gim
* @return {Numeric} -1 means not found
*/
if (typeof Array.prototype.reIndexOf === 'undefined') {
Array.prototype.reIndexOf = function (str) {
@gdibble
gdibble / random-number.js
Last active Aug 29, 2015
random number generator - lower/upper range, as integer or not
View random-number.js
/*
* return random number within lower/upper range
* output a whole number by passing returnInteger=1
* Examples: $R(0, 10); >>> 3.141592653589793
* $R(0, 10, 1); >>> 7
*/
function $R(lowerLimit, upperLimit, returnInteger) {
var step1 = Math.random() * (upperLimit - lowerLimit);
if (returnInteger && (returnInteger === 1)) {
return lowerLimit + parseInt(step1, 10);
@gdibble
gdibble / startup-image-loader.js
Created Apr 20, 2015
iOS Launch Image Loader - meta tags load every image (many large files slow app load/render); this loads only appropriate image
View startup-image-loader.js
/*
* iOS Launch Image Loader v1.1.1 @ GDibble
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Browser downloads all meta-tagged images, thus only append 1 meta tag to
* save download time and provide the fastest loading mobile experience.
*
* Files must live in '/img/ios/' and named:
* startup-2048x1496.png Landscape Retina iPads
* startup-1536x2008.png Portrait Retina iPads
* startup-1024x748.png Landscape iPad 1 & 2
@gdibble
gdibble / bootstrap-popover-keeponhover.js
Last active Aug 29, 2015
bootstrap popovers stay on hover
View bootstrap-popover-keeponhover.js
/*global $*/
/*
* bootstrap popovers stay on hover [4/11/2014 @gdibble]
*/
var originalLeave = $.fn.popover.Constructor.prototype.leave;
$.fn.popover.Constructor.prototype.leave = function (obj) {
var self, container;
if (obj.currentTarget) {
self = obj instanceof this.constructor ? obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type);
container = $(obj.currentTarget).siblings('.popover');
View flatten-object.js
/*
* Flatten Object @gdibble: Inspired by https://gist.github.com/penguinboy/762197
* input: { 'a':{ 'b':{ 'b2':2 }, 'c':{ 'c2':2, 'c3':3 } } }
* output: { 'a.b.b2':2, 'a.c.c2':2, 'a.c.c3':3 }
*/
var flattenObject = function(ob) {
var toReturn = {};
var flatObject;
for (var i in ob) {
if (!ob.hasOwnProperty(i)) {
You can’t perform that action at this time.