Skip to content

Instantly share code, notes, and snippets.

@stefano-bortolotti
stefano-bortolotti / README.md
Last active May 6, 2022 10:56
iOS App Rating widget for Dashing

##Preview

Description

Display your iOS App Rating info. It uses iTunes Store website as the source.

##Usage

@stefano-bortolotti
stefano-bortolotti / LocalStorageUtil
Last active August 29, 2015 13:57
Wrap local storage api
if(!window['UTIL']) window['UTIL'] = {};
UTIL.LocalStorage = function() {
var context = {};
return $.extend(context, {
get : function(key) {
try {
return JSON.parse(localStorage.getItem(key))
}
catch(e) {
return localStorage.getItem(key)
@stefano-bortolotti
stefano-bortolotti / setScreenOrientation
Created March 12, 2014 16:27
Set screen orientation to the body tag
function _getScreenOrientation() {
/*
returns screen orientation(landscape|portrait) and
set the attribute on the body "data-landscape[true|false]"
*/
if ( window.orientation == ( -90 || 180 ) ) {
document.body.setAttribute('data-landscape', 'true');
return 'landscape';
@stefano-bortolotti
stefano-bortolotti / getViewportDimensions
Created March 12, 2014 16:22
Get Viewport dimensions
function _getViewportDimensions() {
var dEl = document.documentElement,
clientH = dEl['clientHeight'],
innerH = window['innerHeight'],
clientW = dEl['clientWidth'],
innerW = window['innerWidth'];
return {
height : ( clientH < innerH ) ? innerH : clientH,
width : ( clientW < innerW ) ? innerW : clientW
@stefano-bortolotti
stefano-bortolotti / isElementInViewport.txt
Created January 25, 2014 16:49
Determine if an element is in the visible viewport
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@stefano-bortolotti
stefano-bortolotti / [JS] Determine connection type
Created November 18, 2013 10:28
[JS] Determine connection type
/**
navigator.connection is supported on: android 2.2+, Chrome 30+
*/
var connection = navigator.connection || {'type':'0'}, // create a custom object if navigator.connection isn't available
connectionSpeed;
// determine connection speed
switch(connection.type) {
case connection.CELL_3G: // 3G
@stefano-bortolotti
stefano-bortolotti / iOS icon size
Created November 8, 2013 10:19
icon sizes to use for the home screen up to iOS7
<!-- non-retina iPhone pre iOS 7 -->
<link rel="apple-touch-icon" href="icon57.png" sizes="57x57">
<!-- non-retina iPad pre iOS 7 -->
<link rel="apple-touch-icon" href="icon72.png" sizes="72x72">
<!-- non-retina iPad iOS 7 -->
<link rel="apple-touch-icon" href="icon76.png" sizes="76x76">
<!-- retina iPhone pre iOS 7 -->
<link rel="apple-touch-icon" href="icon114.png" sizes="114x114">
<!-- retina iPhone iOS 7 -->
<link rel="apple-touch-icon" href="icon120.png" sizes="120x120">
@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;
}
@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 / 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';
}
}