Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / module.js
Created January 13, 2012 17:50
JS Module Pattern B
/*global jQuery */
// ensure root namespace
var App = App || {};
(function(App, $){
'use strict';
// private members
@mckamey
mckamey / module.js
Created January 13, 2012 20:21
JS Module Pattern C
/*global jQuery */
// ensure root namespace
var App = App || {};
App.foo = (function($){
'use strict';
// private members
@mckamey
mckamey / storage.js
Created January 23, 2012 17:49 — forked from remy/gist:350433
Storage polyfill
(function (window) {
'use strict';
if (window.localStorage && window.sessionStorage) {
return;
}
// initialize if data already stored
var data = JSON.parse(window.name || '{}');
@mckamey
mckamey / README.md
Created June 13, 2012 23:08
Polyfill for touch dblclick
@mckamey
mckamey / debounce.js
Created July 16, 2012 22:14
Debounce closure
/**
* Creates a function which fires only once when called in quick succession
* @param {function...} action the function to fire
* @param {number} delay amount of time until considered done, default:100ms
* @param {boolean} asap if should execute at the start of the series (true) or the end (false), default:false
* return {function} debounced function
*/
var debounce = function(action, delay, asap){
if ('function' !== typeof action) {
return null;
@mckamey
mckamey / README.md
Created July 20, 2012 23:23
Example iOS Custom URL Redirection

The way you can do this for "http://" URLs (and what I think Apple and Spotify do) this is to:

  1. Register a custom URL scheme [like the other answers have shown][1].

  2. Set up your HTTP URL to point to a real webpage.

  3. Put a script on that page to redirect to your custom URL if is on iOS.

For example, here is a sample page which will take you to the Twitter app for a particular user or the Twitter website depending upon if you are on the web or on your iOS device.