Skip to content

Instantly share code, notes, and snippets.

View tonylukasavage's full-sized avatar
💭
Learning to make games

Tony Lukasavage tonylukasavage

💭
Learning to make games
View GitHub Profile
@tonylukasavage
tonylukasavage / index.js
Created April 18, 2014 22:18
can't get translucent navbars working
$.nav.open();
exports.createController = function(name, args) {
var newController = new (require('alloy/controllers/' + name))(args);
_.each(_.keys(args), function(key) {
if (key.indexOf('#') === 0 && key !== '#') {
newController[key.substring(1)].applyProperties(args[key]);
}
});
});
@tonylukasavage
tonylukasavage / search.txt
Created May 16, 2014 13:48
Alloy twitter search
((alloy AND appcelerator) OR #tialloy) -Q&A
@tonylukasavage
tonylukasavage / app.js
Last active August 29, 2015 14:01
perf test
var win = Ti.UI.createWindow();
var key = '#foo';
var start = new Date().getTime();
for (var i = 0; i < 10000; i++) {
if (key.indexOf('#') === 0 && key !== '#' && !win.__iamalloy) {
var bar = 1;
}
}
console.log('time (__iamalloy): ' + ((new Date().getTime()) - start) + 'ms');
@tonylukasavage
tonylukasavage / should.js
Created May 24, 2014 02:00
custom should.js assertion
// getter assertion
should.Assertion.add('CRAZY', function() {
this.params = {
operator: 'to be the string "CRAZY"',
expected: 'CRAZY',
showDiff: true
};
this.obj.should.equal('CRAZY');
}, true);
@tonylukasavage
tonylukasavage / app.js
Created June 4, 2014 15:03
maybeCallback(), slightly modified, from node.js source, for adding default callbacks if they aren't provided, with optional options
var util = require('util');
function maybeCallback(cb) {
return util.isFunction(cb) ? cb : function(err) { if (err) throw err; };
}
function iShouldHaveACallback(opts, callback) {
callback = maybeCallback(arguments[arguments.length-1]);
if (!opts || util.isFunction(opts)) {
opts = {};
@tonylukasavage
tonylukasavage / .jshintrc
Created June 24, 2014 13:27
generic .jshintrc for ti, alloy, node.js, mocha
{
"browser": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"expr": true,
"immed": true,
"indent": 4,
"latedef": "nofunc",
"newcap": true,
@tonylukasavage
tonylukasavage / Gruntfile_0.1.0.js
Created August 31, 2014 02:20
grunt-titanium 0.1.0 vs. 0.2.0
grunt.initConfig({
titanium: {
create: {
options: {
command: 'create',
name: 'tmp',
workspaceDir: '.'
}
},
build: {
@tonylukasavage
tonylukasavage / test.js
Created October 28, 2014 19:33
open brace on next line
if (val === 'sdfdsfsdf' ||
val === 'sdfsdfsfsf' ||
val > 23423423 ||
val < 123)
{
// I like the open brace on a new line _only_ in this situation
// so that there's a clear distinction between the end of the
// multi-line conditional and the beginning of the code
}
@tonylukasavage
tonylukasavage / load.js
Created November 12, 2014 13:29
implementing a node module
var format = require('util').format,
fs = require('fs'),
path = require('path');
var code = '', testCode = '',
test = fs.readFileSync(path.join(__dirname, 'test', 'app_src.js'), 'utf8'),
template = 'exports.%s = function %s%s {\n' +
'\tthrow new Error(\'%s not yet implemented\');\n' +
'};\n\n',
testTemplate = '\tit(\'#%s\', function() {\n' +