Skip to content

Instantly share code, notes, and snippets.

@mckamey
mckamey / module.js
Created January 13, 2012 01:29
JS Module Pattern A
/*global jQuery */
var App = (function(App, $){
'use strict';
// private members
var foo = 0,
bar = 'bar';
@mckamey
mckamey / pgDebug.js
Created December 29, 2011 17:51 — forked from purplecabbage/pgDebug.js
Workout your iPhone PhoneGap UI in Desktop Safari
var safariDebug = ( navigator.platform.indexOf("iPhone") < 0 && navigator.platform.indexOf("iPod") < 0 && navigator.platform.indexOf("iPad") < 0 );
if(safariDebug)
{
PhoneGap.run_command = function()
{
if (!PhoneGap.available || !PhoneGap.queue.ready)
return;
@mckamey
mckamey / perf.js
Created October 27, 2011 00:24
Simple JS Perf Timer API
/**
* perf.js
* Simple JS Timer API
*
* @public
* @param {number} alpha weight for EWMA trends (default: 0.2)
* @this {Perf}
* @constructor
*/
var Perf = function(alpha) {
@mckamey
mckamey / datetest.js
Created October 5, 2011 17:20
ECMAScript Date range unit test
try{
module("ES5 ranges");
test("ES5 Epoch", function() {
// epoch
var expected = 0;
var actual = new Date(expected);
@mckamey
mckamey / LICENSE.txt
Created May 19, 2011 21:56 — forked from 140bytes/LICENSE.txt
Indexed string formatting
Copyright (c) 2011 Stephen M. McKamey, http://mck.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@mckamey
mckamey / LICENSE.txt
Created May 19, 2011 21:51 — forked from 140bytes/LICENSE.txt
Named string formatting
Copyright (c) 2011 Stephen M. McKamey, http://mck.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@mckamey
mckamey / LICENSE.txt
Created May 18, 2011 22:17 — forked from 140bytes/LICENSE.txt
Fibonacci
Copyright (c) 2011 Stephen M. McKamey, http://mck.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@mckamey
mckamey / AcceptFilter.java
Created March 10, 2011 23:58
Servlet Filter for JAX-RS content negotiation which fixes WebKit Accept header and adds extension support
package org.example.www.filters;
import java.io.IOException;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Modifies Accept headers and allows URL extensions to improve JAX-RS content negotiation
* Adds "Vary: accept" header to response
@mckamey
mckamey / doctype.js
Created January 10, 2011 16:57
DocType extraction snippet
function getDocType(document) {
var node = document.firstChild;
while (node) {
var nodeType = node.nodeType;
if (nodeType === 10) {
// doctype
var doctype = '<!DOCTYPE '+(document.documentElement.tagName || 'html').toLowerCase();
if (node.publicId) {
doctype += ' PUBLIC "' + node.publicId + '"';
}