Skip to content

Instantly share code, notes, and snippets.

View pegli's full-sized avatar

Paul Mietz Egli pegli

View GitHub Profile
@pegli
pegli / app.js
Last active September 11, 2019 21:44
Titanium: resume event handling on iOS and Android
var win = Ti.UI.createWindow({
backgroundColor: "white",
});
var label = Ti.UI.createLabel({
text: "init"
});
win.add(label);
@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:

/**
* 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 / 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];
@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 / 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:5749878
Created June 10, 2013 15:55
emit doc keys in couchdb map function
function(doc) {
for (var i in doc) {
if (i[0] != '_' && doc.hasOwnProperty(i)) {
emit(parseInt(i), null);
}
}
}
@pegli
pegli / MyProxy.java
Last active December 16, 2015 21:59
pass a native function call to a KrollFunction invocation
public void doSomething() {
}
@Kroll.method
public void foogle(KrollFunction callback) {
final MyProxy self = this;
callback.call(this.getKrollObject(), new Object[] {
new KrollFunction() {
public Object call(KrollObject krollObject, Object[] args) {
self.doSomething();
@pegli
pegli / gist:5447998
Last active December 16, 2015 14:20
couchbase-lite-ios internal replication failure
16:12:24.722| Logging mode 2 enabled in domains: {CBL_Router, CBL_URLProtocol, CBLReplication, ChangeTracker, Sync, SyncVerbose}
16:12:24.725| Sync: ReplicatorManager scanning existing _replicator docs...
16:12:24.751| Sync: ReplicatorManager done scanning.
16:12:29.849| Sync: CBL_Puller[http://lite.couchbase./source/] STARTING ...
16:12:29.849| CBLBasicAuthorizer initWith <http://lite.couchbase./source/>
16:12:29.954| Sync: CBL_Puller[http://lite.couchbase./source/]: Going online
16:12:29.954| Sync: CBL_Puller[http://lite.couchbase./source/]: postProgressChanged (0/0, active=1 (batch=0, net=1), online=1)
16:12:29.954| SyncVerbose: CBL_Puller[http://lite.couchbase./source/]: GET _local/235aa4ef8704428da3bcd63596f7efc7269d840f
16:12:29.957| Sync: CBL_Puller[http://lite.couchbase./source/]: postProgressChanged (0/0, active=1 (batch=0, net=1), online=1)
16:12:29.957| CBLReplication: CBLReplication[from http://lite.couchbase./source/]: mode=3, completed=0, total=0 (changed=1)
@pegli
pegli / back.js
Created April 22, 2013 16:51
Alloy page curl animation example
function curlDown(e) {
$.back.close({ transition: Ti.UI.iPhone.AnimationStyle.CURL_DOWN });
}