Skip to content

Instantly share code, notes, and snippets.

@SapientBoston
SapientBoston / isipad
Created May 22, 2013 14:13
Javascript: Test For iPad
var isiPad = navigator.userAgent.match(/iPad/i) != null;
@SapientBoston
SapientBoston / gist:4066737
Created November 13, 2012 16:23 — forked from padolsey/gist:527683
JavaScript: Detect IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@SapientBoston
SapientBoston / gist:4065808
Created November 13, 2012 13:40
CSS: iPads (portrait and landscape)
/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}
@SapientBoston
SapientBoston / gist:4065777
Created November 13, 2012 13:32
JavaScript: Request Animation Frame Polyfill
(function(){
'use strict';
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'RequestCancelAnimationFrame'];
}
if(!window.requestAnimationFrame){
@SapientBoston
SapientBoston / gist:4063012
Created November 13, 2012 00:28
JavaScript: Query String Map
var queryStringMap = (function(){
'use strict';
var obj = {},
params = location.search.replace(/^\?/,'').split('&'),
i, param, key;
for(i = params.length - 1; i >= 0; i--){
param = params[i].split('=');
key = param[0];
if(key){
obj[key] = param[1];
@SapientBoston
SapientBoston / gist:4062757
Created November 12, 2012 23:23
JavaScript: Random Integer
/**
* Generates a random interger between two given values
*
* @private
* @param {Number} from Integer representing the lower bound of the range
* @param {Number} to Integer representing the upper bound of the range
* @return {Number} Randomly generated integer
*/
function random(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);