Skip to content

Instantly share code, notes, and snippets.

@akgupta
akgupta / localStorageSync.js
Created March 12, 2012 04:20
Overriding backbone sync to use local storage
// overriding sync to use local storage when possible
sync : function(method, model, options){
var key, now, timestamp, refresh;
if(method === 'read' && this.constants.isStoredInLocalStorage) {
// only override sync if it is a fetch('read') request
key = this.getKey();
if(key) {
now = new Date().getTime();
timestamp = $storage.get(key + ":timestamp");
refresh = options.forceRefresh;
@akgupta
akgupta / quotaexceeded.js
Created March 17, 2012 22:12
handle quota exceeded error in local storage
try {
module.$localStorage[key] = serializer(value);
} catch(e) {
if(e.name === 'QUOTA_EXCEEDED_ERR') {
// reset to make space
module.reset();
module.$localStorage[key] = serializer(value);
} else {
module.localStorageAvailable = false;
$log.error("Local storage write failure - " + e);
@akgupta
akgupta / keydescription.js
Created April 26, 2012 03:10
keydescription
<app-id>:user:<user-id>:<key-name>
@akgupta
akgupta / dataURI.css
Created July 14, 2012 17:05
Data URI
$add-experience-icon-data: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAgCAYAAAB6kdqOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAUtJREFUeNpiZEACe/YeEABS64HYgYE+4AAQB7o4O3yACTChKaCnYxigdq1HFmDBooBBSVGBQVFRnqYuuX//IcO9+w8Y0AOACZtiWjsGBGRlpbGKMw5AusGbnpgGiWPg6YmFnumGmPTERM90Q0x6YiFGA9T1DNJSUgzs7GxUdxALCwvxDlqxag3DmzdvwWyQY+JiomniKLzZHgaePnsGdwwI/Pz5Cxjf92kafUykavj0+cvAOejzp890T+B4HaShoc4gLS0F54PSjr6e7sBGGShnwYCSoiLNQwhrLgMl3ouXLgPxJTAbBq7fuAksAu4zaKirM5iZmtAkt2ENoW07djKcOn0GxTHojl20ZCn9ouzp02cENWJzLM2iLCcrfcCqESaGQQawhtCUaTNJNohaoTroQmjUQaO5bNDkMnIAtpgYTUOjaWjYpSGAAAMAOdVqvldCIWIAAAAASUVORK5CYII=";
@mixin add-experience-icon {
@include base-image (
$add-experience-icon-data,
36px,
32px
)
};
@akgupta
akgupta / nativeScroll.css
Created July 14, 2012 17:07
iOS5 Native Scrolling
overflow: scroll;
-webkit-overflow-scrolling: touch;
@akgupta
akgupta / docFrag.js
Created July 14, 2012 17:44
docFrag append
var div = document.getElementById("container");
var docFrag = document.createDocumentFragment();
for ( var i = 0; i < elems.length; i++ ) {
docFrag.appendChild( elems[i] );
}
div.appendChild(docFrag);
@akgupta
akgupta / accelerate.css
Created July 14, 2012 18:04
css h/w accelerate
@mixin accelerate {
-webkit-transform:translate3d(0,0,0);
}
@akgupta
akgupta / spinner.css
Created July 15, 2012 01:46
spinner css
.spinner {
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABs0lEQVQ4y42TPS8EURSG18ey4nuFNXPu+bizFMRGQmI7ChEEBYWCgoKSKFVCQhRaLVrR+wsSSn6AX6Hmnd0hk7UrbvIkd+bO+5733Ds3k/ljFNXuwUPmvyMSZXAHwsTgOSaec8G1iBN25LINDbxIbPABbhODJ/ASz8Ux5FKygH4bRCwBKCQp9sAnmIH4EbwOD1FWRCaFNF8xC1xW0kZF0cui6hvYSkyewCnES2CDyPWi+ki8piRDRjptJD6VQAniK/AO7vE8CLq+15VdsxakBcIxIysraRSF1FZvE6eR5miE7VeffsA3aaAhk+usFR2A84QzYx1vtMk4hV5Un0goCaEtiA7BxTeedbKhAUl32gCM1qSRCKzhOFtrxZqPmtD/qDrpq3f+eQh3wQ049sJdyvqzDxxyqw37NnNWBsug5Ely6co74BrMVQxZ98G8iYTAmeOSMS/EaxAzWDCnE+kE/aCvKpYpiC8gZM+8jPerxjIAg20QVUxCa7dAc3Va0R6IT8BG1YxX0M5qRcQ8AzZRoKPhXUCsHlRex4/TnaRZhMFatarkzEkZm9jx79uJ+LMxf33zBSwYVsQayZ4lAAAAAElFTkSuQmCC) 0 50% no-repeat;
background-size: 16px;
....
}
@akgupta
akgupta / img.html
Created July 15, 2012 02:38
img loading unloading
<!--loaded-->
<div data-src=""
style="background-image: url(http://www.blogcdn.com/www.joystiq.com/media/2012/07/assassinscreedthefall530px.jpg);">
</div>
<!--unloaded-->
<div data-src="http://www.blogcdn.com/www.joystiq.com/media/2012/07/assassinscreedthefall530px.jpg"
style="background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAABJJREFUeF4FwIEIAAAAAKD9qY8AAgABdDtSRwAAAABJRU5ErkJggg==);">
</div>
Lix.getBucket('mobile.abtest1', 'memberId:23', function(err, bucket) {
if(bucket === 'A') {
// do A
AsyncCallForA(req, handleAFn)
} else if(bucket === 'B') {
// do B
AsyncCallForB(req, handleBFn)
}
}