Skip to content

Instantly share code, notes, and snippets.

View pegli's full-sized avatar

Paul Mietz Egli pegli

View GitHub Profile
@pegli
pegli / index.tss
Created March 27, 2013 00:24
header/content/footer example
".container": {
backgroundColor:"white"
},
"#header": {
top: 0,
height: 40,
backgroundColor: 'yellow'
},
@pegli
pegli / eventRow.js
Last active December 14, 2015 13:09
var args = arguments[0] || {};
var event = args.event;
var parent = args.parent;
$.addEventListener('swipe', function(e) {
parent.swipe(e);
}
var styles = require('styles');
// creates { color: 'blue', font: { fontSize: 16 }, textAlign: 'right' }
var usernameLabel = Ti.UI.createLabel(_.defaults({
textAlign: 'right'
}, styles.style_classes.Label, styles.style_ids.username_label));
@pegli
pegli / app.js
Created January 25, 2013 18:48
app.js wrapper for Ejecta sample code
var webgl = require('appersonlabs.webgl');
var win = Ti.UI.createWindow({
backgroundColor:'#ccc'
});
var canvas = webgl.createCanvasView({
height: Ti.Platform.displayCaps.platformHeight,
width: Ti.Platform.displayCaps.platformWidth,
backgroundColor: 'white'
@pegli
pegli / gist:4559132
Created January 17, 2013 19:55
widget example

widgets/switchfield/views/widget.xml

<Alloy>
  <TableViewRow id="container">
    <Label id="label"/>
    <Switch id="switchControl" onChange="change"/>
  </TableViewRow>
</Alloy>
@pegli
pegli / gist:4002405
Created November 2, 2012 16:21
styled buttons in a toolbar
var toolbar = Ti.UI.iOS.createToolbar({
bottom: 0,
left: 0,
right: 0,
width: Ti.UI.FILL,
barColor: 'transparent',
translucent: true,
backgroundGradient: {
type: 'linear',
colors: [
@pegli
pegli / gist:3789307
Created September 26, 2012 17:19
example use case of afterCollectionCreate
// semi-contrived example: adding a count() function to SQL collections which doesn't
// load all of the models.
// Alloy/lib/alloy/sync/sql.js
function Count() {
var table = model.config.adapter.collection_name;
var sql = 'SELECT * FROM '+table;
var rs = db.execute('SELECT COUNT(*) FROM '+table);
return rs.isValidRow() ? rs.field(0) : 0;
@pegli
pegli / gist:3520111
Created August 29, 2012 23:10
TiTouchDB save new document
var server = require('com.obscure.titouchdb'),
db = server.databaseNamed('mydb');
var doc = db.untitledDocument()
var result = doc.putProperties({
foo: 10,
bar: 'a string',
x: [1,2,3,4]
});
@pegli
pegli / gist:3520302
Created August 29, 2012 23:25
using couch_client.js
var client = require('couch_client').CouchClient('http://foo.iriscouch.com');
var db = client.database('mydb');
db.create(); // if not already created
var document = {
x: 10,
y: 'some string',
foo: [1, 2, 3]
};
@pegli
pegli / gist:3137381
Created July 18, 2012 16:46
list function for `mx
{
"_id": "_design/configs",
"_rev": "4-a0b96a31984e1267e6ecf46302744451",
"views": {
"subnet": {
"map": "function(doc) {\n emit(null, doc);\n};"
}
},
"lists": {