Idea for an uber-simplistic view / data binding in Alloy
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
// We'll use cluster to split work across all of our CPUs. | |
var cluster = require('cluster'); | |
// Are we the master process ... | |
if (cluster.isMaster) { | |
// Monitor the workers for failures. | |
cluster.on('exit', function(worker) { | |
console.log('Worker ' + worker.process.pid + ' died. Forking another...'); | |
cluster.fork(); | |
}); |
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 lox = require('lib/lox'); | |
lox.start(); | |
lox.exampleOfSendWithoutCallback(); | |
lox.exampleOfSendWithCallback(function(result) { | |
console.log('Got data back! ' + result); | |
}); |
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 win = Ti.UI.createWindow({ backgroundColor: '#000' }); | |
var progress = Ti.UI.createProgressBar({ max: 1, min: 0, value: 0, visible: true }); | |
var videoBlob, videoName = 'todo.mp4'; | |
// Get your own API key from the following URL: http://code.google.com/apis/youtube/dashboard/ | |
var yourApiKey = '<< YOUR API KEY GOES HERE >>'; | |
function checkToken() { | |
win.add(progress); | |
var sessionToken = Ti.App.Properties.getString('GoogleAuthSubSessionToken', ''); |
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
/* | |
State. | |
*/ | |
var simplify = Ti.Platform.osname === 'mobileweb'; | |
var currentFlashes = {}; | |
/* | |
Public API. | |
*/ | |
exports.chainAnimateForever = chainAnimateForever; |
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
// now you can use it in a titanium app | |
useSomeApi(Ti.App.Properties.getString('SOME_API_KEY')); |
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 win = Ti.UI.createWindow({ | |
backgroundColor: 'white' | |
}); | |
win.addEventListener('click', function foo(e) { // note the named function expression needed for the second way | |
// oringal idea by @fukhaos | |
// http://www.tidev.io/2014/09/10/the-case-against-ti-app-fireevent-2/#comment-13013 | |
e.source.removeEventListener(e.type, arguments.callee); | |
Script showing how to clean a view inside a window (like a scrollview)
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 base controller event handler, which will get overridden by the derived one | |
exports.doClick = function(e) { | |
alert('base click handler'); | |
}; | |
// We have to wait until the object is initialized before applying the event listener. This is so | |
// the derived listener is used, not the base one. Also, "$" must be used instead of "exports", to | |
// ensure that the overridden instance of the controller's "doClick" is used, not the exported | |
// version of the function from the base controller. | |
exports.init = function(e) { |
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
// next two from http://stackoverflow.com/a/5624139/292947 | |
function componentToHex(c) { | |
var hex = c.toString(16); | |
return hex.length == 1 ? "0" + hex : hex; | |
} | |
function rgbToHex(r, g, b) { | |
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); | |
} |