Skip to content

Instantly share code, notes, and snippets.

Avatar

Steve Stedman sx

  • X.Commerce
  • Austin, Texas
View GitHub Profile
@sx
sx / .jshintrc
Created Dec 5, 2012 — forked from haschek/.jshintrc
JSHint Configuration, Strict Edition
View .jshintrc
{
// --------------------------------------------------------------------
// 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 Sep 18, 2012 — forked from cowboy/jquery.ba-queuefn.js
jQuery queueFn: add a $.fn method or function onto the effects queue
View jquery.ba-queuefn.js
/*!
* 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 Feb 17, 2012
Test if a font is loaded on a client machine.
View test-loaded-font.js
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 / console_log.js
Created Feb 10, 2012
Universal JavaScript console log script
View console_log.js
// 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 / userAgent.js
Created Nov 4, 2011
UserAgent sniffer
View userAgent.js
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';
View 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 Sep 1, 2011
HTML5 polyfill for document.head
View documentHead.js
document.head = document.head || document.getElementsByTagName('head')[0];
@sx
sx / addStyle.js
Created Aug 30, 2011
add a new stylesheet tag to the head
View addStyle.js
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