Skip to content

Instantly share code, notes, and snippets.

View gdibble's full-sized avatar
🤩
Optimistic

Gabriel Dibble gdibble

🤩
Optimistic
View GitHub Profile
/*
* 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)) {
@gdibble
gdibble / bootstrap-popover-keeponhover.js
Last active August 29, 2015 14:19
bootstrap popovers stay on hover
/*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');
@gdibble
gdibble / startup-image-loader.js
Created April 20, 2015 20:50
iOS Launch Image Loader - meta tags load every image (many large files slow app load/render); this loads only appropriate image
/*
* 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 / random-number.js
Last active August 29, 2015 14:19
random number generator - lower/upper range, as integer or not
/*
* 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 / reIndexOf.js
Last active May 20, 2016 22:04
Regular Expresion indexOf for Arrays
/**
* 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) {
/* 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 / grab.styl
Last active May 12, 2017 22:47 — forked from BenKalsky/grab.scss
Grabbing Cursor SCSS Mixin
.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
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 / intersectionObj.js
Created May 12, 2017 22:41
Lodash mixin to find similar property values in an array of objects
/**
* 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 } ]
@gdibble
gdibble / findDateRanges.js
Created October 4, 2019 22:30
findDateRanges: Find and group date-ranges in an Array of dates
/**
* @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([