Skip to content

Instantly share code, notes, and snippets.

View krawaller's full-sized avatar

David Waller krawaller

View GitHub Profile
Ti.include("/struct/struct.js");
S.app.mainWindow = S.ui.createApplicationWindow();
S.app.mainWindow.open();
S.app.mood = "RADIANT!";
Ti.App.fireEvent("app:mood.update");
setTimeout(function(){Ti.App.fireEvent("app:msg",{msg:"Welcome!"});},1000);
@krawaller
krawaller / foowin.js
Created July 15, 2011 04:50 — forked from levi730/foowin.js
how to do subwindow with nav using struct
/**
* Appcelerator Titanium Platform
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
**/
// Code is stripped-down version of Tweetanium, to expose new structure paradigm
(function(){
S.ui.createFooWin = function(){
@krawaller
krawaller / gist:1125138
Created August 4, 2011 13:26
Demo object literals
demos = [{
description: "A parent with the layout property set to 'vertical' uses a vertical layout mechanism instead. Here, a child is placed in relation to the bottom of the previous child.",
children: [{height:80,width:100,left:30},{top:5,left:20,height:80,width:60}]
},{
iphone: "Everything works as normal, even negative offsets (not on Android though!) and zIndexes. Except...",
android: "Negative top offsets have weird behaviour in a vertical layout on Android. Here, the second child ends up before the first!",
children: [{height:80,width:100,left:30,zIndex:1},{top:-5,left:20,height:80,width:60}]
},{
iphone: "...the top and bottom properties are both used as margins (on Android only top!). So the height difference between two siblings is the sum of the bottom of the first and the top of the second.",
android: "The height difference between two siblings is controlled by the top property of the second sibling. On iPhone, the bottom prop of the first is added to the difference as well.",
@krawaller
krawaller / twinexport.coffee
Created September 18, 2011 08:13
Exporting to Node and the browser
if typeof exports is "undefined"
exportTo = @parser = {}
else
exportTo = exports
tests.addBatch "the implicit operation function":
"is defined": -> assert.isFunction iO
"returns product for": pairs "1x", "2y", "3z", "5(", "0x", ")(", "xy", "5\"", "x\"", "\"y","\"\"", "5|", "||", "!x"
"returns power for": pairs "x2", "y3", "z4", ")6", "\"2", "\"8", "|2", "x0", "!2"
"returns sum for": pairs "3-", "z-", ")-", "\"-"
"returns nothing for": wrongpairs "3+", "x*"
tests.addBatch "the calc function":
"is defined": -> assert.isFunction calc
"when relating":
topic: -> (arg)-> calc "relation", start, arg, "eq"
"a blob":
topic: (relate)-> relate blob
"we get a": type "relation"
"containing": objs [start, blob]
"with a value": val "eq"
"a relation": (relate)-> assert.throws -> relate relation
calc = (tool,a1,a2,toolarg)->
if tool is "relation"
throw "Only one relation allowed!" if a2.type is "relation"
type:"relation",objs:[a1,a2],val:toolarg
else if a2.type is "relation"
type: "relation",val:a2.val, objs:[calc(tool,a1,a2.objs[0]),a2.objs[1]]
else if a2.isblock
o tool,[a1,a2]
else if tool in ["sum","product"] and tool is a2.type
o tool, [a1].concat a2.objs
@krawaller
krawaller / ui.coffee
Created September 28, 2011 10:52
mathparser UI code
# ----------------------------- jquerified DOM references ---------------------------
ui = {}
ui[id] = $("##{id}") for id in ["input","output","response","history","current","savebtn","examples","clearhistorybtn","clearbtn"]
ui.currentstring = $ "#current .string"
ui.currentobjprint = $ "#current .objprint"
# -------------------------- variables/constans -----------------------------------
@krawaller
krawaller / comparedbs.js
Created January 27, 2012 18:22
Compare performance of Titanium Mobile SQLite insert in different ways
// Compare classic insert, insert using Begin/Commit and Union insert described slightly down on this page: http://stackoverflow.com/questions/1609637/is-it-possible-to-insert-multiple-rows-at-a-time-in-an-sqlite-database
// Create some values
var values = [];
for(var i = 0; i < 500; i++){
values.push(i);
values.push(String.fromCharCode(65 + i % 25));
}
@krawaller
krawaller / bbviewpubpattern.js
Created February 29, 2012 06:48
Backbone Sanitary View Publishing Pattern
/*
S A N I T A R Y V I E W P U B L I C A T I O N P A T T E R N
This pattern adresses three issues; memory leaks, involuntarily allowing unwanted event listeners to live
on, and the cumbersome process of publishing a view to the page. The first two issues are dealt with through
making sure that previously published views are removed properly, and not merely have their html
overwritten. And, as will see, the solution to fixing the removal process will also mean a streamlining
of the publication process!
We do this through the use of two mixin modules; one for our views, and one for our router.