Skip to content

Instantly share code, notes, and snippets.

/** make_flat(Array)
* Simple method for flattening a multidimensional array
* @example make_flat([[1,2,[3]],4]) == [1, 2, 3, 4]
**/
function make_flat(arr) {
// simply make use of `reduce` method to to reduce each element to a single val
return arr.reduce(function(a, b) {
// if val is array, rerun thru, else, move on
return a.concat( Array.isArray(b) ? make_flat(b) : b );
},
;(function() {
/**
* AssociativeArray( { key: value } )
* AssociativeArray( key, value )
* AssociativeArray( [keys], [value] )
**/
function AssociativeArray() {
var args = Array.prototype.slice.call(arguments),
arr = [];
switch (true) {
/** isEmpty(varried)
* Simple method for testing if item is "empty"
**/
;(function() {
/**
* !a Basic empty check. Takes care of 90% of items passed through.
* 0 >= a Catchs '0' strings and empty Arrays
*
* /\{\}/.test(JSON.stringify(a).replace(/"[^"]*":(0|"0*"|false|null|\{\}|\[(null(,)?)*\]),?/g, '').replace(/"[^"]*":\{\},?/g, '')) // to determine Blank Object
* /|\[(null(,)*)*\]/.test(JSON.stringify(a).replace(/(0|"0*"|false|null|\{\}|\[(null(,)?)*\]),?/g, '')) // to determine Blank Array
;(function() {
function createOpenLink(href, oType) {
var objStyle = {
'padding': '1em',
'text-align': 'center'
},
strStyle = $.map(objStyle, function(v, k) { return k + ': ' + v; }).join('; ') + ';',
attrs = { 'href': href, 'style': strStyle, 'target': '_blank', 'text': 'Open ' + oType },
lnkOpen = $('<a />', attrs);
return lnkOpen;
;(function() {
if (/(\/$)|\/(hot|trending)/.test(location.href)) {
var art = $('article:first').clone(),
/* REPLACEMENTS MADE BELOW */
title = "YOU'RE AWESOME!", // replace between "" with what you want it to say
picLink = 'http://some.picture.com/pic.png', // replace this with a link to a pic you want on hots
profileLink = 'http://9gag.com/u/your_username'; // replace this with link to your profile
/* REPLACEMENTS MADE ABOVE */
img = $('<img />', { 'alt': "Your pic link is incorrect.", 'src': picLink }).addClass('badge-item-img');
art.find('.badge-item-title a').text(title);
@JDMcKinstry
JDMcKinstry / arrStateAreaSizes.js
Created September 6, 2016 14:43
Array of States Sizes in Mi and Km. Index is rank size with Alaska being 1 & RI at 50. DC set to 0, as it's not a state, and helps complete the array 0-50.
[
{
"District of Columbia": {
"sqmi":6825,
"sqkm":17675
}
},
{
"Alaska": {
"sqmi":663267,
@JDMcKinstry
JDMcKinstry / jQuery.outerHTML.js
Last active July 2, 2016 22:39
Simply adds outerHTML method to jQuery
;(function($) {
$.extend({
outerHTML: function() {
var $ele = arguments[0],
args = Array.prototype.slice.call(arguments, 1)
if ($ele && !($ele instanceof jQuery) && (typeof $ele == 'string' || $ele instanceof HTMLCollection || $ele instanceof Array)) $ele = $($ele);
if ($ele && $ele.length) {
if ($ele.length == 1) return $ele[0].outerHTML;
else return $.map($("div"), function(ele,i) { return ele.outerHTML; });
}
@JDMcKinstry
JDMcKinstry / instagram.desktop.links.js
Created June 22, 2016 21:59
Makes it easy to open Instagram images and videos in separate links when using IG on Desktop
var cjsSelector = '';
;(function() {
var iDoIt = 1;
function doIt() {
/* ↓↓↓ DO WORK IN HERE ↓↓↓ */
jQuery(cjsSelector).remove();
/* ↑↑↑ DO WORK IN HERE ↑↑↑ */
iDoIt = iDoIt < 10 ? iDoIt + 1 : 1;
setTimeout(doIt, iDoIt * 1000);
}
;(function() {
var hrefUI = { open: "https://ajax.googleapis.com/ajax/libs/jqueryui/", close: "/themes/smoothness/jquery-ui.css" },
srcJQ = { open: "https://ajax.googleapis.com/ajax/libs/jquery/", close: "/jquery.min.js" },
srcUI = { open: "https://ajax.googleapis.com/ajax/libs/jqueryui/", close: "/jquery-ui.min.js" },
jQVers = ["2.2.4","2.2.3","2.2.2","2.2.1","2.2.0","2.1.4","2.1.3","2.1.1","2.1.0","2.0.3","2.0.2","2.0.1","2.0.0","1.12.4","1.12.3","1.12.2","1.12.1","1.12.0","1.11.3","1.11.2","1.11.1","1.11.0","1.10.2","1.10.1","1.10.0","1.9.1","1.9.0","1.8.3","1.8.2","1.8.1","1.8.0","1.7.2","1.7.1","1.7.0","1.6.4","1.6.3","1.6.2","1.6.1","1.6.0","1.5.2","1.5.1","1.5.0","1.4.4","1.4.3","1.4.2","1.4.1","1.4.0","1.3.2","1.3.1","1.3.0","1.2.6","1.2.3"],
jQUIVers = ["1.11.4","1.11.3","1.11.2","1.11.1","1.11.0","1.10.4","1.10.3","1.10.2","1.10.1","1.10.0","1.9.2","1.9.1","1.9.0","1.8.24","1.8.23","1.8.22","1.8.21","1.8.20","1.8.19","1.8.18","1.8.17","1.8.16","1.8.15","1.8.14","1.8.13","1.8.12","1.8.11","1