Skip to content

Instantly share code, notes, and snippets.

View pegli's full-sized avatar

Paul Mietz Egli pegli

View GitHub Profile
@pegli
pegli / setup.coffee
Last active December 19, 2015 07:38
common kanso setup that includes a validation function
# assumes you have "load": "setup" in your kanso.json
module.exports =
views: require './views'
lists: require './lists'
validate_doc_update: (newDoc, oldDoc, userCtx, secObj) =>
if newDoc._deleted == true
throw { forbidden: 'Docs live forever!' }
@pegli
pegli / gist:5951901
Last active December 19, 2015 11:59
prototype methods for attachment management
module.exports.afterModelCreate = function(Model) {
Model = Model || {};
Model.prototype.idAttribute = '_id'; // true for all TouchDB documents
Model.prototype.config.Model = Model; // needed for fetch operations to initialize the collection from persistent store
Model.prototype.attachmentNamed = function(name) {
var doc = db.documentWithID(this.id);
if (doc) {
return doc.currentRevision.attachmentNamed(name);
@pegli
pegli / ComObscureOverlaytestDerpView.m
Created August 28, 2013 18:29
label overlay example
#import "ComObscureOverlaytestDerpView.h"
@implementation ComObscureOverlaytestDerpView
- (void)initializeState
{
label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = @"hello, world!";
label.backgroundColor = [UIColor greenColor];
[self addSubview:label];
/**
* This file was auto-generated by the Titanium Module SDK helper for Android
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 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.
*
*/
package com.example.androidextension;
@pegli
pegli / README.md
Last active January 1, 2016 13:19
Alloy binding example

These files show how to use Mads Møller's sqlrest adapter to fetch the remove video metadata and cache it locally in a sqlite database. Replace the underscores in the file names with slashes to get their actual location in your project.

Adapter Setup

There were two issues with the adapter code that you posted in pastie: the columns were missing from the adapter definition, and you needed to specify a custom parser function in order to pull out the embedded videos[i].video objects. Also, the data that were posted to pastie were not valid JSON, so I had to fix that. The data used for this example can be found here: http://pastie.org/8580518.

View

The index.xml file above shows a basic list view that uses item templates and Alloy's data binding to create a list of video titles. The docs for ListView show more details about how to set up list item templates and bind model properties. In brief:

var c = require('window_view_controller').createController();
@pegli
pegli / view.js
Last active August 29, 2015 13:58
function do_something(e) {
if (e.source.type == 'a') {
// something specific to a
}
else if (e.source.type == 'b') {
// something specific to b
}
}
$.index.open();
@pegli
pegli / question.js
Created September 29, 2014 20:34
fetching relations in Alloy model
extendModel: function(Model) {
_.extend(Model.prototype, {
answers: function() {
var coll = Alloy.createCollection('answer');
coll.fetch({ query: 'select * from answers where question_id = ' + this.get('id')});
return coll;
},
});
return Model;
}
@pegli
pegli / app.js
Created October 1, 2014 20:13
Ti webview eventing
var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({
url: 'local.html'
});
var button = Ti.UI.createButton({
title: 'fromTitanium',
height: '50dp',
width: '130dp'
});
button.addEventListener('click', function(e) {