This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myProcedure = commonFunctionalityX(commonFunctionalityY(commonFunctionalityZ(function(arg1, arg2){ | |
//procedure-specific code | |
}))); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@commonFunctionalityX | |
@commonFunctionalityY | |
@commonFunctionalityZ | |
function myProcedure(arg1, arg2){ | |
//procedure-specific code | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A little workaround to proper handle resume and paused events on Android | |
*/ | |
var platformTools = require('bencoding.android.tools').createPlatform(); | |
var wasInForeGround = true; | |
//to be executed on every activity staus change | |
//check if it's passing from foreground to background or viceversa | |
function checkStatusSwitch() { | |
var isInForeground = platformTools.isInForeground(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//array of async resources to be loaded | |
var paths = ['file1.xml', 'file2.xml', 'file3.xml']; | |
//the callback for the ajax call | |
var callback = function(fileIndex){ | |
alert('this is a callback for file ' + paths[fileIndex]); | |
}; | |
//generates ajax calls | |
for(var i=0; i<=paths.length; i++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//array of async resources to be loaded | |
var paths = ['file1.xml', 'file2.xml', 'file3.xml']; | |
//finalizing function, to be called after all async operations are completed | |
var finalize = _.after(function(){ | |
alert('this is the last execution!'); | |
}, paths.length); | |
//the callback for the ajax call | |
var callback = function(fileIndex){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//a generic function to call api endpoints | |
function apiCall(host, method, endpoint, params, callback){ | |
var url = host + endpoint; | |
http(method, url, params, callback); | |
} | |
//this is some API for a foo.com web service | |
var fooAPI = _(apiCall).partial('http://foo.com'); | |
var foo_listPosts = _(fooAPI).partial('GET', '/posts'); | |
var foo_savePost = _(fooAPI).partial('POST', '/post'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this is the "debounced" search | |
// it runs after 500ms from its first call, just once in 500ms | |
var search = _.debounce(function(){ | |
var keyword = document.getElementById('searchbox').value; | |
doSearch(keyword); //this performs server call and displays results | |
}, 500); | |
//this is the keyboard event | |
document.getElementById('searchbox').addEventListener('keypress', search); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//the buffer to store measures | |
var buffer = []; | |
//this is the function that calls the endpont | |
var saveToAPI = function(data){ | |
//here the logic fo calling the endpoint | |
}; | |
//this is the function that handles data receiving | |
// it passes data from the buffer to the api, then clean the buffer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this is the handler | |
var onClick = function(e){ | |
alert('button clicked just one time'); | |
}; | |
//this is the "once" function, | |
// that is a function that executes only once, forever | |
var onlyOnce = _.once(onClick); | |
//here the handler is bound to the event |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//click count | |
var count = 0; | |
//this is the handler | |
var onClick = function(e){ | |
alert('button clicked ' + (++count) + ' times'); | |
}; | |
//this is the "throttled" function, | |
// that is a function that executes only once in a given timespan (here: 200ms) |