Skip to content

Instantly share code, notes, and snippets.

@stefano-bortolotti
stefano-bortolotti / get screen orientation [JS]
Last active October 6, 2015 13:47
JS: detect screen orientation
switch (window.orientation) {
case 90:
case -90: document.body.setAttribute('landscape', 'landscape');
break;
case 0:
case 180: document.body.removeAttribute('landscape');
break;
}
@stefano-bortolotti
stefano-bortolotti / CSS rules for carousels
Last active December 16, 2015 03:39
some webkit CSS rules for carousels
.className, .className * {
   -webkit-touch-callout: none; /* disable callout on tap hold, like save image */
   -webkit-user-drag: none; /* no drag for images */
   -webkit-user-select: none; /* no user text selection */
   -webkit-tap-highlight-color: transparent; /* no highlight on tap */
}
function uMemory() {
var props = {
'blocksLimit' : 5
};
var queue = [];
var blocks = {};
this.init = function (options) {
props = $.extend(props, options);
//console.dir(props);
@stefano-bortolotti
stefano-bortolotti / get viewport height
Last active December 24, 2015 02:19
get the viewport height
function getViewportHeight() {
var docElement = document.documentElement,
client = docElement['clientHeight'],
inner = window['innerHeight'];
if ( client < inner )
return inner;
return client;
}
@stefano-bortolotti
stefano-bortolotti / String.endsWith
Created October 13, 2013 17:29
Javascript String ends with function
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
@stefano-bortolotti
stefano-bortolotti / border-box [CSS]
Last active December 25, 2015 10:59
use border box, a better layout model
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
@stefano-bortolotti
stefano-bortolotti / web apps viewports [HTML]
Last active December 26, 2015 10:39 — forked from burin/gist:3840737
Home screen Web apps viewport and icon syntax
<!-- standard viewport tag to set the viewport to the device's width
, Android 2.3 devices need this so 100% width works properly and
doesn't allow children to blow up the viewport width -->
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width" />
<!-- width=device-width causes the iPhone 5 to letterbox the app, so
we want to exclude it for iPhone 5 to allow full screen apps -->
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)" />
<!-- provide the splash screens for iPhone 5 and previous -->
<link href="assets/splash_1096.png" rel="apple-touch-startup-image" media="(device-height: 568px)">
<link href="assets/splash_iphone_2x.png" rel="apple-touch-startup-image" sizes="640x960" media="(device-height: 480px)">
@stefano-bortolotti
stefano-bortolotti / clearCookies [JS]
Created October 28, 2013 22:15
Clear all the cookies
function clearCookies() {
var c = document.cookie.split(";");
for ( var i = 0; i < c.length; i++ ) {
var e = c[i].indexOf('=');
var n = ( e > -1 ) ? c[i].substr(0, e) : c[i];
document.cookie = n + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
}
}
@stefano-bortolotti
stefano-bortolotti / Get Credit card type [JS]
Last active March 8, 2020 14:27
Get credit card type [JS]
function getCreditCardType(creditCardNumber) {
// start without knowing the credit card type
var result = "unknown";
// first check for MasterCard
if (/^5[1-5]/.test(creditCardNumber)) {
result = "mastercard";
}
// then check for Visa
else if (/^4/.test(creditCardNumber)) {
@stefano-bortolotti
stefano-bortolotti / get user agent [PHP]
Created November 7, 2013 16:30
Get the User Agent [PHP]
function getUA() {
static $browser; //No accident can arise from depending on an unset variable.
if ( !isset($browser) ) {
$browser = get_browser($_SERVER['HTTP_USER_AGENT']);
}
return $browser;
}