Skip to content

Instantly share code, notes, and snippets.

View krawaller's full-sized avatar

David Waller krawaller

View GitHub Profile
// Demo usage of http://github.com/krawaller/PubSubHotTub
var func = function(){ console.log(Array.prototype.slice.call(arguments).join(" ")); };
pb.sub('/root/leaf/meatloaf', func, 'i', 'like', 'curry');
pb.pub('/root/leaf/meatloaf', 'and', 'cheese'); // => i like curry and cheese
pb.sub('/*/leaf/*', func);
pb.pub('/root/leaf/*', 'cheese'); // => cheese, i like curry cheese ^^ (curry cheese sounds rad)
var Test = {
name: 'test',
init: function(){
this.proxiedHandleEvents = $.proxy(this.handleEvents, this);
Ti.App.addEventListener('app', this.proxiedHandleEvents);
},
// Event cannon with callback fix.
fire: function(opts){
$('<div/>').attachAndReturn(Letter, this, letter, specialLetter);
Ti.include('../js/go.view.pre.js');
currentWin.add(Go.table([{
titleKey: 'play',
url: 'play_menu.js'
},
{
titleKey: 'options',
url: 'options.js'
},
// CSS-like styling
// test.css
tableView {
background-color: #f00;
color: #fff;
}
row { background-color: #0f0; }
.info { right: 0; }
// HTML-like templates combined with micro-templates or mustasche
"plr-gate":{
conds: [{ // array of condition objects
'if': { // all properties here are conditions to be evaluated
"hasflag": "haskey" // tests for global flag of the given name
},
then: { // effects to take place if all conditions were true
on: true, // collision takes place on the square
stop: "b", // stops the marble motion, with animation "b" (bounce)
setwalltype: "none" // makes the gate disappear
},
@krawaller
krawaller / css_anchors.js
Created July 5, 2010 12:17
CSS Anchors Shim
(function(){
var hash = decodeURIComponent((location.href.match(/#(.*)$/) || [])[1]);
if(hash){
var el = document.querySelector(hash), t = 0;
do { t += el.offsetTop; }
while (el.offsetParent && (el = el.offsetParent));
window.scrollTo(0, t);
}
K.createKraWebView = function(o){
var webview = K.create(K.merge({url: "../views/"+ (o.masterPageFile || "_masterpage.html")} o),
template = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory+"/views/"+o.templateFile).read().text,
opts = { template: template, data: {data: o.data} };
webview.addEventListener("load",function(){ webview.evalJS("render("+JSON.stringify(opts)+")"); });
return webview;
},
win.add(createKraWebView({template: "templateexamaple.html",data:{name:"ole",role:"bass",presentation:"<p>Nice guy!</p>"}}));
@krawaller
krawaller / community.js
Created October 21, 2010 10:05
CouchOne Tristania example
function map(doc){
if(doc.username && doc.presentation){
emit(doc._id, doc);
}
}