Skip to content

Instantly share code, notes, and snippets.

Nathan Bubna nbubna

Block or report user

Report or block nbubna

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
View css-layout-hack.js
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var elements = document.body.getElementsByTagName('*');
var items = [];
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) {
items.push(elements[i]);
}
}
@nbubna
nbubna / error.js
Last active Sep 10, 2015
A convenient global error handler
View error.js
(function(scope, console, CustomEvent) {
var error = scope.error = function() {
var output = []
for (var i=0; i<arguments.length; i++) {
var arg = arguments[i];
if (typeof arg === "object" && arg.length) {
output.push.apply(output, Array.prototype.slice.call(arg));
} else {
output.push(arg);
@nbubna
nbubna / domx-core-idea.js
Created Dec 22, 2014
On demand, duplicate prototype chain for creating performant, polymorphic, type-aware extensions on per-instance DOM wrapper objects. (rough draft)
View domx-core-idea.js
window.X = {};
function fnName(fn){
if (!fn){ return null; }
if (fn.name){ return fn.name; }
var s = fn.toString().match(/ \w+/);
return s && s[0].substring(1);
}
function xType(name, type) {
if (name in X) {
return X[name];
@nbubna
nbubna / textarea.autosize.js
Last active Jan 20, 2016
Vanilla JS textarea auto-size
View textarea.autosize.js
(function(document) {
var flex = {
tagName: 'TEXTAREA',
attribute: 'autosize',
buffer: 20,
events: 'input propertychange change',
adjust: function(el, shrunk) {
var height = el.scrollHeight,
style = el.style;
@nbubna
nbubna / resolve.js
Last active Dec 24, 2015
Safely resolve string-form variable references.
View resolve.js
(function(scope) {
var resolve = scope.resolve = function(reference, context) {
if (resolve.RE.test(reference)) {
return resolve.unsafe(reference, context);
}
};
resolve.RE = /^([\w\$]+)?((\.[\w\$]+)|\[(\d+|'(\\'|[^'])+'|"(\\"|[^"])+")\])*$/;
resolve.unsafe = function(reference, context) {
@nbubna
nbubna / gist:6250091
Created Aug 16, 2013
Reliably fire 'click' event with HTML.js
View gist:6250091
// this gives HTMLified nodes 'click' if not defined already
HTML._.fn.click = function() {
var e = document.createEvent('MouseEvent');
e.initMouseEvent('click', true, true);
el.dispatchEvent(e);
};
// call it like so:
HTML.find('.foo').each('click');
@nbubna
nbubna / define.js
Last active Dec 20, 2015
A paranoid function for defining properties on an object such that they will never override existing ones, never error, never interrupt the current thread, and never allow subsequent definitions of the property. (requires ES5)
View define.js
function define(object, key, fn, force) {
if (force || !(key in object)) {// unless we're forcing the issue, avoid already defined keys
(setImmediate || setTimeout)(function() {// do it asynchronously to not interrupt other initialization
try {// suppress errors when the property isn't configurable
Object.defineProperty(object, key, { value: fn });// define the new one to be non-enumerable and non-configurable
} catch (e) {}
}, 0);
}
};
// if you really want to get fancy, you could use promises or callbacks to resume init after this is defined.
@nbubna
nbubna / diff.js
Last active Dec 17, 2015
Simple object diffing, outputs to console log
View diff.js
function diff(a, b) {
for (var k in a) {
if (!(k in b)) {
console.log('b is missing '+k, a[k]);
} else if (a[k] != b[k]) {
var av = a[k], bv = b[k];
try {
if (JSON.stringify(av) != JSON.stringify(bv)) {
console.log('different '+k, av, bv);
}
@nbubna
nbubna / state.js
Created Jul 11, 2012
state.js - browser history and bookmarks for ajax apps
View state.js
/**
* Copyright (c) 2012, ESHA Research
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* @version 0.4
* @requires jQuery
* @name state
* @author Nathan Bubna
View key.js
/**
* Copyright (c) 2012, ESHA Research
*
* @version 0.1
* @name key
* @requires jQuery
* @author Nathan Bubna
*/
;(function($, window, document) {
You can’t perform that action at this time.