Skip to content

Instantly share code, notes, and snippets.

View sx's full-sized avatar

Steve Stedman sx

  • X.Commerce
  • Austin, Texas
View GitHub Profile
@sx
sx / console_log.js
Created February 10, 2012 22:14
Universal JavaScript console log script
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function f() {
log.history = log.history || [];
log.history.push(arguments);
if (this.console) {
var args = arguments,
newarr;
args.callee = args.callee.caller;
newarr = [].slice.call(args);
@sx
sx / .jshintrc
Created December 5, 2012 01:48 — forked from haschek/.jshintrc
JSHint Configuration, Strict Edition
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true
@sx
sx / jquery.ba-queuefn.js
Created September 18, 2012 13:16 — forked from cowboy/jquery.ba-queuefn.js
jQuery queueFn: add a $.fn method or function onto the effects queue
/*!
* jQuery queueFn - v0.5 - 06/18/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
@sx
sx / test-loaded-font.js
Created February 17, 2012 21:44
Test if a font is loaded on a client machine.
function testFont(name) {
name = name.replace(/['"<>]/g,'');
var body = document.body,
test = document.createElement('div'),
installed = false,
template =
'<b style="display:inline !important; width:auto !important; font:normal 10px/1 \'X\',sans-serif !important">ii</b>'+
'<b style="display:inline !important; width:auto !important; font:normal 10px/1 \'X\',monospace !important">ii</b>',
ab;
@sx
sx / userAgent.js
Created November 4, 2011 03:09
UserAgent sniffer
var browsers = [ 'Firefox', 'IEMobile', 'MSIE', 'Android', 'BlackBerry', 'iPhone', 'Chrome', 'Safari', 'Opera Mini', 'Opera' ],
thisBrowser = ( function() {
for ( var i = 0, bl = browsers.length; i < bl; i++ ) {
if ( !!~navigator.userAgent.indexOf( browsers[i] ) ) {
return browsers[i];
}
}
})() || 'Unknown';
@sx
sx / screening.js
Created November 3, 2011 17:45 — forked from rmurphey/screening.js
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
@sx
sx / documentHead.js
Created September 1, 2011 20:20
HTML5 polyfill for document.head
document.head = document.head || document.getElementsByTagName('head')[0];
@sx
sx / addStyle.js
Created August 30, 2011 21:21
add a new stylesheet tag to the head
addStyle = function( css ) {
var styleEl = document.createElement( 'style' );
styleEl.rel = 'stylesheet';
// overwrite the stylesheet if it already exist...
if ( styleEl.styleSheet ) { // IE
styleEl.styleSheet.cssText = css;
} else { // !IE
styleEl.appendChild( document.createTextNode( css ) );
}
// attach the stylesheet to the page