Skip to content

Instantly share code, notes, and snippets.

View brentonhouse's full-sized avatar
🚀
Busy being awesome!

Brenton House brentonhouse

🚀
Busy being awesome!
View GitHub Profile
@brentonhouse
brentonhouse / app.js
Last active August 29, 2015 14:11 — forked from dawsontoth/app.js
NodeJS server side simple JSON based socket communications. The Titanium client side counterpart to this is here: https://gist.github.com/dawsontoth/8412167
// 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();
});
@brentonhouse
brentonhouse / app.js
Last active August 29, 2015 14:11 — forked from dawsontoth/app.js
Titanium client side simple JSON based socket communications. The NodeJS server side component to this is available here: https://gist.github.com/dawsontoth/8412318
var lox = require('lib/lox');
lox.start();
lox.exampleOfSendWithoutCallback();
lox.exampleOfSendWithCallback(function(result) {
console.log('Got data back! ' + result);
});
@brentonhouse
brentonhouse / app.js
Last active August 29, 2015 14:11 — forked from dawsontoth/app.js
Record to YouTube
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', '');
@brentonhouse
brentonhouse / animations.js
Last active August 29, 2015 14:11 — forked from dawsontoth/animations.js
CommonJS module to make animations easier, like fading stuff out. Tested on iOS, Android, and Mobile Web.
/*
State.
*/
var simplify = Ti.Platform.osname === 'mobileweb';
var currentFlashes = {};
/*
Public API.
*/
exports.chainAnimateForever = chainAnimateForever;
@brentonhouse
brentonhouse / app.js
Last active August 29, 2015 14:11 — forked from tonylukasavage/app.js
Inject environment variables into Titanium. Makes shared code easier to manage (no more sanitizing keys in repos). Uses Titanium to encrypt the values.
// now you can use it in a titanium app
useSomeApi(Ti.App.Properties.getString('SOME_API_KEY'));
@brentonhouse
brentonhouse / app.js
Last active August 29, 2015 14:11 — forked from FokkeZB/app.js
addEventListenerOnce
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);
@brentonhouse
brentonhouse / _databinding_for_alloy.md
Last active August 29, 2015 14:12 — forked from rblalock/controller.js
Idea for an uber-simplistic view / data binding in Alloy

Idea for an uber-simplistic view / data binding in Alloy

@brentonhouse
brentonhouse / _ remove views from window.md
Last active August 29, 2015 14:15 — forked from mauropm/app.js
Script showing how to clean a view inside a window (like a scrollview)

Script showing how to clean a view inside a window (like a scrollview)

@brentonhouse
brentonhouse / base.js
Last active August 29, 2015 14:15 — forked from tonylukasavage/base.js
inheriting event handlers in Alloy
// 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) {
@brentonhouse
brentonhouse / anim.js
Last active August 29, 2015 14:16 — forked from guiled/anim.js
A fixed version for animated color in Titanium
// 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);
}